急求!C#练习题。请用C#设计一个长方体类CUB,该类能够计算并输出长方体的体积和表面积,要求(内附)

请用C#设计一个长方体类CUB,该类能够计算并输出长方体的体积和表面积,要求(内附),
要求
(a)cub 类含长方体的长long宽width高height三个成员,并包含两个成员保存长方体的体积v和表面积S
(B)编写构造函数,为long和height及width赋初值
(c)并编写成员函数calcvolumn()和calcarea()计算长方体的体积和表面积
(D)编写成员函数print()输出V和s
(e)在program类中编写相应的Main()函数,生成长方体对象,输出对应的s和v

    class Program
    {
        static void Main(string[] args)
        {
            Cub cube = new Cub(3, 4, 5);
            cube.CalcArea();
            cube.CalcVolume();
            cube.Print();
            Console.ReadLine();
        }
    }
    class Cub
    {
        public int Length { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public int Volume { get; set; }
        public int SuperficialArea { get; set; }
        public Cub(int length, int width, int height)
        {
            this.Length = length;
            this.Width = width;
            this.Height = height;
        }

        public void CalcVolume()
        {
            Volume = Length * Width * Height;
        }

        public void CalcArea()
        {
            SuperficialArea = 2 * (Length * Width + Width * Height + Length * Height);
        }

        public void Print()
        {
            Console.WriteLine("表面积为:{0},体积为:{1}", SuperficialArea, Volume);
        }
    }

大小写什么的,名字什么的你自己看着改改就行了

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-01-14
有的还可以提供大纲哦。
相似回答