#include <iostream>
using namespace std;
class Cylinder{
private:
double h;
double r;
public:
static double PI;
public:
Cylinder(double i,double j):h(i),r(j) { };
~Cylinder(){ }
void GetRadius();
void GetHeight();
void SetRadius(double i);
void SetHeight(double i);
void Volume();
void Area();
};
double Cylinder::PI = 3.1415926;
void Cylinder::GetRadius()
{
cout<<this->r;
}
void Cylinder::GetHeight()
{
cout<<this->h;
}
void Cylinder::SetRadius(double i)
{
this->r=i;
}
void Cylinder::SetHeight(double i)
{
this->h=i;
}
void Cylinder::Volume()
{
cout<<PI*r*r*h;
}
void Cylinder::Area()
{
cout<<PI*r*r*2+2*PI*r*h;
}
int main()
{
double h,r;
cin>>h>>r;
Cylinder c(h,r);
cout<<"pi="<<Cylinder::PI<<", height=";
c.GetHeight();
cout<<", radius=";
c.GetRadius() ;
cout<<":volume=";
c.Volume() ;
cout<<", area=";
c.Area() ;
return 0;
}
代码编写不易,如果对您有帮助,谢谢您的点赞支持~