2015-06-28 14:47:29 OJ期末模考B

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 <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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值