Problem

You should complete the Programming Project 10 before attempting this one. Write a program...

You should complete the Programming Project 10 before attempting this one. Write a program that converts a fully parenthesized mathematical infix expression into an equivalent postfix expression and then evaluates die postfix expression. A fully parenthesized expression is one in which parentheses surround every operator and its operands. Starting with an empty stack of strings to store operators and an empty queue of strings to store the postfix expression, the conversion can be implemented with the following rules:

■If “ (“ is input, then ignore it.

■If a number is input, then add it to the queue.

■If an operator (either “*”, “+”, “-”, or “/”) is input, then push it on the stack.

■If “) “ is input, then pop the operator from the stack and add it to the queue.

■If “q” is input, then exit.

When the final operator is popped from the stack, the queue contains die equivalent postfix expression. Use your solution from Programming Project 10 to evaluate it. You will need to convert a string object to an integer. Use die c_str() function to convert the string to a C string, and then use the atoi function to convert the C suing into an integer. Refer to Chapter 8 for details.

Sample output is shown below for ((10 - (2 + 3)) * 2),which

translates to the postfix expression 10 2 3 + − 2 *:

(

(

10

-

(

2

+

3

)

)

*

2

)

q

The expression evaluates to 10

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 13
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT