C++这道题应该怎么做?
订单号、书桌长宽、木料类型、抽屉数量。书桌价格按如下规则计算:
所有书桌最低成本价200元;表面积(长X宽)超过1.8平米,增加50元;
木料是桃木,增加50元,橡木增加125元,松木则不加价;每个抽屉增加10元。
请编写计费软件。并查询总价最高的书桌。(要运用对象数组和对象指针) 展开
#include<iostream>
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<<"圆桌高:"<<rt.getheight()<<"米"<<endl;
cout<<"圆桌面积:"<<rt.getarea()<<"平方米"<<endl;
cout<<"圆桌颜色:"<<rt.getcolor()<<endl;
return 0;
}
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结束循环)"<<endl;
while(cin>>l>>g>>tr>>ct){
dsk->set(l,g,tr,ct);
max<dsk->getzj()?max=dsk->getzj():max;
dsk++;
}
cout<<max;
return 0;
}
广告 您可能关注的内容 |