男人一路微笑 男人一路微笑
女人一路尖叫、
关注数: 55 粉丝数: 127 发帖数: 952 关注贴吧数: 21
新手求帮助 继承过程中为什么数据继承不过来 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace shape { class shape { public const double PI = 3.1416; double c, s; public void yx() { Console.WriteLine("图形的周长为:{0}", c); Console.WriteLine("图形的面积为:{0}", s); } public void jx() { Console.WriteLine("图形的周长为:{0}", c); Console.WriteLine("图形的面积为:{0}", s); } } class shape2: shape { double r, a, b,c1,c2,s1,s2; string read1, read2; public void yx() { Console.WriteLine("请输入圆形的半径:"); read1 = Console.ReadLine(); r = Convert.ToDouble(read1); c1 = 2 * PI * r; s1 = PI * r * r; Console.WriteLine("图形的周长为:{0}", c1); Console.WriteLine("图形的面积为:{0}", s1); } public void jx() { Console.WriteLine("请输入矩形的长:"); read1 = Console.ReadLine(); a = Convert.ToDouble(read1); Console.WriteLine("请输入矩形的宽:"); read2 = Console.ReadLine(); b= Convert.ToDouble(read2); c2=2*(a+b); s2 = a * b; Console.WriteLine("图形的周长为:{0}", c2); Console.WriteLine("图形的面积为:{0}", s2); } public double A{ get { return this.a; } } public double B { get { return this.b; } } public double C2 { get { return this.c2; } } public double R { get { return this.r; } } public double S2 { get { return this.s2; } } public double S1{ get { return this.s1; } } public double C1 { get { return this.c1; } } } class shape3 : shape2 { double h,v,S; string readone, readtwo; public void yzx() { Console.WriteLine("请输入圆柱体的高:"); readone = Console.ReadLine(); h = Convert.ToDouble(readone); S =2*S1+C1* h; v =S1*h; Console.WriteLine("圆柱体的表面积为:{0}", S); Console.WriteLine("圆柱体的体积为:{0}", v); } public void cfx() { Console.WriteLine("请输入长方体的高:"); readone = Console.ReadLine(); h = Convert.ToDouble(readone); S = 2 * (A *B +B * h +A * h); v = S2 * h; Console.WriteLine("长方体的表面积为:{0}", S); Console.WriteLine("长方体的体积为:{0}", v); } } class Program { static void Main(string[] args) { shape2 yx=new shape2(); yx.yx(); shape2 jx=new shape2(); jx.jx(); shape3 yzx = new shape3(); yzx.yzx(); shape3 cfx = new shape3(); cfx.cfx(); } } }
1 下一页