c++高手来帮忙

利用重载函数,编写计算球、正方形、长方形、圆锥形的体积。
要求1:输入根据屏幕输入的边长或半径求出相应的体积。
要求2:有友好的用户输入界面

下面这个程序还有很多bug,第一:老师需要这个程序既能输入数字,又能输入字母,但这个程序无法通过输入字母来选择!!!(所以作业无法通过) 第二:程序本身存在一些bug!!!
#include<iostream>
#include<cmath>
//#include<windows.h>
using namespace std;
#define PI 3.14159;//宏定义PI
int chose;//定义一个整形变量 chose
bool chose2;
double aa,tt,a,b,c,h,r,hh,rr;//定义双精度形的aa tt a b c h r hh rr
double v(double r);
double v(double tt,int);
double v(double a,double b,double c);
double v(double h,double r);
double v(double h1,double r1,int);

int main()
{cout<<" =================== "<<endl;
cout<<" *********各种立体体积计算************ "<<endl;
cout<<" =================== "<<'\t'<<endl;
T1:cout<<" 请输入你想计算立体图形"<<endl;
system("color 3e");
cout<<" 球体=1,正方体=2,长方体=3,圆锥=4"<<endl;
cin>>chose;
while(chose!=1&&chose!=2&&chose!=3&&chose!=4)
{
cout<<" 输入错误";
cout<<" 请输入你想计算立体图形"<<endl;
system("pause");cin>>chose;
}
switch(chose)
{
case 1:
{
cout<<"请输入球的半径:"<<endl;
cout<<"a=";
cin>>aa;
cout<<"球的体积是:"<<v(aa)<<'\n';
}break;
case 2:
{
cout<<"请输入正方体的边长:"<<endl;
cout<<"a=";
cin>>tt;
cout<<"正方体的体积是:"<<v(tt,2)<<'\n';
}break;
case 3:
{
cout<<"请输入长方体的边长a,b,c:"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
cout<<"长方体的体积是:"<<v(a,b,c)<<'\n';
}break;
case 4:
{
cout<<"请输入圆锥半径、高:"<<endl;
cout<<"r=";
cin>>rr;
cout<<"h=";
cin>>hh;
cout<<"圆锥的体积是:"<<v(hh,rr,3)<<'\n';
}break;

}
cout<<"是否想继续体积计算"<<endl;
cout<<"是=1,否=2"<<endl;
cin>>chose2;
if(chose2==1)goto T1;
else;

return 0;
}

double v(double)
{
return 4.0/3.0*aa*aa*aa*PI;
}
double v(double,int)
{
return tt*tt*tt;
}
double v(double,double,double)
{
return a*b*c;
}
double v(double,double)
{
return 4.0*r*r*h*PI;
}
double v(double,double,int)
{
return 4.0/3*rr*rr*hh*PI;
}

我都帮你调试好了 一些错误都点出来了
#include<iostream>
#include<cmath>
//#include<windows.h>
using namespace std;
#define PI 3.14159//宏定义PI 不能加“;”
char chose; //可以定义成字符类型的
int x;
//int chose;//定义一个整形变量 chose
//bool chose2;
double aa,tt,a,b,c,h,r,hh,rr;//定义双精度形的aa tt a b c h r hh rr
double v(double r);
double v(double tt,int);
double v(double a,double b,double c);
double v(double h,double r);
double v(double h1,double r1,int);

int main()
{
while(1)
{
cout<<" =================== "<<endl;
cout<<" *********各种立体体积计算************ "<<endl;
cout<<" =================== "<<'\t'<<endl;
cout<<" 请输入你想计算立体图形"<<endl;
system("color 3e");
cout<<" 1(A) 球体,2(B) 正方体,3(C) 长方体,4(D) 圆锥, 5(E) 退出"<<endl;//直接通过用户选择是否继续
cin>>chose;
x=int (chose)-48;
if(x>=6)
x=x-16;
while(x!=1&&x!=2&&x!=3&&x!=4&&x!=5)
{
cout<<" 输入错误";
cout<<" 请输入你想计算立体图形"<<endl;
system("pause");
// cin>>chose; 输入错误后不能继续就是因为这个没改过来
// cin>>x;
while(x!=1&&x!=2&&x!=3&&x!=4&&x!=5)
{
cout<<" 输入错误";
cout<<" 请输入你想计算立体图形"<<endl;
system("pause");
cin>>chose; // 加上下面几行判断处理代码就没问题了
x=int (chose)-48;
if(x>=6)
x=x-16;
}
}

switch(x)//switch 语句的case不要用{}
{
case 1:

cout<<"请输入球的半径:"<<endl;
cout<<"a=";
cin>>aa;
cout<<"球的体积是:"<<v(aa)<<'\n';
break;
case 2:

cout<<"请输入正方体的边长:"<<endl;
cout<<"a=";
cin>>tt;
cout<<"正方体的体积是:"<<v(tt,2)<<'\n';
break;
case 3:

cout<<"请输入长方体的边长a,b,c:"<<endl;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
cout<<"长方体的体积是:"<<v(a,b,c)<<'\n';
break;
case 4:

cout<<"请输入圆锥半径、高:"<<endl;
cout<<"r=";
cin>>rr;
cout<<"h=";
cin>>hh;
cout<<"圆锥的体积是:"<<v(hh,rr,3)<<'\n';
break;

}
// cout<<"是否想继续体积计算"<<endl;
// cout<<"是=1,否=2"<<endl;
// cin>>chose2;
// if(chose2==1)goto T1; 不要使用goto语句!!
// else;
if(x==5)
break;
}

return 0;
}

double v(double)
{
return 4.0/3.0*aa*aa*aa*PI;
}
double v(double,int)
{
return tt*tt*tt;
}
double v(double,double,double)
{
return a*b*c;
}
double v(double,double)
{
return 4.0*r*r*h*PI;
}
double v(double,double,int)
{
return 4.0/3*rr*rr*hh*PI;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-12-12
首先,宏定义那句不该有分号,否则相当于定义PI为“3.14159;”
相似回答