Question: Write a program in cppthat accepts a string that is a space - delimited integer arithmetic expression in postfix notation. Use a stack to compute
Write a program in cppthat accepts a string that is a spacedelimited integer arithmetic expression in postfix notation. Use a stack to compute the value.
Example:
The input string is equivalent to the infix expression
The answer is
The algorithm is:
Take the leftmost token from the string
If it is numeric which may include a unary operator push that token onto the stack
If it is a binary operation, pop the vector twice, apply the operation, and push the result
When the input string is empty, the stack will contain one entry: the final answer
Heres how the given string gets processed:
String Stack
a
The final answer, is the only element in the stack after all tokens in the string have been consumed.
This problem has an extra twist. The string contains characters, so isnt a ten, but is the char followed by the char You will need to convert string representations of integers signed and unsigned into their integer values. Youll also need to handle unary and
We also have to worry about the three noncommuting operators We will evaluate the postfix string as and, likewise, will evaluate as and as
The program should continue to accept and process input strings until the user enters a zero as input. Theres no need to check for validity; all input will be wellformed postfix expressions.
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
