#include
#include
#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<<"底圆周长:"< <<"\t圆柱体体积"< cout<<"================="< cout<<"cylinderArea(float r,float h):"< <<"\tvolume(float r,float h):"< } 你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网站标题:用c++计算圆柱体的体积,底圆的面积和周长-创新互联
本文链接:http://bzwzjz.com/article/esjdp.html