using System;
namespace 矩形類
{
// 矩形類
public class Rectangle
{
private float width;
private float height;
private float chang;
//建構式:引數為寬度width和高度height和長chang
public Rectangle(float width, float height, float chang)
{
this.width = width;
this.height = height;
this.chang = chang;
}
// 獲取寬度
public float Width { get { return this.width; } }
//獲取高度
public float Height { get { return this.height; } }
// 獲取長度
public float Chang { get { return this.chang; } }
//獲得矩形面積
public float Area { get { return this.width * this.height; } }
// 獲取周長
public float Circumference { get { return 2 * (this.width + this.height); } }
// 獲取長方體體積
public float Volume { get { return this.chang * this.height * this.width; } }
//獲得長方體表面積
public float Bmj { get { return 2 * (this.height * this.width) + 2 * (this.width * this.chang) + 2 * (this.chang * this.height); } }
//輸出
public override string ToString()
{
return string.Format("矩形的寬度:{0},高度:{1},寬:{2},矩形面積:{3},矩形周長:{4},長方體體積:{5},長方體表面積:{6}",
Width, Height, Chang, Area, Circumference, Volume, Bmj);
}
}
class Program
{
static void Main(string[] args)
{
Rectangle r1 = new Rectangle(5, 7, 9);//寬高長
Console.WriteLine(r1.ToString());
Console.ReadLine();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/232235.html
標籤:C#
