Question: The following code is an implementation of the stack operation. Complete the program to convert postfix to infix using the given C++ sample code. Input

The following code is an implementation of the stack operation.Complete the program to convert postfix to infix using the given C++ sample code.

Input A B C * + D E / F * - Output (A+(B*C))+((D/E)*F))

Algorithm of Postfix to infix

1. Push post fix notation to the PostfixStack reverse order ( eg. push - * F / E D + * C B A)

2. while there are no data at PostfixStack

3. read one symbol from the PostfixStack

4. if the symbol is an operand

5. push it into the InfixStack

6. else

7. pop the top 2 values from the InfixStack

8. put the operator between two operand

9. Encapsulate the resulted string with parenthesis

10. if there is only one value in the stack That value in the stack is the desired Infix notation

#include

#include \"Lab6.h\" // from the Lab#06 Assignment

using namespace std;

void testCopyConstructor(stackType otherStack);

int main()

{

stackType stack(50);

stackType copyStack(50);

stackType dummyStack(100);

//Q1. Create two stacks PostfixStack type of char, InfixStack type of string

//Q2. Push post fix notation to the stack //A B C * + D E / F * -

stack.push(23);

stack.push(45);

//Q3. Function call isOperator

//Q4 Test function call using while loop

while ( )

{

//read all contents from the PostfixStack

//call function isOperator with actual parameter

//convert a char to string using string stream

// hint= Convert char to string

// stringstream ss;

// ss > str;

Q5. If a content is an opcode

if ( )

{

// push to the InfixStack

}

else

{

Q6. Take two operand from the InfixStack and save each value to the Variable opr1 and opr2. And concatenate opr1, operator, opr2 And enclosed with ( ) and then save to the InfixStack.

}//end if

} // end while

Q7. Check contents of the InfixStack

copyStack = stack; //copy stack into copyStack

cout

while (!copyStack.isEmptyStack()) //print copyStack

{

cout

copyStack.pop();

}

cout

testCopyConstructor(stack); //test the copy constructor

if (!stack.isEmptyStack())

cout

dummyStack = stack; //copy stack into dummyStack

cout

while (!dummyStack.isEmptyStack()) //print dummyStack

{

cout

dummyStack.pop();

}

cout

return 0;

}

void testCopyConstructor(stackType otherStack)

{

if (!otherStack.isEmptyStack())

cout

}

//Header file: myStack.h

//Lab8A.h

Q1. Use #ifndef directive for Lab9A.h

Q2.Create a function that identifies the operator

// Name of the function isOperator

// Formal parameter char

// return type bool

// 0~9, a ~z, A ~ Z return true;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!