C++问题,编写一个程序计算出球、圆柱和圆锥的表面积和体积#include#includeusing namespace std;#define PI 3.1415class circle{public:\x09void information()\x09{\x09 \x09\x09double a;\x09\x09couta;\x09}};class sphere:public circle{p
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 15:40:23
C++问题,编写一个程序计算出球、圆柱和圆锥的表面积和体积#include#includeusing namespace std;#define PI 3.1415class circle{public:\x09void information()\x09{\x09 \x09\x09double a;\x09\x09couta;\x09}};class sphere:public circle{p
C++问题,编写一个程序计算出球、圆柱和圆锥的表面积和体积
#include
#include
using namespace std;
#define PI 3.1415
class circle
{
public:
\x09void information()
\x09{\x09
\x09\x09double a;
\x09\x09couta;
\x09}
};
class sphere:public circle
{
public:
void first(double s1,double a)
\x09{
\x09\x09double v1;
\x09\x09s1=4*PI*a*a;
//第一二处错误
v1=(PI*a*a*a*4)/3;
cout
C++问题,编写一个程序计算出球、圆柱和圆锥的表面积和体积#include#includeusing namespace std;#define PI 3.1415class circle{public:\x09void information()\x09{\x09 \x09\x09double a;\x09\x09couta;\x09}};class sphere:public circle{p
你的程序何止那几处错误,简直惨不忍睹.
我简单的修改了,编译通过了.
#include <iostream>#include <string>
using namespace std;
#define PI 3.1415
class circle
{
public:
void information(double & a)
{\x09
cout<<"请输入半径:";
cin>>a;
}
};
class sphere:public circle
{
public:
void first(double a)
{
double v1;
double s1;
s1=4*PI*a*a;
//第一二处错误
v1=(PI*a*a*a*4)/3 ;
cout<<"球的表面积为:"<<s1<<endl<<"球的体积为:"<<v1<<endl;
}\x09
};
class cylinder:public circle
{
public:
void second(double a)
{
double s2;
double v2;
double h;
cout<<"请输入圆柱的高:";
cin>>h;
s2=2*2*PI*a*a+2*PI*a*h;
v2=2*PI*a*a*h;
cout<<"圆柱的表面积为:"<<s2<<endl<<"圆柱的体积为:"<<v2<<endl;
}
};
class cone:public circle
{
public:
void third(double a)
{
double s2;
double v2;
double l;
cout<<"请输入圆锥的高:";
cin>>l;
s2=2*PI*a*a+PI*a*l;
v2=2*PI*a*a*l/3;
cout<<"圆锥的表面积为:"<<s2<<endl<<"圆锥的体积为:"<<v2<<endl;
}
};
void main()
{
int chose;
double a;
double h;
double l;
cin>>chose;
circle bason;
bason.information(a);
cout<<"请选择:"<<endl<<"求球请输入1"<<endl<<"求圆柱请输入2"<<endl<<"求圆锥请输入3"<<endl;
if(chose==1)
{
sphere bason;
//第三处错误
bason.first(a);
}
else if(chose==2)
{
cylinder bason;
bason.second(a);
}
else if(chose==3)
{
cone bason;
bason.third(a);
}
}