Question: USING C++ Polish notation/expression is also known as prefix notation where the numbers are preceded by its operator (placed in the front). In RPN, the

USING C++

Polish notation/expression is also known as prefix notation where the numbers are preceded by its operator (placed in the front). In RPN, the operator comes after the operands instead of the normal format in which the operator is between the operations (this is called infix notation).

Starting with an empty stack, a RPN calculator can be implemented with the following rules:

If a number is input, push it o the stack.

If + is input then pop value1, pop value2, then push value2-value1 on the stack.

If - is input, then pop the last two operands off the stack, multiply them, and push the result on the stack.

If / is input, then pop value1, pop value2, then push value2/value1on the stack.

If q is input, then stop inputting values, print out the top of the stack, and exit the program.

Modify the Stack class given in the class to store integers instead of characters. Use the modified stack to implement a RPN calculator. Output an appropriate error message if there are not two operands on the stack when given an operator.

Here is a sample input and output that is equivalent to ( (10 ( 2 + 3 ) * 2 ) ) / 5:

10

2

3

+

-

2

*

5

/

q

The top of the stack is: 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!