C++ I have to do this program but using the STL class stack to convert the infix expressions to postfix expressions.

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%

C++

I have to do this program but using the STL class stack to convert the infix expressions to postfix expressions.

(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 - 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 - 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
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Functions
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.
Similar questions
  • SEE MORE QUESTIONS
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