建设游泳池

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Fiverya/article/details/88837069

建设圆形游泳池如图所示,现在需要在其周围建一圆形过道,并在其四周围上栅栏。栅栏的价格是35元/米,过道造价是20元/平方米。过道宽度为3米,游泳池半径由键盘输入。要求编程计算并输出过道和栅栏的造价。(pi=3.14159)

提示:声明类Circle,其数据成员为半径,其成员函数为构造函数、求周长函数、求面积函数。

#include<iostream>  
using namespace std;  
class Circle  
    {  
        float r;  
        public:  
            Circle() {cout<<"Enter the radius of the pool:";cin>>r;cout<<r<<endl;};  
            ~Circle() {};  
            float Perimeter() {return 2*3.14159*(r+3);};  
            float Area() {return 3.14159*(6*r+9);};  
     };  
int main ()  
{  
    Circle circle;  
    cout<<"Fencing Cost is "<<circle.Perimeter()*35<<endl<<"Concrete Cost is "<<circle.Area()*20<<endl;  
} 

猜你喜欢

转载自blog.csdn.net/Fiverya/article/details/88837069