【3.23】建立类cylinder,cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度。用类cylinder计算圆柱体的体积,并储存在一个double变量中。在类cylinder中包含vol,用来显示每个cylinder对象的体积。
#include <iostream>
#include <stdio.h>
using namespace std;
class cylinder
{
public:
double r;
double h;
double vol;
void r_h_input()
{
cout<<"请输入圆柱体的底面半径和圆柱体的高:"<<endl;
cin>>r;
cin>>h;
}
void vol_out()
{vol=3.14*r*r*h;
printf("The volume of cylinder is :%f\n",vol);
}
};
int main()
{
cylinder c1,c2;
c1.r_h_input();
c1.vol_out();
c2.r_h_input();
c2.vol_out();<pre class="cpp" name="code">#include <iostream>
#include <stdio.h>
using namespace std;
class cylinder
{
public:
double r;
double h;
double vol;
void r_h_input()
{
cout<<"请输入圆柱体的底面半径和圆柱体的高:"<<endl;
cin>>r;
cin>>h;
}
void vol_out()
{vol=3.14*r*r*h;
printf("The volume of cylinder is :%f\n",vol);
}
};
int main()
{
cylinder c1,c2;
c1.r_h_input();
c1.vol_out();
c2.r_h_input();
c2.vol_out();
return 0;
}
https://img-blog.csdn.net/20150401181726484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWlhYW96aHUyMDE1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center