求用C#写一个控制台应用程序,具体要求如下:
1个回答
展开全部
类:
class Rectangle
{
double width;
double height;
public static int number = 0;
public double Width
{
get { return width; }
set { width = value; }
}
public double Height
{
get { return height; }
set { height = value; }
}
public double Circumstance
{
get { return (height + width) * 2; }
}
public double Area
{
get { return height * width; }
}
public Rectangle
{
number++;
}
public Rectangle(int width, int height)
{
Width = width;
Height = height;
number++;
}
public void Display()
{
Console.WriteLine(string.Format("Width: {0}.", Width));
Console.WriteLine(string.Format("Height: {0}.", Height));
Console.WriteLine(string.Format("Circumstance: {0}.", Circumstance));
Console.WriteLine(string.Format("Area: {0}.", Area));
Console.WriteLine();
}
}
主函数:
Rectangle rect1 = new Rectangle();
rect1.Display();
Console.WriteLine(string.Format("number: {0}.", Rectangle.number));
Rectangle rect2 = new Rectangle(10, 20);
rect2.Display();
Console.WriteLine(string.Format("number: {0}.", Rectangle.number));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询