Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string ReversePolandNotation::makeCalculations(std::string const &val1, std::string const &val2, char const sign) const
- {
- if (isDigit(val1) && isDigit(val2))
- {
- Operand<int> operand1(std::atoi(val1.c_str()));
- Operand<int> operand2(std::atoi(val2.c_str()));
- switch (sign)
- {
- case '*':
- return std::to_string((operand1 * operand2).getValue());
- break;
- case '-':
- return std::to_string((operand1 - operand2).getValue());
- break;
- case '/':
- return std::to_string((operand1 / operand2).getValue());
- break;
- case '+':
- return std::to_string((operand1 + operand2).getValue());
- break;
- }
- }
- else if(isDigit(val1) && isAlpha(val2))
- {
- Operand<int> operand1(std::atoi(val1.c_str()));
- Operand<std::string> operand2(val2);
- switch (sign)
- {
- case '*':
- return (operand1 * operand2).getValue();
- break;
- case '+':
- return (operand1 + operand2).getValue();
- break;
- }
- }
- else if (isAlpha(val1) && isAlpha(val2))
- {
- Operand<std::string> operand1(val1);
- Operand<std::string> operand2(val2);
- switch (sign)
- {
- case '+':
- return (operand1 + operand2).getValue();
- break;
- }
- }
- else if(isAlpha(val1) && isDigit(val2))
- {
- Operand<std::string> operand1(val1);
- Operand<int> operand2(std::atoi(val2.c_str()));
- switch (sign)
- {
- case '*':
- return (operand1 * operand2).getValue();
- break;
- case '+':
- return (operand1 + operand2).getValue();
- break;
- }
- }
- return "#Calculation Error";
- }
Advertisement
Add Comment
Please, Sign In to add comment