求用C#编一下!谢谢高手指教啊!!
13、设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据。要求:circ...
13、设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据。要求:circle类包含私有数据成员radius和求圆面积的成员函数getarea();table类包含私有数据成员height和返回高度的成员函数getheight()。roundtable类继承所有上述类的数据成员和成员函数,添加了私有数据成员color和相应的成员函数,并编写完整程序进行演示。
展开
2个回答
展开全部
C#不支持多继承,因此把其中的一个设置为接口吧
class RoundTable : Circle, ITable
{
private System.Drawing.Color color;
#region ITable 成员
public int height
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public int GetHeight()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
public void MyMethod()
{
this.Radius = 3.0;
double area = base.GetArea();
Console.WriteLine(area);
}
}
class Circle
{
const double PI = 3.14;
private double radius;
protected double Radius
{
get { return radius; }
set { radius = value; }
}
public double GetArea()
{
return PI * radius * radius;
}
}
interface ITable
{
int height
{
get;
set;
}
int GetHeight();
}
class RoundTable : Circle, ITable
{
private System.Drawing.Color color;
#region ITable 成员
public int height
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public int GetHeight()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
public void MyMethod()
{
this.Radius = 3.0;
double area = base.GetArea();
Console.WriteLine(area);
}
}
class Circle
{
const double PI = 3.14;
private double radius;
protected double Radius
{
get { return radius; }
set { radius = value; }
}
public double GetArea()
{
return PI * radius * radius;
}
}
interface ITable
{
int height
{
get;
set;
}
int GetHeight();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询