Postfix notation, is a mathematical notation in which operators follow their operands; for instance, to add 3 and 4, one would write 3 4 + rather than 3 + 4 (infix notation). If there are multiple operations, operators are given immediately after their second operands; so, the
expression written 3 − 4 + 5 in conventional notation would be written 3 4 − 5 + in postfix notation: 4 is first subtracted from 3, then 5 is added to it. An advantage of postfix notation is that it removes the need for parentheses that are required by infix notation. While 3 − 4 × 5 can also be written 3 − (4 × 5), which is different from (3 − 4) × 5. In postfix notation, the former could be written 3 4 5 × −, while the latter could be written 3 4 − 5 × or 5 3 4 − ×. (from Wikipedia)
Stacks can be used to evaluate expressions in postfix notations by following these steps:
If a number is typed, push it on the
If an operation is typed, depending on the operation, pop off two numbers from the stack, perform the operation, and push the result back on the
You should complete the Stack class and other functions in the template file (found on Carmen) so that when the user enters an expression in postfix notation, the program calculates and shows the result. In this assignment the user enters one-digit positive numbers only, but the result can be any integer. Only basic operations (i.e. +, -, /, *) are entered by the user and integer division is used in calculations. User input ends with a semicolon.
Class Stack uses a linked list to implement a stack, and it has five public member functions:
Default constructor: initializes the stack to an empty stack
isEmpty: returns true if the stack is empty and false otherwise
push: pushes a new number to the top of stack
pop: removes the top of stack
top: returns the value at the top of stack, does not remove it from stack
You must use the template file and only add you code were you see /*your code here*/. Do not modify other parts of the code. Do not use C/C++ libraries other than iostream and cstdlib.
Input/Output example
Your output must match the solution file on Carmen exactly. Following are some example test cases and their expected outputs. User input is underlined.
Program Submission
Your submission files must have the following at the top:
/*
File name: (your file name) Created by: (your name) Created on: (date)
Synopsis: (what your program does)
*/
Compile your code in CSE stdlinux system with this command:
g++ homework4.cpp -std=c++11 –pedantic-errors
Program does not compile in CSE stdlinux system using the above command will receive a zero.
Make sure your code is formatted properly. Your program should have appropriate indention and necessary comments. See textbook on section 2.5 or any code example in textbook/lecture slides.
Submit your code to the designated dropbox on Carmen. You can find the dropbox under the Assignments tab.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of