You will implement a calculator using stacks and queues in C++. You may use the STL. Your calculator must support the following operators:

  • Addition: +
  • Subtraction:
  • Multiplication: *
  • Division: /
  • Modulo: %
  • Exponent: ^
  • Parentheses: ( and )

The input will be given in the form of infix expressions. For example, ( 20.4 + 3 ) * -5, where each operator or operand is separated by a space. Implement parentheses checking to ensure that the input is a valid expression. If the expression is not valid, output an error message. Convert the checked infix expression into a postfix expression. For example, the above infix expression would covert to 20.4 3 + -5 *. Use a stack for the infix to postfix conversion. Store the resulting postfix expression in a queue and print it onto the screen. Then, using a second stack, evaluate the postfix expression and print the result.

Here is sample output (input in bold green):

Enter a valid infix expression: 3 + 4 * 5 / 6
The resulting postfix expression is: 3 4 5 * 6 / +
The result is: 6.33333

Your program should accept integers and floating-point numbers, including negative numbers, as operands. Additionally, your program should accept only those operators indicated above. You may assume valid infix expression input, though parentheses may be invalid (and need to be checked/matched). All operators, with the exception of exponent (^), have left-to-right associativity.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.