#include<iostream>
#include<cmath>
#define PI 3.1415926
using namespace std;
class Cylinder
{
private:
float r,h;
public:
Cylinder(float,float);
float perimeter(); //底圆周长
float circleArea(); //底圆面积
float volume(); //圆柱体体积
float getH();
};
Cylinder::Cylinder(float num1,float num2)
{
r=num1;
h=num2;
}
float Cylinder::perimeter()
{
return 2*PI*r;
}
float Cylinder::circleArea()
{
return PI*pow(r,2);
}
float Cylinder::volume()
{
return circleArea()*h;
}
float Cylinder::getH()
{
return h;
}
//计算圆柱体表面积
float cylinderArea(float r,float h)
{
Cylinder cy=Cylinder(r,h);
float perimeter=cy.perimeter(); //底圆周长
float circleArea=cy.circleArea(); //底圆面积
float output;
output=circleArea*2;
output+=perimeter*cy.getH();
return output;
}
//计算圆柱体体积
float volume(float r,float h)
{
Cylinder cy=Cylinder(r,h);
return cy.volume();
}
int main()
{
Cylinder cy=Cylinder(1,10);
cout<<"底圆周长:"<<cy.perimeter()<<"\t底圆面积:"<<cy.circleArea()
<<"\t圆柱体体积"<<cy.volume()<<endl;
cout<<"================="<<endl;
cout<<"cylinderArea(float r,float h):"<<cylinderArea(1,10)
<<"\tvolume(float r,float h):"<<volume(1,10);
}