Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please give me the answer as a text Thank you I know it's long put please try 10. a. b. (Infix to Postfix) Write a

image text in transcribed

Please give me the answer as a text Thank you I know it's long put please try

10. a. b. (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, sym, from infx. b.1. If sym is an operand, append sym to pfx. b.2. If sym is (push sym into the stack. b.3. If sym is), pop and append all of the symbols from the stack until the most recent left parentheses. Pop and discard the left parentheses. b.4. If sym is an operator: b.4.1. Pop and append all of the operators from the stack to pfx that are above the most recent left parentheses and have precedence greater than or equal to sym. 6.4.2 Push sym 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: getInfix: Stores the infix expression. showInfix: Outputs the infix expression showPostfix: Outputs the postfix expression. . Programming Exercises 1277 . . Some other operations that you might need are as follows: convertToPostfix: 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 false. Include the constructors and destructors for automatic initialization and dynamic memory deallocation. Test your program on the following expressions: A + B - C; (A + B) + C; (A + B) * (C - D); ((B + C) + (B - F) - G) / (H - I); A + B + (C + D) -E/F+G + H; For each expression, your answer must be in the following form: Infix Expression: A + B - C; Postfix Expression: ABC a b. c d. A + e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions