OJ期末模考B
2015-06-28 14:47
225 查看
Problem B: P2
别墅造价几何?
Time Limit: 1 Sec Memory Limit:
128 MB
Submit: 311 Solved:
197
[Submit][Status][Web
Board]
Description
宇宙房产开发有限公司要盖一批圆顶的别墅,现要编制一个程序,计算别墅土建部分的造价。
为简化起见,只计算别墅房顶、墙面和柱子的价格。房顶每平方米的价格为3000元、墙面每平方米2000元、每根柱子10000元。
要求输入每栋别墅的房顶半径、墙面高度和柱子数,能计算出单栋别墅的造价,进而计算出多栋别墅的造价和。
请在begin和end之间定义完成任务需要的类House,并提交这一部分程序,
#include <iostream>
#include <iomanip>
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<n; i++)
{
cin>>r>>h>>p; //分别表示别墅的房顶半径、墙高、柱子数
houses[i].setData(r,h,p);
sum+=houses[i].getPrice(); //求出第i栋别墅造价并累加
}
cout <<setiosflags(ios::fixed)<<setprecision(2);
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:
别墅造价几何?
Time Limit: 1 Sec Memory Limit:
128 MB
Submit: 311 Solved:
197
[Submit][Status][Web
Board]
Description
宇宙房产开发有限公司要盖一批圆顶的别墅,现要编制一个程序,计算别墅土建部分的造价。
为简化起见,只计算别墅房顶、墙面和柱子的价格。房顶每平方米的价格为3000元、墙面每平方米2000元、每根柱子10000元。
要求输入每栋别墅的房顶半径、墙面高度和柱子数,能计算出单栋别墅的造价,进而计算出多栋别墅的造价和。
请在begin和end之间定义完成任务需要的类House,并提交这一部分程序,
#include <iostream>
#include <iomanip>
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<n; i++)
{
cin>>r>>h>>p; //分别表示别墅的房顶半径、墙高、柱子数
houses[i].setData(r,h,p);
sum+=houses[i].getPrice(); //求出第i栋别墅造价并累加
}
cout <<setiosflags(ios::fixed)<<setprecision(2);
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 <iostream> #include <iomanip> 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<n; i++) { cin>>r>>h>>p; //分别表示别墅的房顶半径、墙高、柱子数 houses[i].setData(r,h,p); sum+=houses[i].getPrice(); //求出第i栋别墅造价并累加 } cout <<setiosflags(ios::fixed)<<setprecision(2); cout<<"Total price: " << sum << endl; //输出总造价 return 0; }
相关文章推荐
- A Brief Introduction to PHP Namespacing
- 在Ubuntu 14.04 64bit上安装numpy和matplotlib库
- iOS 并行开发技术之 NSOperation && GCD
- Hibernate3学习笔记(8)——hibernate3缓存管理
- Hadoop分布式文件系统:架构和设计要点
- Android Volley完全解析(四),带你从源码的角度理解Volley
- json 排序
- java回调函数机制
- Android Rom分区 与 SD卡读写
- 使SourceInsight支持Python语言的方法
- weak_ptr解决shared_ptr环状引用所引起的内存泄漏
- OJ期末模考A
- 2015062807 - EffactiveJava笔记 - 第42条 慎用可变参数
- 理解static的作用
- 开源项目
- 毕业五年决定你的命运
- 杭电1005 Number Sequence
- HttpUrlconnection POST提交 用于接口调用传参
- C++第四章 习题
- C#高级编程三十天----泛型结构,泛型方法,泛型委托