编程泳池
❶ 编程 游泳池改造预算,Circle类
游泳池改造预算,circle类
#include<iostream>
using namespace std;
const float
pi=(float)3.14159;
const float FencePrice=35.;
const float
ConcretePrice=20.;
class circle
//定义类circle及其数据和方法
{
public:
circle(float
r); //构造函数
float
circumference(); //计算圆周长
float
area();
//计算圆面积
private:
float radius;
};
circle::circle(float r) //构造函数初始化数据成员radius
{
radius=r;
}
float circle:: circumference() //计算圆的周长
{
return
2*pi*radius;
}
float circle:: area()
//计算圆的面积
{
return pi*radius*radius;
}
//主函数实现
int main()
{
float radius;
float
Fencecost,Concretecost;
cout<<"Enter the radius of the
pool:"<<endl;
cin>>radius;
circle
Pool(radius); //声明Circle类对象
circle PoolRium(radius+3);
//计算栅栏造价并输出
Fencecost=PoolRium.circumference()*FencePrice;
cout<<"Fencing Cost is:"<<Fencecost<<endl;
//计算国道造价并输出
Concretecost=(PoolRium.area()-Pool.area())*ConcretePrice;
cout<<"Concrete Cost is:"<<Concretecost<<endl;
}
❷ 游泳池经费预算C++编程题
// 类的实现
/******start******/
Circle::Circle(float r)
{
radius = r ;
}
/******end******/
float Circle::GetRadius()const
{
/******start******/
return radius;
/******end******/
}