用C语言 编辑一个求圆锥体表面积与体积的代码
2个回答
2013-10-31
展开全部
我来回答#include<iostream>
#include<cmath>
#define N 3.1415
using namespace std;
class Height
{
private:
float h;
public:
Height(float h):h(h)
{}
float getheight()
{
return h;
}
};
class Circle
{
private:
float radius;
public:
Circle(float r):radius(r)
{}
float getradius();
float area();
};
float Circle::getradius()
{
return radius;
}
float Circle::area()
{
return N*radius*radius;
}
class cone:public Height,public Circle
{
private:
float line;
public:
cone(float h,float r):Height(h),Circle(r)
{}
void getline();
float surarea();
float volume();
void show();
};
void cone::getline()
{
float a=getradius();
float b=getheight();
line=sqrt(a*a+b*b);
}
float cone::surarea()
{
return area()+N*getradius()*line;
}
float cone::volume()
{
return area()*getheight()/3;
}
void cone::show()
{
cout<<"圆锥的表面积为:"<<surarea()<<endl;
cout<<"圆锥的体积为:"<<volume()<<endl;
}
int
main()
{
cone A(4,3);
A.getline();
A.surarea();
A.volume();
A.show();
return 0;
}
#include<cmath>
#define N 3.1415
using namespace std;
class Height
{
private:
float h;
public:
Height(float h):h(h)
{}
float getheight()
{
return h;
}
};
class Circle
{
private:
float radius;
public:
Circle(float r):radius(r)
{}
float getradius();
float area();
};
float Circle::getradius()
{
return radius;
}
float Circle::area()
{
return N*radius*radius;
}
class cone:public Height,public Circle
{
private:
float line;
public:
cone(float h,float r):Height(h),Circle(r)
{}
void getline();
float surarea();
float volume();
void show();
};
void cone::getline()
{
float a=getradius();
float b=getheight();
line=sqrt(a*a+b*b);
}
float cone::surarea()
{
return area()+N*getradius()*line;
}
float cone::volume()
{
return area()*getheight()/3;
}
void cone::show()
{
cout<<"圆锥的表面积为:"<<surarea()<<endl;
cout<<"圆锥的体积为:"<<volume()<<endl;
}
int
main()
{
cone A(4,3);
A.getline();
A.surarea();
A.volume();
A.show();
return 0;
}
2013-10-31
展开全部
若圆锥体底半径r, 高h,
则体积=(1/3)*h*π*r^2,
表面积= π*r^2+ π*r√(h^2+r^2)
则体积=(1/3)*h*π*r^2,
表面积= π*r^2+ π*r√(h^2+r^2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询