Question: In c++ Reverse Polish Notation (RPN), or postfix notation is a format to specify mathematical expressions. In RPN, the operator comes after the operands instead

In c++

Reverse Polish Notation (RPN), or postfix notation is a format to specify mathematical expressions. In RPN, the operator comes after the operands instead of the normal format, which is between the operands (infix notation).

Implement a program using an STL Stack Container for integers with the following rules:

1. If a number is input, push it on the stack

2. If + is input, then pop the last two operands off the stack, add them together and push the result

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

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

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

6. If q or Q is input, output the top of the stack and end the program

7. Output an appropriate error message if there are not two operands on the stack when an operator is input, and request a valid input.

Sample input and output which is equivalent to the equation: ((10 (2 + 3)) * 2) / 5

10

2

3

+

-

2

*

5

/

Q

The value on the top of the stack is: 2

In c++ Reverse Polish Notation (RPN), or postfix notation is a format

Sample output: Enter a number or a to quit: 10 Enter a number or operator, a to quit: 2 Enter a number or operator, a to quit: 3 Enter a number or operator, a to quit:+ Enter a number or operator, a to quit: Enter a number or operator, Q to quit: 2 nter a number or operator, Q to quit: Enter a number or operator, a to quit: 5 Enter a number or operator, a to quit: Enter a number or operator, to quit: The value on the stack is: 2 Process returned 0 (0x0 excution time 19 Press any key to continue

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!