注:普通计算是我自己做的(无人帮助)
谁能想到我三级还没过
#include <iostream>
#include <stack>
#include<windows.h>
#include <math.h>
#include <cmath>
using namespace std;
double inStack();
void calculate(stack<char>& Ope, stack<double>& Num);
void factorial(stack<double>& Num);
int priority(char ope_);
const double PI=3.14;
double s_changfangxing(double a,double b){
return a*b;
}
double c_changfangxing(double a,double b){
return a+a+b+b;
}
double c_zhengfangxing(double a){
return a*4.0;
}
double c_sanjiaoxing(double a,double b,double c){
return a+b+c;
}
double s_zhengfangxing(double a){
return a*a;
}
double c_yuan(double r){
return r*2.0*PI;
}
double s_yuan(double r){
return r*r*PI;
}
double s_sanjiaoxing(double a,double h){
return a*h/2.0;
}
double v_yuanzhu(double r,double h){
return PI*r*r*h;
}
double s_yuanzhu(double r,double h){
double d;
d=r+r;
return 2*PI*r*r+PI*d*h;
}
double v_yuanzhui(double r,double h){
double a;
a=PI*r*r*h;
return a/3.0;
}
double v_changfangti(double a,double b,double c){
return a*b*c;
}
double v_zhengfangti(double a){
return a*a*a;
}
double sb_changfangti(double a,double b,double c){
return 2.0*(a*b+a*c+b*c);
}
double sb_zhengfangti(double a){
return 6.0*a*a;
}
double sb_yuanzhu(double r,double h){
return 2*s_yuan(r)+c_yuan(r)*h;
}
int main()
{
int a,b,c,d,e;
bool flag=true;
double c_chang_a,c_chang_b,c_zheng_a,c_yuan_r,c_sanjiaoxing_a,c_sanjiaoxing_b,c_sanjiaoxing_c,s_chang_a,s_chang_b,s_zheng_a,s_yuan_r,s_sanjiaoxing_a,s_sanjiaoxing_h,v_changfangti_a,v_changfangti_b,v_changfangti_c,v_zhengfangti_a,v_yuanzhui_r,v_yuanzhui_h,v_yuanzhu_r,v_yuanzhu_h,sb_changfangti_a,sb_changfangti_b,sb_changfangti_c,sb_zhengfangti_a,sb_yuanzhu_r,sb_yuanzhu_h;
cout<<"欢迎来到计算器!\n"<<endl;
system("pause");
system("cls");
while(flag){
Sleep(1000);
cout<<"请问你要:1.计算周长;2.计算面积;3.计算体积;4.计算表面积;5.普通计算;6.退出\n";
cin>>a;
switch(a){
case 1:
cout<<"请问你要计算哪种图形的周长:\n";
cout<<"1.长方形;2.正方形;3.圆(π取3.14);4.三角形 \n";
cin>>b;
switch(b){
case 1:
cout<<"请输入长方形的长:\n";
cin>>c_chang_a;
cout<<"请输入长方形的宽:\n";
cin>>c_chang_b;
cout<<"长方形的周长:\n"<<c_changfangxing(c_chang_a,c_chang_b)<<endl;
system("pause");
system("cls");
break;
case 2:
cout<<"请输入正方形的边长:\n";
cin>>c_zheng_a;
cout<<"正方形的周长:\n"<<c_zhengfangxing(c_zheng_a)<<endl;
system("pause");
system("cls");
break;
case 3:
cout<<"请输入圆的半径:\n";
cin>>c_yuan_r;
cout<<"圆的周长大约是:\n"<<c_yuan(c_yuan_r)<<endl;
system("pause");
system("cls");
break;
case 4:
cout<<"请输入三角形的第一条边:\n";
cin>>c_sanjiaoxing_a;
cout<<"请输入三角形的第二条边:\n";
cin>>c_sanjiaoxing_b;
cout<<"请输入三角形的第三条边:\n";
cin>>c_sanjiaoxing_c;
cout<<"三角形的周长是:\n"<<c_sanjiaoxing(c_sanjiaoxing_a,c_sanjiaoxing_b,c_sanjiaoxing_c)<<endl;
system("pause");
system("cls");
break;
default:
cout<<"输入错误,请重新输入!\n"<<endl;
Sleep(2000);
system("pause");
break;
}
break;
case 2:
cout<<"请问你要计算哪种图形的面积:\n";
cout<<"1.长方形;2.正方形;3.圆(π取3.14);4.三角形 \n";
cin>>c;
switch(c){
case 1:
cout<<"请输入长方形的长:\n";
cin>>s_chang_a;
cout<<"请输入长方形的宽:\n";
cin>>s_chang_b;
cout<<"长方形的面积:\n"<<s_changfangxing(s_chang_a,s_chang_b)<<endl;
system("pause");
system("cls");
break;
case 2:
cout<<"请输入正方形的边长:\n";
cin>>s_zheng_a;
cout<<"正方形的面积:\n"<<s_zhengfangxing(s_zheng_a)<<endl;
system("pause");
system("cls");
break;
case 3:
cout<<"请输入圆的半径:\n";
cin>>s_yuan_r;
cout<<"圆的面积大约是:\n"<<s_yuan(s_yuan_r)<<endl;
system("pause");
system("cls");
break;
case 4:
cout<<"请输入三角形的底:\n";
cin>>s_sanjiaoxing_a;
cout<<"请输入三角形的高:\n" ;
cin>>s_sanjiaoxing_h;
cout<<"三角形的面积是:\n"<<s_sanjiaoxing(s_sanjiaoxing_a,s_sanjiaoxing_h)<<endl;
system("pause");
system("cls");
break;
default:
cout<<"输入错误,请重新输入!\n"<<endl;
Sleep(2000);
system("cls");
break;
break;
}
case 3:
cout<<"请问你要计算哪种图形的体积:\n";
cout<<"1.长方体;2.正方体;3.圆锥(π取3.14);4.圆柱(π取3.14) \n";
cin>>d;
switch(d){
case 1:
cout<<"请输入长方体的长:\n";
cin>>v_changfangti_a;
cout<<"请输入长方体的宽:\n";
cin>>v_changfangti_b;
cout<<"请输入长方体的高:\n";
cin>>v_changfangti_c;
cout<<"长方体的体积是:\n"<<v_changfangti(v_changfangti_a,v_changfangti_b,v_changfangti_c)<<endl;
system("pause");
system("cls");
break;
case 2:
cout<<"请输入正方体的棱长:\n";
cin>>v_zhengfangti_a;
cout<<"正方体的体积:"<<v_zhengfangti(v_zhengfangti_a)<<endl;
system("pause");
system("cls");
break;
case 3:
cout<<"请输入圆锥的底面半径:\n";
cin>>v_yuanzhui_r;
cout<<"请输入圆锥的高:\n";
cin>>v_yuanzhui_h;
cout<<"圆锥的体积大约是:\n"<<v_yuanzhui(v_yuanzhui_r,v_yuanzhui_h)<<endl;
system("pause");
system("cls");
break;
case 4:
cout<<"请输入圆柱的底面半径:\n";
cin>>v_yuanzhu_r;
cout<<"请输入圆柱的高:\n";
cin>>v_yuanzhui_h;
cout<<"圆柱的体积大约是:\n"<<v_yuanzhu(v_yuanzhu_r,v_yuanzhu_h)<<endl;
system("pause");
system("cls");
break;
default:
cout<<"输入错误,请重新输入!\n"<<endl;
Sleep(2000);
system("pause");
break;
}
break;
case 4:
cout<<"请问你要计算哪种图形的表面积:\n";
cout<<"1.长方体;2.正方体;3.圆柱(π取3.14) \n";
cin>>e;
switch(e){
case 1:
cout<<"请输入长方体的长:\n";
cin>>sb_changfangti_a;
cout<<"请输入长方体的宽:\n";
cin>>sb_changfangti_b;
cout<<"请输入长方体的高:\n";
cin>>sb_changfangti_c;
cout<<"长方体的表面积是:\n"<<sb_changfangti(sb_changfangti_a,sb_changfangti_b,sb_changfangti_c);
system("pause");
system("cls");
break;
case 2:
cout<<"请输入正方体的棱长:\n";
cin>>sb_zhengfangti_a;
cout<<"正方体的表面积:\n"<<sb_zhengfangti(sb_zhengfangti_a)<<endl;
system("pause");
system("cls");
break;
case 3:
cout<<"请输入圆柱的底面半径:\n";
cin>>sb_yuanzhu_r;
cout<<"请输入圆柱的高:\n";
cin>>sb_yuanzhu_h;
cout<<"圆柱的表面积大约是:\n"<<sb_yuanzhu(sb_yuanzhu_r,sb_yuanzhu_h)<<endl;
system("pause");
system("cls");
break;
default:
cout<<"输入错误,请重新输入!\n"<<endl;
Sleep(2000);
system("cls");
}
break;
case 5:
int aaa;
char op;
double num1, num2;
cout<<"请问你要计算什么:\n";
cout<<"1.加法;2.减法;3.乘法;4.除法;5.开方(开根号)\n" ;
cin>>aaa;
switch (aaa) {
case 1:
cout << "请输入两个操作数(中间打空格): \n";
cin >> num1 >> num2;
cout<<" 答案: ";
cout << num1 << " + " << num2 << " = " << num1 + num2<<"\n";
break;
case 2:
cout << "请输入两个操作数(中间打空格): \n";
cin >> num1 >> num2;
cout<<" 答案: ";
cout << num1 << " - " << num2 << " = " << num1 - num2<<"\n";
break;
case 3:
cout << "请输入两个操作数(中间打空格): \n";
cin >> num1 >> num2;
cout<<" 答案: ";
cout << num1 << " * " << num2 << " = " << num1 * num2<<"\n";
break;
case 4:
ads:
cout << "请输入两个操作数(中间打空格): \n";
cin >> num1 >> num2;
cout<<" 答案: ";
if (num2 != 0)
cout << num1 << " / " << num2 << " = " << num1 / num2<<"\n";
else{
cout << "\n除数不能为零!!!\n";
Sleep(1000);
cout<<"请重新输入!\n"<<endl;
Sleep(2000);
system("cls");
goto ads;
}
break;
case 5:
cout << "请输入一个操作数: \n";
cin >> num1 ;
cout<<" 答案: ";
cout<<sqrt(num1)<<"\n";
break;
default:
cout<<"输入错误,请重新输入!\n"<<endl;
Sleep(2000);
system("cls");
}
break;
case 6:
flag=false;
break;
default:
cout<<"输入错误,请重新输入!\n"<<endl;
Sleep(2000);
system("cls");
}
}
return 0;
}
共 7 条回复
更新
主要是最近要弄生地会考,都没时间开发了
@lyhldy 的确是加了点
不过那个普通计算是我还在开发中的
http://st.cpolar.cn/article/4215
嗯,第一眼我也以为是抄袭
为什么看着那么眼熟……
等等我之前好像发过差不多的