Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 4 Postfix Calculator The stack based calculator is constructed using the postfix notation. In this assignment, we are to implement the postfix calculator using

Assignment 4 Postfix Calculator

The stack based calculator is constructed using the postfix notation. In this assignment, we are to implement the postfix calculator using the Stack and Queue from the Combo class that we build previously.

We are to create one queue to hold all input tokens and one stack for hold the operands. The calculation shall follow the depicted description above.

This program shall not check the validity of the postfix expression. It is assumed that the test pattern is valid. Use this online infix to postfix converter http://www.mathblog.dk/tools/infix-postfix-converter/ to generate a valid postfix expression from infix expression for your choice.

Your program shall implement and show:

the user input

the calculation of following 4 operators: + - * /

tracing of all the content of the Operand Stack and Postfix Queue between changes.

Sample Test Output

For this exercise we are to use a line prompt for user to enter a postfix expression.

image text in transcribed 
Running /home/ubuntu/workspace/comsc210/m04/comboCalculator.cpp Enter a postfix expression, q to quit: 12345+-+* Operand Stack Postfix Queue 2, 1 3, 2, 1 4, 3, 2, 1 5, 4, 3, 2, 1 3, 2, 1 9, 3, 2, 1 = 4+5 2, 1 -6, 2, 1 = 3-9 -4 1*-4 = Enter a postfix expression, q to quit: Running /home/ubuntu/workspace/comsc210/m04/comboCalculator.cpp Enter a postfix expression, q to quit: 12345+-+* Operand Stack Postfix Queue 2, 1 3, 2, 1 4, 3, 2, 1 5, 4, 3, 2, 1 3, 2, 1 9, 3, 2, 1 = 4+5 2, 1 -6, 2, 1 = 3-9 -4 1*-4 = Enter a postfix expression, q to quit

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

More Books

Students also viewed these Databases questions