C程序设计题目—设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前
1个回答

#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<

}