Question: (c++) Language 10 (Infix to Postfix) Write a program that converts an infix expression into an equivalent postfix expression, The rules to convert an infix
10 (Infix to Postfix) Write a program that converts an infix expression into an equivalent postfix expression, The rules to convert an infix expression into an equivalent postfix expression are as follows: Suppose infx represents the infix expression and pfx represents the postfix expression. The rules to convert infx into pfx are as follows: Initialize pfx to an empty expression and also initialize the stack. Get the next symbol, sy, from infx 11. If aym is an operand, append wym to pfx. 2 If ayn is c.pushaym into the stack. 3. If aya is ), pop and append all of the symbols from the stack until the most recent left parentheses. Pop and discard the left parentheses. If sym is an operator: 41 Pop and append all of the operators from the stack to ptx that are above the most recent left parentheses and have precedence greater than or equal to ay. 12 Push ayn onto the stack After processing infx, some operators might be left in the stack Pop and append to pfx everything from the stack In this program, you will consider the following (binary) arithmetic operators: +,-. and /. You may assume that the expressions you will process are error free. Design a class that stores the infix and postfix strings. The class must include the following operations getIntix: Stores the infix expression showInfix: Outputs the infix expression. showPostfix: Outputs the postfix expression: Programming Exeroses 1277 Some other operations that you might need are as follows: convert to Postfix Converts the infix expression into a postfix expression. The resulting postfix expression is stored in pfx precedence: Determines the precedence between two operators. If the first operator is of higher or equal precedence than the second operator, it returns the value true; otherwise, it returns the value tale. Include the constructors and destructors for automatic initialization and dynamic memory deallocation. Test your program on the following expressions A.B.C: 1 7 (A + B). (C-D): dA((B+C) (E-F) - G) / H - 1); AB. ( CD) - RP.G. For each expression, your answer must be in the following form: Infix Expression ABC Postfix Expression: ABC
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
