OJ期末模考B

2019-04-14 12:46发布

Problem B: P2 别墅造价几何? Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 311  Solved: 197
[Submit][Status][Web Board]
Description 宇宙房产开发有限公司要盖一批圆顶的别墅,现要编制一个程序,计算别墅土建部分的造价。 为简化起见,只计算别墅房顶、墙面和柱子的价格。房顶每平方米的价格为3000元、墙面每平方米2000元、每根柱子10000元。 要求输入每栋别墅的房顶半径、墙面高度和柱子数,能计算出单栋别墅的造价,进而计算出多栋别墅的造价和。 请在beginend之间定义完成任务需要的类House,并提交这一部分程序, #include #include using namespace std; const int roofPrice = 3000; //房顶每平方米的价格 const int wallPrice = 2000;//墙面每平方米的价格 const int pillarPrice = 10000; //每根柱子的价格 const double PI = 3.1415926; //************* begin ***************** class House { private:     double radius;   //房顶半径     double height;   //房高     int pillars;     //柱子数 }; //************* end ***************** int main( ) {     House houses[10];     int n,i;     double r, h, p;     cin>>n;         //要盖n栋别墅     double sum = 0;     for(i=0; i     {         cin>>r>>h>>p;      //分别表示别墅的房顶半径、墙高、柱子数         houses[i].setData(r,h,p);            sum+=houses[i].getPrice();   //求出第i栋别墅造价并累加     }     cout <     cout<<"Total price: " << sum << endl;   //输出总造价     return 0; } Input 别墅数量(不超过10栋) 每栋别墅的房顶半径、墙面高度、和柱子数 Output 多栋别墅的造价和,小数点后保留2位小数 Sample Input 3 6.4 3 1 10.5 3.2 4 8.4 4.25 0 Sample Output Total price: 3252256.75   Submit: #include #include using namespace std; const int roofPrice = 3000; //房顶每平方米的价格 const int wallPrice = 2000;//墙面每平方米的价格 const int pillarPrice = 10000; //每根柱子的价格 const double PI = 3.1415926; //************* begin ***************** class House { private: double radius; //房顶半径 double height; //房高 int pillars; //柱子数 public: House(){}; void setData(double r,double h,int p){radius=r;height=h;pillars=p;} double getPrice(); }; double House::getPrice() { return 2*PI*radius*height*wallPrice+PI*radius*radius*roofPrice+pillars*pillarPrice; } //************* end ***************** int main( ) { House houses[10]; int n,i; double r, h, p; cin>>n; //要盖n栋别墅 double sum = 0; for(i=0; i>r>>h>>p; //分别表示别墅的房顶半径、墙高、柱子数 houses[i].setData(r,h,p); sum+=houses[i].getPrice(); //求出第i栋别墅造价并累加 } cout <