永发信息网

急!!请C++编程高手帮忙编个程序

答案:1  悬赏:40  手机版
解决时间 2021-05-01 08:14
  • 提问者网友:你给我的爱
  • 2021-04-30 23:03
采用面向对象的程序编写一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度,面积和颜色等数据
最佳答案
  • 五星知识达人网友:洎扰庸人
  • 2021-04-30 23:22

#include <iostream>


using namespace std;


class circle {
protected:
double r;


public:
circle(double _r) {r = _r;}
double getArea() {return r * r * 3.14;}


};


class table {
protected:
double h;
int color;
public:
table(double _h, int _color) {
h = _h;
color = _color;
}
double getHight() {return h;}
int getColor() {return color;}
};


class roundtable:public circle, public table {
public:
roundtable(double _r, double _h, int _color):circle(_r), table(_h, _color) {}
};


int main() {
roundtable onetable(10.0, 10.0, 1);


cout<<"高度:"<<onetable.getHight()<<endl;
cout<<"面积:"<<onetable.getArea()<<endl;
cout<<"颜色:"<<onetable.getColor()<<endl;


return 0;
}



希望对你有帮助,有什么问题可以继续提问

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯