Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Infix to Postfix Converter Project Construct a class that converts an infix expression into an equivalent postfix express and a program to test the...

Infix to Postfix Converter Project

Construct a class that converts an infix expression into an equivalent postfix express and a program to test the class. Your class must utilize a stack structure as describe in the algorithm below.

Suppose infx represents the infix expression and pfx represents the postfix expression. The rules to convert infx into pfx are as follows:

  1. Initialize pfx to an empty expression and also initialize the stack.
  2. Get the next symbol, sym, from infx.
  3. If sym is an operand, append sym to pfx.
  4. If sym is (, push sym into the stack.
  5. 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.
  6. If sym is an operator:
  7. 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.
  8. Push sym onto the stack.
  9. 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. Include get and set functions for infx and a get function for pfx. Include a conversion function and a function to evaluate the precedence of operators. Also include a constructor.

Here is the UML diagram for this class:

infixToPostfix

-infx: string

-pfx: string

+setInfx(string): void

+ getInfx() const: string

+ getpfx() const: string

+ convertToPostfix(): void

- precedence(): bool

+ infixToPostfix()

Write a test your program to the read these infix expressions from a data file, convert them to postfix expressions and display the results. Use one of the stack implementations that has been provided in the Chapter 17/Source Code from Textbook folder.

A data file has been provided containing these expressions.

  1. A + B - C;
  2. (A + B ) * C;
  3. (A + B) * (C - D);
  4. A + ((B + C) * (E - F) - G) / (H - I);
  5. A + B * (C + D ) - E / F * G + H;

Your output should look like this:

Infix Expression: A+B-C;

Postfix Expression: AB+C-

Infix Expression: (A+B)*C;

Postfix Expression: AB+C*

Infix Expression: (A+B)*(C-D);

Postfix Expression: AB+CD-*

Infix Expression: A+((B+C)*(E-F)-G)/(H-I);

Postfix Expression: ABC+EF-*G-HI-/+

Infix Expression: A+B*(C+D)-E/F*G+H;

Postfix Expression: ABCD+*+EF/G*-H+

Turn in all your source code files, your test program, and one or more screen shots showing the results of your testing.

Once completed you will show that you can:

  • Explain how parentheses are eliminated in converting an infix expression to a postfix expression.
  • Explain how the order of operations is maintained for operators in the absence of parentheses.
  • Construct a class that utilizes a stack to convert infix expressions to postfix expressions.

infixData.txt

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;

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question