Question: Data Abstraction and Problem Solving with C++ Ch 6 Programming Problem 8 C++ Pseudocode only please! Do not need a functioning program, just help understanding

Data Abstraction and Problem Solving with C++ Ch 6 Programming Problem 8

C++ Pseudocode only please! Do not need a functioning program, just help understanding the concepts in each step.

Consider simple infix expressions that consis of single digit operands; the operators +,-,*, and /; and parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class of infix calculators. Use the algorithms given in this chapter to evaluate infix expressions as entered into the calculator. You must first convert the infix expression to postfix form and then evalute the resulting postfix expression.

Do the above BUT use the following algorithm to evaluate an infix expression infixExp. The algorithm uses two stacks: One stack opStack contains operators, and the other stack valStack contains values of operands and intermediate results. Note that the algorithm treats parentheses as operators with the lowest precedence.

for(each character ch in infixExp)

{

switch(ch)

{

case ch is an operand, that is, a digit

valStack.push(ch)

break

caes ch is a '('

opStack.push(ch)

break

case ch is an operator

if (opStack.isEmpty())

opStack.push(ch)

else if (precedence(ch) > precedence(opStack.peek()))

opStack.push

else

{

while (!opStack.isEmpty() and

precedence(ch) <= precedence(opStack.peek()))

performOperation()

opStack.push(ch)

}

break

case ch () is a ')'

while (opStack.peek is not a '(' )

performOperation()

opStack.pop()

break

}

}

while (!opStack.isEmpty())

Execute

result = valStack.peek()

Note that performOperation() means:

operand2 = valStack.peek()

valStack.pop()

operand1 = valStack.peek()

valStack.pop()

op = opStack.peek()

opStack.pop()

result = operand1 op operand2

valStack.push(result)

THIS PROGRAM MUST BE MODIFIED AS FOLLOWS:

Your solution must be able to handle input expressions that contain spaces and valid multi-digit integers. So, something like this (( 15 + 2 * 3 - 4 ) / 17 + ( 22 / 11 * 3)) * 101 must work properly. Your solution should display the postfix expression resulting from the translation from infix before evaluating the expression to produce the numerical result. Your program must repeatedly accept input, translate, and evaluate, until the input contains a single period. (i.e., just a '.')

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 Databases Questions!