#include<iostream>
using namespace std;
const double PI=3.14;
class cylinder{
public:
cylinder(double x,double y)
{ radius=x;
high=y;
}
double calcu();
void vol();
private:
double radius,high;
};
void cylinder::vol()
{ cout<<"圆柱体的半径:"<<radius<<endl;
cout<<"圆柱体的高度:"<<high<<endl;
cout<<"圆柱体的体积:"<<calcu()<<endl;
}
double cylinder::calcu()
{ return PI*radius*radius*high;}
int main()
{
cylinder r1(1,3);
cylinder r2(3,7);
cout<<"r1的相关信息:"<<endl;
r1.vol();
cout<<"r2的相关信息:"<<endl;
r2.vol();
return 0;
}
3.23
最新推荐文章于 2022-05-13 16:11:59 发布