#include<iostream>
#include<iomanip>
using namespace std;
#define PI 3.1415926535
class Pool
{
private:
double radius;//池子的半径
double width;//走道的宽度
const static double railPrice;
const static double pathPrice;
public:
//Pool() :radius(0), width(0) {}//默认构造函数
Pool(double r, double w) :radius(r), width(w) {}//构造函数
double railLength() { return 2 * PI*radius; }
double pathArea() { return PI*(2 * width*radius + width*width); }
double getPrice() { return railLength()*railPrice + pathArea()*pathPrice; }
};
const double Pool::railPrice = 36.4;
const double Pool::pathPrice = 167.5;
int main()
{
Pool pool[5] = { Pool(12.2, 3),Pool(5, 2.8),Pool(4.8, 1),Pool(6, 1.4),Pool(8.7, 2.3) };
for (int i = 0;i < 5;++i)
{
cout << "第" << i + 1 << "个水池的造价为:" << setiosflags(ios::fixed) << setprecision(2)<< pool[i].getPrice() << endl;
}
}
ll
最新推荐文章于 2024-11-07 16:51:25 发布