Sale!

CS 2401 Homework Assignment 5 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (6 votes)

For this lab you are to use the STL stack which you can obtain by putting #include at the top of your program, and having the std namespace open, of course.
Write a program that evaluates an arithmetic expression in postfix (RPN) notation. The basic algorithm is to use a single stack of integers. If, when parsing the input you encounter a number you push the number onto the stack. If you encounter an operator (+, -, *, / are the only ones we are working with) you apply the operator to the top two elements on the stack. The result is then pushed back onto the stack. At the end of the whole operation there should be a single number on the stack which is a single number, the value of the expression.
In the files calc_useful.h and calc_useful.cc, I have given you a couple of simple functions, one which identifies if the char it receives is or is not an operator, and the other which evaluates two operands when given a character that is an operator. I have also written a main to help you with parsing the input. All three of these files appear in ~jdolan/cs2401/hw/hw5 or on Blackboard.
The calculator should be embedded in a loop in the main that runs until the user chooses to quit. (Everything that you write for this assignment can be done in the main, just #include “calc_useful.h” and compile both .cc files.)
Use your calculator to evaluate:
12 679 5 + 4 * 8 / + (Answer = 354)
34 6 + 16 * 18 – (Answer = 622)
12 6 – 8 + 7 * + (Should produce an error)
56 78 84 + 33 * (Should produce an error)
Plus: Two problems that you make up on your own. These should each have a minimum of four operands.
Run a script of the above interaction including the two problems that you made up on your own. Submit on Blackboard the script and the source code for your program. You should complete this assignment before taking Quiz 4 which is due the same evening.
CS 2401