Question: This assignment is on conversion from Infix to Postfix, and evaluate Postfix. You will write two functions: Infix to Postfix: this function converts infix expression
This assignment is on conversion from Infix to Postfix, and evaluate Postfix. You will write two functions: Infix to Postfix: this function converts infix expression to postfix using stack and queue
Postfix Evaluation: this function evaluates postfix expression using a stack and the postfix expression from Queue that results from Infix to Postfix function.
You will also need PUSH, POP, and other procedures for manipulating stacks, and Enqueue, Dequeue and other procedures for queues. You must implement stack and queue, as defined in the textbook or a style of similar. You cannot just make a function call to the standard stack or queue libraries. The stack and queue functions must be in your own code.
The infix expressions to be evaluated are follows. Your main program reads in an infix expression, calls INFIX_TO_POSTFIX to convert it to postfix form, and then calls EVALUATE_POSTFIX to evaluate it.
For each infix expression, your program should
-
print the original infix expression
-
its postfix expression
-
the result of the evaluation (that is, the value of the expression).
Your program should check for end-of-file and stop when there are no more infix expressions.
The only operators used in the infix expressions are multiplication (*), division (/), addition (+), subtraction (-). Standard C++ precedence rules are observed. Parentheses are also used. As is customary, anything within parenthesis is evaluated before anything else is evaluated. You may assume there will be no unary minus. All operands are one-digit decimal numbers with no decimal point. The result of each calculation should be a float.
The input data file name should be "a3.txt"
Sample Test Data:
0/1+4*5 7+(46)*(8+6)/3 9*2+((43)*2)/2 1+2*3/4-5
Note: your program should not provide other functionalities that are not required.
a3.txt :
0 / ( 1 + 4 ) * 5 7 + ( 4 6 ) * ( 8 + 6 ) / 3 9 * 2 + ( ( 4 3 ) * 2 ) / 2 1 + 2 * 3 / 4 - 5 8 * 4 - ( ( ( 5 - 8 ) / 2 ) + 4 / 2 - 9 * 3 ) / 4 ( ( 9 - 3 - 5 - 7 + 0 ) )
c++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
