ll

本文介绍了一个使用C++实现的泳池及其周边设施造价计算程序。该程序定义了一个名为Pool的类,通过输入泳池半径和走道宽度来计算围栏长度、路径面积及总造价,并展示了五个不同尺寸泳池的具体造价。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值