设计一个园类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;}
};
推荐
- (用java解决)设计一个圆类,Circle,有表示半径的protected类型的成员变量radius,获取和设置radius值的
- 定义圆类circle,数据成员有半径radius,成员函数有默认构造函数,默认半径为10,构造函数,计算圆面积圆周长以及输出函数,分别构造默认对象和半径为15的对象,输出各对象的周长和面积
- 2.定义一个圆类(Circle),私有数据成员为半径(radius)、圆周长和面积,共有成员函数为输入半径;计算
- circle U Q set the
- 定义一个圆类(Circle),属性为半径(radius)、圆周长和面积,操作为输入半径并计算周长、面积,输出半径、周长
- there will be more a_______ people than young people
- 某礼堂有30排座位,第1排共有20个座位,后面每一排比前一排多2个座位.问:
- 如图所示,同一水平桌面上放有长方体木块和铁块各一个.现想探究木块和铁块的下表面谁更粗糙,请你只利用一个量程满足实验要求的弹簧测力计,设计一个实验来验证你的猜想.写出实
猜你喜欢