eturn 2 * PI * radius;
}
// 计算圆的面积
float Circle::Area() const
{
return PI * radius * radius;
}
void main ()
{
float radius;
float FenceCost, ConcreteCost;
// 提示用户输入半径
cout<<"Enter the radius of the pool: ";
cin>>radius;
// 声明 Circle 对象
Circle Pool(radius);
Circle PoolRim(radius + 3);
//计算栅栏造价并输出
FenceCost=PoolRim.Circumference()*FencePrice;
cout<<"Fencing Cost is ¥"<<FenceCost<<endl;
//计算过道造价并输出
ConcreteCost=(PoolRim.Area()-
Pool.Area())*ConcretePrice;
cout<<"Concrete Cost is ¥"<<ConcreteCost<<endl;
}
运行结果
Enter the radius of the pool: 10
Fencing Cost is ¥2858.85
Concrete Cost is ¥4335.39
|