ll

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

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章