> 其他 >
设计一个园类circle和一个桌子类table,circle类包括私有数据成员半径radius和求圆面积得成员函数getarea():table类包含私有数据成员height(高度)和返回高度的成员函数getheight().另设计一个圆桌类roundtable,它是从前两个类的派生,roundtable类继承所有上述类得数据成员和成员函数,添加了私有数据成员color和相应的成员函数.要求输出一个圆桌得高度、面积和颜色等数据.
人气:215 ℃ 时间:2019-12-13 17:39:02
解答
class circle
{
float radius;
float area;
public:
circle(float r)
{radius=r; }
float getarea(void)
{area=3.14*radius*radius; return area;}
};
class table
{
float height;
public:
table(float h)
{height=h;}
float getheight(void)
{return height;}
};
class roundtable : public table, public circle
{
TColor color;
public:
roundtable(float h,float r,TColor c):circle(r), table(h)
{color=c;}
TColor getcolor(void)
{return color;}
};
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版