Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ write a Design and implement a class of infix calculators ,simply write a function named evaluateInfix() that evaluates infix expressions. It should have

Use C++ write a "Design and implement a class of infix calculators" ,simply write a function named "evaluateInfix()" that evaluates infix expressions. It should have one string parameter and should return an int result. It should call a separate function named "infixToPostfix()" to convert the infix expression into a postfix expression, and then it should do the work of evaluating the resulting postfix expression. Then write a main() function to thoroughly test the function.

Use the pseudocode algorithm that evaluates postfix expressions given at the end of section 6.3.1 and the pseudocode algorithm that converts an infix expression to postfix form given near the end of section 6.3.2. Use the STL stack class. Include the output. Also don't forget the separate function "infixToPostfix()"

Here is the pseudocode for 6.3.1

for ( each character ch in the string) {

if (ch is an operand)

Push the value of the operand ch onto the stack

else // ch is an operator named

{

// Evaluate and push the result

operand2 = top of stack

Pop the stack

operand1 = top of stack

Pop the stack

result = operand1 op operand2

Push result onto the stack

}

}

Here is the pseudocode for 6.3.2

for ( each character ch in the infix expression) {

switch (ch) {

case operand: // Append operand to end of postfix expressionstep 1

postfixExp = postfixExp ch

break

case '(': // Save '(' on stackstep 2

aStack.push(ch)

break

case operator: // Process stack operators of greater precedencestep 3

while (!aStack.isEmpty() and aStack.peek() is not a '(' and precedence(ch) <= precedence(aStack.peek())) {

Append aStack.peek() to the end of postfixExp

aStack.pop()

}

aStack.push(ch) // Save the operator

break

case ')': // Pop stack until matching '(' step 4

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

{ Append aStack.peek() to the end of postfixExp

aStack.pop()

}

aStack.pop() // Remove the open parenthesis

break }

}

// Append to postfixExp the operators remaining in the stackstep 5

while (!aStack.isEmpty())

{ Append aStack.peek() to the end of postfixExp

aStack.pop()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

=+Are you interested in working on global teams?

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago