(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: a. Initialize pfx to an empty expression and also initialize the stack. b. 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 the symbols from the stack until the most recent left parenthesis. Pop and discard the left parenthesis. b. 4. If sym is an operator: b. 4.1. Pop and append all the operators from the stack to pfx that are above the most recent left parenthesis and have precedence greater than or equal to sym. b. 4.2. Push sym onto the stack. c. 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: • getlnfix -Stores the infix expression • showlnfix -Outputs the infix expression • showPostfix -Outputs the postfix expression Some other operations that you might need are the following: • 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 five expressions: A B - C; (A + B) * C; (A + B) * (C - D);A + ((B + C) * (E - F) - G) / (H - I);A + B* (C + D) E/ F*G + H

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Language C++

(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:
a. Initialize pfx to an empty expression and also initialize the stack.
b. 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 the symbols from the stack until the most recent left parenthesis. Pop and discard the left parenthesis.
b. 4. If sym is an operator:
b. 4.1. Pop and append all the operators from the stack to pfx that are above the most recent left parenthesis and have precedence greater than or
equal to sym.
b. 4.2. Push sym onto the stack.
c. 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
• showlnfix -Outputs the infix expression
• showPostfix -Outputs the postfix expression
Some other operations that you might need are the following:
• 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 five expressions:
A + B - C; (A + B ) * C; (A + B) * (C - D);A + ((B + C) * (E - 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: A B + C -
Transcribed Image Text:(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: a. Initialize pfx to an empty expression and also initialize the stack. b. 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 the symbols from the stack until the most recent left parenthesis. Pop and discard the left parenthesis. b. 4. If sym is an operator: b. 4.1. Pop and append all the operators from the stack to pfx that are above the most recent left parenthesis and have precedence greater than or equal to sym. b. 4.2. Push sym onto the stack. c. 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 • showlnfix -Outputs the infix expression • showPostfix -Outputs the postfix expression Some other operations that you might need are the following: • 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 five expressions: A + B - C; (A + B ) * C; (A + B) * (C - D);A + ((B + C) * (E - 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: A B + C -
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 9 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education