这是大约10个月前,
我做的一个小程序
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void gs(long long h,long long l,string z)
{
for(long long i=1;i<=h;i++)
{
cout<<endl;
}
cout<<setw(l)<<z;
}
long long jjcc(long long a,long long b,char j)
{
switch(j)
{
case '+':a=a+b;break;
case '-':a=a-b;break;
case '*':a=a*b;break;
case '/':a=a/b;break;
}
return a;
}
int main()
{
string n;
char j='+';
long long tot=0,s=0;
gs(1,3,"");
cout<<"计算器"<<endl<<endl;
cout<<"注意事项:"<<endl<<endl;
gs(0,2,"1.对不起,因本计算器系统");
gs(1,2,"低级,在复合算式中,运算没");
gs(1,2,"有先后之分,一律从左往右计");
gs(1,2,"算。");
gs(2,2,"2.除法只会得出向下取整的");
gs(1,2,"商。");
gs(1,2,"3.不支持负数运算");
gs(2,2,"");
system("pause");
system("cls");
gs(1,2,"算式:");
cin>>n;
for(long long i=0;i<n.size();i++)
{
if(n[i]>='0'&&n[i]<='9')
{
s=s*10+n[i]-'0';
}
else
{
tot=jjcc(tot,s,j);
s=0;
switch(n[i])
{
case '+':j='+';break;
case '-':j='-';break;
case '*':j='*';break;
case '/':j='/';break;
}
}
}
tot=jjcc(tot,s,j);
gs(0,n.size()+7,"=");
cout<<tot;
return 0;
}