#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include <iostream>
#include <cstdlib>
using namespace std;
/*
简单的整数计算器
能够进行加、减、乘除运算。
采用中缀输入法 ,一次输入整个算式得出结果
缺点:不识别"( )",不能输入负数
输入
5*7+9-4+12
输出
52
输入
25*4+25*4+135/3+43-232/33
输出
281
输入
34524+42884*323/2334
输出
40458
*/
class Calculator //计算器类
{
public:
void clear(); //清空操作数栈
// 连续将两个操作数和一个操作符弹出栈
char getpop();//double &op1,double &op2,char &ch
void compute();// 执行运算
void ops_or_ods(string str);
stack<double> ods; //操作数栈
stack<char> ops;//操作符栈
};
int level(char ch) //判断输入的运算符的优先级
{
switch (ch)
{
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
default:
return -1;
}
}
void Calculator::compute() //执行运算
{