CS111 Project 3: Postfix

Due Wednesday, October 26, at 9:00 AM

Postfix, or Reverse Polish Notation (RPN) is a notation where the operator comes after the operands, not before as it does using infix notation. This is best explained by example: Postfix notation does not require parenthesis, but rather uses a stack-based calculation system. Consider the following expressions: In the postfix expression, evaluation happens like this, with the top of the stack drawn at the right:
  1. 3 is pushed on the stack. Stack: 3
  2. 4 is pushed on the stack. Stack: 3 4
  3. 5 is pushed on the stack. Stack: 3 4 5
  4. + is evaluated. The top two operands are popped off the stack, added, and the result is placed back on the stack. Stack: 3 9
  5. * is evaluated. The top two operands are popped off the stack, multipled, and the result is placed back on the stack. Stack: 27
For this assignment, you will create a postfix calculator. It must support the basic operators +, -, *, and /, plus pop, which removes the top item from the stack. You can use a list for the stack. There are three types of operation: Regarding user input, the user should be presented with a prompt, at which they may enter as many operations as they like, separated by spaces. So the following are all valid input: Some method of exiting the program should be provided. How this works is up to you.

When you are finished, upload the program in the usual manner.