Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago