Question: Write a program that uses C++ STL stacks to evaluate a postfix expression. The postfix expression can use the binary operators: *, /,+,-, and %.
Write a program that uses C++ STL stacks to evaluate a postfix expression. The postfix expression can use the binary operators: *, /,+,-, and %. The program should read the expression in postfix notation. Your program should work only on single digits operands (0 through 9). Do not add code to handle more than one digit operands.
Your program should use a while loop or for-loop to allow the user to enter and evaluate as many expressions as the user needs. The program should issue an error message if the expression is invalid (for example: if the stack is empty or does not have enough operands for a given operator or if the stack is not empty after the entire expression has been evaluated) It should also check for division by zero (% and /).
At the end, the program should display the number of invalid expressions, the number of valid expressions, and the total number of expressions the program processed.
Use the following expressions to test your program after converting them to postfix notation. You should not hard-code these expressions in your program.
(2+3) * (5-1) =20 the postfix notation is 2 3 + 5 1 - *
2+(3*5) 1 = 16 the postfix notation is 2 3 5 * + 1 -
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
