Homework 2 - CS4980 iOS Fall 2017
Due: Monday, Sept. 11 by 8:00am
Maximum score: 10 points

Create a Swift iOS calculator app with features described below. (Note: this is essentially the first assignment of the Winter 2015 Stanford on-line iOS course. See Stanford Winter 2015 iOS class Assignment1. It is significantly different from the calculator demo'd in the Stanford Winter 2017 iOS class lectures and the corresponding assignment. Your calculator must be an RPN calculator like that developed in our class.)

NOTE: Because many many people have taken the online Stanford course, it is not hard to find implementations of calculators like on the web. DO NOT COPY other people's implementations! Try to do this on your own. When stuck, it is reasonable to look at other implementations to learn how people approached particular tasks. But don't copy. Understand what you've looked up and then use that understanding to implement your own version.

  1. First, create your own version of the basic calculator developed in class. It is important that you start from a brand new project and reproduce the basic calculator yourself, step by step, rather than simply copying files or starting from the completed basic app; you need to get comfortable building an app from scratch.
  2. After step 1, the calculator works only with can integers. Modify the operations to use floating point numbers and make it possible for users to directly enter floating point numbers (thus, as part of this, you'll need to add a '.' button).
  3. Add the following 4 operation buttons:
  4. Add a “C” button that clears everything (for example, the calculator's display, the stack in your model, any state you maintain in your view controller, etc.). E.g., make sure 3 7 C 5 results in 5 showing in the display.
  5. Add a new label to your user-interface which shows everything that has been sent to the model (separated by spaces). For example, if the user has entered 6.3 Enter 5 + 2 *, this new text label would show 6.3 5 + 2 *. A good place to put this label is to make it a thin strip above the display text label. Don’t forget to have the C button clear this too. All of the code for this task should be in your view controller (no changes to the model are needed for this). You do not have to display an unlimited number of operations and operands, just a reasonable amount.
  6. If the user performs an operation for which he or she has not entered enough operands, use zero as the missing operand(s) (the basic calculator created in class does not do this). Also, protect somehow against invalid operands (e.g. division by zero).
OPTIONAL ADDITIONAL FEATURES (if you have interest/time):
  1. Implement a “backspace” button for the user to press if they hit the wrong digit button. This is not intended to be “undo,” so if they hit the wrong operation button, they are out of luck! It’s up to you to decided how to handle the case where they backspace away the entire number they are in the middle of entering, but having the display go completely blank is probably not a good design.
  2. When the user hits an operation button, put an = on the end of the text label that is showing what was sent to the model (item #5 above). Thus the user will be able to tell whether the number in the Calculator’s display is the result of a calculation or a number that the user has just entered.
  3. Add a +/- operation which changes the sign of the number in the display. Be careful with this one. If the user is in the middle of entering a number, you probably want to change the sign of that number and let them continue entering it, not force an enterPressed like other operations do. But if they are not in the middle of entering a number, then it would work just like any other single-operand operation (e.g. sqrt).


IMPORTANT NOTES: