C++这道题应该怎么做?

2024-12-05 10:09:15
推荐回答(2个)
回答1:

#include

using namespace std;

class circle

{

public:

circle(double r=0):radius(r)

{

}

double getarea() const

{

return Pi*radius*radius;

}

private:

static const double Pi=3.14159;

double radius;

};

class table

{

public:

table(double h):height(h)

{

}

double getheight() const

{

return height;

}

private:

double height;

};

class roundtable : public circle,public table

{

public:

roundtable(double r=0,double h=0,string c="棕色"):circle(r),table(h),color(c)

{

}

string getcolor() const

{

return color;

}

void setcolor(string c)

{

color=c;

}

private:

string color;

};

int main()

{

roundtable rt(1.6,1.2,"金红");

cout<<"圆桌高:"<

cout<<"圆桌面积:"<

cout<<"圆桌颜色:"<

return 0;

}

回答2:

#include
using namespace std;
class DSK{
double l,g;//长,宽
int tr,ct,zj;//木料,抽屉,总价

public: void set(double l,double g,int tr,int ct){
this->l=l;
this->g=g;
this->tr=tr;
this->ct=ct;
if(l*g>1.8)zj+=50;
if(tr==1)zj+=50;
if(tr==2)zj+=125;
zj+=ct*10;
}
int getzj(){
return zj;
}
DSK(){
this->zj=200;
}
};
int main(){
DSK *dsk=new DSK[1000];
double l,g,n=0;
int tr,ct,max=0;
cout<<"请输入书桌的长,宽,木料(桃木1,橡木2,其它数为松木),抽屉:\n(Ctrl+z结束循环)"< while(cin>>l>>g>>tr>>ct){
dsk->set(l,g,tr,ct);
maxgetzj()?max=dsk->getzj():max;
dsk++;
}
cout<return 0;
}