Guest User

uno

a guest
Nov 25th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. std::string ReversePolandNotation::makeCalculations(std::string const &val1, std::string const &val2, char const sign) const
  2. {
  3.     if (isDigit(val1) && isDigit(val2))
  4.     {
  5.         Operand<int> operand1(std::atoi(val1.c_str()));
  6.         Operand<int> operand2(std::atoi(val2.c_str()));
  7.         switch (sign)
  8.         {
  9.         case '*':
  10.             return std::to_string((operand1 * operand2).getValue());
  11.             break;
  12.         case '-':
  13.             return std::to_string((operand1 - operand2).getValue());
  14.             break;
  15.         case '/':
  16.             return std::to_string((operand1 / operand2).getValue());
  17.             break;
  18.         case '+':
  19.             return std::to_string((operand1 + operand2).getValue());
  20.             break;
  21.         }
  22.     }
  23.     else if(isDigit(val1) && isAlpha(val2))
  24.     {
  25.         Operand<int> operand1(std::atoi(val1.c_str()));
  26.         Operand<std::string> operand2(val2);
  27.         switch (sign)
  28.         {
  29.         case '*':
  30.             return (operand1 * operand2).getValue();
  31.             break;
  32.         case '+':
  33.             return (operand1 + operand2).getValue();
  34.             break;
  35.         }
  36.     }
  37.     else if (isAlpha(val1) && isAlpha(val2))
  38.     {
  39.         Operand<std::string> operand1(val1);
  40.         Operand<std::string> operand2(val2);
  41.         switch (sign)
  42.         {
  43.         case '+':
  44.             return (operand1 + operand2).getValue();
  45.             break;
  46.         }
  47.     }
  48.     else if(isAlpha(val1) && isDigit(val2))
  49.     {
  50.         Operand<std::string> operand1(val1);
  51.         Operand<int> operand2(std::atoi(val2.c_str()));
  52.         switch (sign)
  53.         {
  54.         case '*':
  55.             return (operand1 * operand2).getValue();
  56.             break;
  57.         case '+':
  58.             return (operand1 + operand2).getValue();
  59.             break;
  60.         }
  61.     }
  62.     return "#Calculation Error";
  63. }
Advertisement
Add Comment
Please, Sign In to add comment