求圆柱体体积

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

求圆柱体的体积,将结果输出到屏幕上。

要求:( 1 )头文件用 iostream.h ,输入输出用 cin 、 cout 。

   ( 2 )定义圆柱体类,两个数据成员,圆柱体的半径和高、两个成员函数,构造函数实现设置半径和高,另一个实现计算圆柱体体积。

           ( 3 )在主函数中实现输入圆柱体的半径、高,计算体积并输出结果。(pai =3.14 )

#include<iostream>  
using namespace std;  
class Yuanzhu  
{     
    public:  
        double r,high;  
        void input()  
            {  
                cin>>r>>high;  
            }  
        void Volume()  
            {   double volume;  
                volume=3.14*r*r*high;  
                cout<<volume<<endl;   
            }  
};  
int main()  
{Yuanzhu yuanzhu;  
yuanzhu.input();  
cout<<"v=";  
yuanzhu.Volume();  
return 0;  
} 

猜你喜欢

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