大学项目作业,用了类和选择希望各位大佬可以指点一下。
#include
#include <math.h>
using namespace std;
int n;
class computer //加减乘除
{ public:
int op1, op2;
char ch;
float jisuan();
};
float computer::jisuan() //计算
{ switch (ch)
{ case ‘+’: return(float)(op1 + op2); break;
case ‘-’: return(float)(op1 - op2);; break;
case ‘*’: return(float)(op1 * op2); break;
case ‘/’: if (op2==0)
{cout << “分母不能为零!” << endl; }
return(float)(op1 / op2);
default:
cout << “格式错误!”;
break; }
}float pin(float c[])
{ int m; float max=0;
for ( m = 0; m < n; m++)
{ max += c[m]; }
return (max / n);
}
int jie(int l)
{ int jj,mm=1;
for(jj = 1; jj< l;jj++)
{ mm = mm * (jj + 1); }
return mm;
}
float sj(float tb)
{ float ct;
if (tb<360)
{ ct= cos((tb/180.0)M_PI); }
return ct;
}
int main()
{ computer a[100];
float b[100];
int i,x,c,ti;
cout << "\t\t\t\t\t****************************" <<endl;
cout << “\t\t\t\t\t** 算式前先输入算数个数 " << endl;
cout << "\t\t\t\t\t 本计算器可进行以下计算 " << endl;
cout << "\t\t\t\t\t 1.进行两位数的加减乘除 " << endl;
cout << "\t\t\t\t\t 2.进行平均值的计算 " << endl;
cout << "\t\t\t\t\t 3.求n的阶乘 " << endl;
cout << "\t\t\t\t\t 4.求三角函数cos的值 " << endl;
cout <<"\t\t\t\t\t***************************” << endl; lle:
cout << “\t\t\t\t\t请选择计算种类:” << endl;
cout << “\t\t\t\t\t”; cin >> x;
switch (x) {
case 1:
cout << “\t\t\t\t\t请输入计算式个数:” << endl;
cout << “\t\t\t\t\t”; cin >> n;
cout << “\t\t\t\t\t开始输入算式:” << endl;
cout << “\t\t\t\t\t”;
for (i = 0; i < n; i++)
{ cin >> a[i].op1 >> a[i].ch >> a[i].op2; }
cout << “\t\t\t\t\t”;
for (i = 0; i < n; i++)
{
cout << a[i].op1 << a[i].ch << a[i].op2 << “=”<<a[i].jisuan() << endl; }
break;
case 2:
cout << “\t\t\t\t\t请输入有多少个数:” << endl;
cout << “\t\t\t\t\t”; cin >> n;
cout << “\t\t\t\t\t请开始输入:” << endl;
cout << “\t\t\t\t\t”;
for ( i = 0; i < n; i++)
{ cin >> b[i]; }
pin(b);
cout << “\t\t\t\t\t平均值=” << pin(b) << endl;
break;
case 3:
cout << “\t\t\t\t\t请输入阶乘值n:” << endl;
cout << “\t\t\t\t\t”; cin >> c;
cout <<"\t\t\t\t\t" <<c << “的阶乘为:” << endl;
cout << “\t\t\t\t\t”; cout << jie©<< endl;
break;
case 4:
cout <<"\t\t\t\t\t请选择要求的所求度数(要求小于360度):"<<endl;
cout << “\t\t\t\t\t”; cin>>ti;
cout <<"\t\t\t\t\t该三角函数的值为:"<<endl;
cout << “\t\t\t\t\t”;cout <<sj(ti)<<endl;
break;
default:
cout << “\t\t\t\t\t请输入正确的运算节点” <<endl;
break;
}
goto lle;
}