# P2 别墅造价几何？

P2 别墅造价几何？

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

``````3
6.4 3 1
10.5 3.2 4
8.4 4.25 0``````

``Total price: 3252256.75``

``````#include <iostream>
#include <iomanip>
using namespace std;

const int roofPrice = 3000; //房顶每平方米的价格
const int wallPrice = 2000;//墙面每平方米的价格
const int pillarPrice = 10000; //每根柱子的价格
//************* begin *****************
const double PI = 3.1415926;
class House
{
public:
void setData(double r, double h, int p)
{
height = h;
pillars = p;
}
double getPrice()
{
float a, s;
return (a+s+pillars*pillarPrice);
}
private:
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;
}``````

``````#include <iostream>
#include <iomanip>
using namespace std;

const int roofPrice = 3000; //房顶每平方米的价格
const int wallPrice = 2000;//墙面每平方米的价格
const int pillarPrice = 10000; //每根柱子的价格
//************* begin *****************
const double PI = 3.1415926;
class House
{
public:
void setData(double r, double h, int p)
{
height = h;
pillars = p;
}
double getPrice()
{
float a, s;
return (a+s+pillars*pillarPrice);
}
private:
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;
}``````