C++问题,编写一个程序计算出球、圆柱和圆锥的表面积和体积
#include<iostream>#include<string>usingnamespacestd;#definePI3.1415classcircle{public...
#include<iostream>
#include<string>
using namespace std;
#define PI 3.1415
class circle
{
public:
void information()
{
double a;
cout<<"请输入半径:";
cin>>a;
}
};
class sphere:public circle
{
public:
void first(double s1,double a)
{
double v1;
s1=4*PI*a*a;
//第一二处错误
v1=(PI*a*a*a*4)/3;
cout<<"球的表面积为:"<<s1<<endl<<"球的体积为:"<<v1<<endl;
}
};
class cylinder:public circle
{
public:
void second()
{
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 s3;
double v3;
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();
cout<<"请选择:"<<endl<<"求球请输入1"<<endl<<"求圆柱请输入2"<<endl<<"求圆锥请输入3"<<endl;
if(chose==1)
{
sphere bason;
//第三处错误
bason.first();
}
else if(chose==2)
{
cylinder bason;
bason.second();
}
else if(chose==3)
{
cone bason;
bason.third();
}
};
出现的提示错误是:
C:\Users\bason\Desktop\zgch.cpp(25) : error C2018: unknown character '0xa3'
C:\Users\bason\Desktop\zgch.cpp(25) : error C2018: unknown character '0xbb'
C:\Users\bason\Desktop\zgch.cpp(78) : error C2660: 'first' : function does not take 0 parameters
执行 cl.exe 时出错.
求解要怎么改正啊 展开
#include<string>
using namespace std;
#define PI 3.1415
class circle
{
public:
void information()
{
double a;
cout<<"请输入半径:";
cin>>a;
}
};
class sphere:public circle
{
public:
void first(double s1,double a)
{
double v1;
s1=4*PI*a*a;
//第一二处错误
v1=(PI*a*a*a*4)/3;
cout<<"球的表面积为:"<<s1<<endl<<"球的体积为:"<<v1<<endl;
}
};
class cylinder:public circle
{
public:
void second()
{
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 s3;
double v3;
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();
cout<<"请选择:"<<endl<<"求球请输入1"<<endl<<"求圆柱请输入2"<<endl<<"求圆锥请输入3"<<endl;
if(chose==1)
{
sphere bason;
//第三处错误
bason.first();
}
else if(chose==2)
{
cylinder bason;
bason.second();
}
else if(chose==3)
{
cone bason;
bason.third();
}
};
出现的提示错误是:
C:\Users\bason\Desktop\zgch.cpp(25) : error C2018: unknown character '0xa3'
C:\Users\bason\Desktop\zgch.cpp(25) : error C2018: unknown character '0xbb'
C:\Users\bason\Desktop\zgch.cpp(78) : error C2660: 'first' : function does not take 0 parameters
执行 cl.exe 时出错.
求解要怎么改正啊 展开
2个回答
展开全部
你的程序何止那几处错误,简直惨不忍睹。
我简单的修改了,编译通过了。
#include <iostream>
#include <string>
using namespace std;
#define PI 3.1415
class circle
{
public:
void information(double & a)
{
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;
}
};
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);
}
}
东莞大凡
2024-11-14 广告
2024-11-14 广告
标定板认准大凡光学科技,专业生产研发厂家,专业从事光学影像测量仪,光学投影测量仪.光学三维测量仪,光学二维测量仪,光学二维测量仪,光学三维测量仪,光学二维测量仪.的研发生产销售。东莞市大凡光学科技有限公司创立于 2018 年,公司总部坐落于...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询