Stack Project Solution

$30.00 $24.90

Description

infix to postfix conversion and postfix evaluation WITH stacks

Give students practice using stacks, converting infix to postfix, and evaluating postfix equations. Also reinforces the following concepts:

file i/o

implementing pseudo-code standard template stacks

Using the skeleton solution provided, write code which will

read each infix equation from the data file (one line at a time) display the infix equation

convert the equation to an equivalent postfix (using InfixToPostfix() which you have to write) display the equivalent postfix equation

evaluate the postfix equation (using EvaluatePostfix() which you have to write) display the result of the last step

sample output:
Infix to Postfix Pseudo Code

Figure 7.12 page 385 re-written

1. initialize stack to hold operation symbols and parenthesis

2. do

if (the next input is a left parenthesis)

Read the left parenthesis and push it onto the stack else if (the next input is a number or operand)

Read the operand (or number) and write it to the output else if (the next input is one of the operation symbols) {

while ( stack is not empty AND

stack’s top is not left parenthesis AND

stack’s top is an operation with equal or higher precedence than the next input symbol)

{

print the stack’s top

pop the stack’s top

}

push the next operation symbol onto the stack

}

else

{

read and discard the next input symbol (should be a right parenthesis)

print the top operation and pop it

while ( stack’s top is not a left parenthesis )

print next symbol on stack and pop stack

pop and discard the last left parenthesis

}

while (there is more of the expression to read)

3. print and pop any remaining operations on the stack (there should be no remaining left parenthesis)

Grade Sheet

Stack (150 pts.)

Documentation (10 pts)

Student name, Section and Disclaimer

______/5

Proper function headers

______/5

Correct Output (140 pts)

______/140

10 Points per correct equation