#include //未实现,通过编译
#include
#include
#include
double jisuan(double a,double b,char ope)
{
switch(ope)
{
case'+': return a+b; break;
case'-': return a-b; break;
case'*': return a*b; break;
case'/': return a/b; break;
}
}
double calculator(string str)
{
getline(cin,str);
vectornum;
vectorope;
istringstream sin(str);
for(int i=0;i<=str.length();i++)
{
if(str[i]=='+'||str[i]=='-'||str[i]=='*'||str[i]=='/')
ope.push_back(str[i]);
else
num.push_back(str[i]);
}
for(int i=0;i if(ope[i]=='*'||ope[i]=='/')
{
jisuan(num[i],num[i+1],ope[i]);
num.erase(num.begin()+i+1);
ope.erase(num.begin()+i);
}
for(int i=0;i {
jisuan(num[i],num[i+1],ope[i]);
num.erase(num.begin()+i+1);
ope.erase(num.begin()+i);
}
return num.front();
}
int main()
{
string s;
cout<<"请输入计算表达式:"< cout<<"计算结果:"< cout< getchar();
}
//在BCB上通过了编译,但不能运行,不知那错了。恳请高手指点!初学编程,或许算法根本就是错的,请大家不要笑话!
--------------------next---------------------
阅读(1149) | 评论(0) | 转发(0) |