导读:C程序设计题目设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前 C程序设计题目设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据. 许溢 1年前他留下的回答...
C程序设计题目设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前
C程序设计题目
设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据.
许溢
1年前他留下的回答
已收到1个回答
roland11
网友
该名网友总共回答了24个问题,此问答他的回答如下:采纳率:87.5%
#include
#include
using namespace std;
class circle{//圆类
public:
circle(){
r=0.0;
}
circle(double c_r){
r=c_r;
}
double getArea(){//得到面积
return M_PI*r*r;
}
private:
double r;//半径
};
class table{//桌子类
public:
table(){
height=0.0;
color="nocolor";
}
table(double t_height,string t_color){
height=t_height;
color=t_color;
}
double getHeight(){
return height;
}
string getColor(){
return color;
}
private:
double height;//高度
string color;//颜色
};
class roundtable : public circle,public table{
public:
roundtable(double r_r,double r_height,string r_color):circle(r_r),table(r_height,r_color){
}
};
int main(){
roundtable a = roundtable(0.5,1.2,"red");
cout<<"area="<
}
1年前他留下的回答
追问
4
许溢
Compiling... gerg.cpp E:WORKSPACEgregerg.cpp(15) : error C2065: 'M_PI' : undeclared identifier 执行 cl.exe 时出错.
roland11
M_PI实在math.h里面定义的,要是没有你就用3.14...替代吧 以上就是小编为大家介绍的C程序设计题目—设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前 的全部内容,如果大家还对相关的内容感兴趣,请持续关注上海建站网!
标签:
内容声明:网站所展示的内容均由第三方用户投稿提供,内容的真实性、准确性和合法性均由发布用户负责。上海建站网对此不承担任何相关连带责任。上海建站网遵循相关法律法规严格审核相关关内容,如您发现页面有任何违法或侵权信息,欢迎向网站举报并提供有效线索,我们将认真核查、及时处理。感谢您的参与和支持!