Professional Documents
Culture Documents
Basic Calculator
Basic Calculator
if (op.top() == '*')
num.push(a * b);
else if (op.top() == '/')
num.push(a / b);
else if (op.top() == '+')
num.push(a + b);
else if (op.top() == '-')
num.push(a - b);
op.pop();
}
public:
int calculate(string s) {
stack<char> op;
stack<int> num;
string operators("+-*/");
string digits("0123456789");
string number = "";
op.push(s[i]);
} else if (digits.find(s[i]) != string::npos) {
number += s[i];
}
}
num.push(atoi(number.c_str()));
while (!op.empty())
eval(op, num);
return num.top();
}
};