cover picture cover picture


Final Exam

CMP 464: iOS Programming
Lehman College, City University of New York
Fall 2015


This Final Is Due By 11:59 PM on Sunday December 20, 2015

Objective

In this exam, you will create a calculator application.

The primary work to be done in this exam is to create a tab-based user-interface with two tabs: Calculator and Scientific Calculator.

  1. The first tab will allow the perform basic calculations like addition, subtraction, multiplication, division, and square root.

  2. The second tab will allow the user to perform all the same operations as the first tab, but will add the trigonometric functions sin(x), cos(x) and tan(x).

Required Tasks (100 points)

  1. The calculator will have buttons arranged in a standard layout with buttons for all the digits 0-9, buttons for +, -, ×, ÷, √, =, and C (for clear). The calculator will also have a field used to display the numbers being computed.

  2. The calculator should allow the user to make simple calculations using infix notation. Please note, that this is different than the Swift calculator that we did in class, which uses postfix notation. However, the unary operations like √, sin, cos, and tan are still postfix operations. Examples:

    • 7 × 9 =
    • 37 ÷ 3 =
    • 522 - 275 =
    • 39 + 15 =
    • 10356 - 3463 =
    • 4 √

  3. Pressing the C button will reset the calculator to initial state.

  4. In scientific mode, in addition to all the basic operations, the calculator will display three additional buttons for the trigonometric functions: sin(x), cos(x), tan(x). The scientific calculator should allow the user to perform the same calculations that the standard calculator does in addtion to the trigonometric functions. Examples:

    • 90 sin(x)
    • 45 cos(x)
    • 20 tan(x)

  5. After completing a calculation, by pressing the = sign, or by pressing any of the unary operators: √, sin(x), cos(x) or tan(x). The calculation can be considered complete. Any new input from the user will replace the current result on the display and begin a new calculation.

  6. Your calculator must work in both portrait and landscape mode.

  7. You must use autolayout to maximize the size of your buttons so they occupy the entire available screen space.

  8. You will have a CalculatorBrain class which maintains its own state. Each tab will have it's instance of this class. This class will be the model application.

  9. Both tabs should have a segue to a tableview that will be used to display the history of all the computations in each tab. Each table cell will have the result of an entire computation Example:
    	       +--------------------+
    	       | 795 + 459 = 1254   |
    	       +--------------------+
    	       | 44 ÷ 11 = 4        |
    	       +--------------------+
    	       | 222 + 8 = 230      |
    	       +--------------------+
    	       | 4 × 12 = 48        |
    	       +--------------------+
          
  10. When the user clears the calculator, the history should not be cleared. However, the history should record the fact the the calculator has been cleared.

  11. Each calculator maintains its own history.

  12. Navigation to the history view needs to be done through a push segue.

Extra Credit

  1. (10 Points) From the history view, provide the user with the ability to segue into a different tableview which divides your history into sections of similar operations. Example:
    	       +--------------------+
    	       | Additions:         |
    	       +--------------------+
    	       | 795 + 459 = 1254   |
    	       +--------------------+
    	       | 222 + 8 = 230      |
    	       +--------------------+
    	       | Divisions:         |
    	       +--------------------+
    	       | 44 ÷ 11 = 4        |
    	       +--------------------+
    	       | Multiplications:   |
    	       +--------------------+
    	       | 4 × 12 = 48        |
    	       +--------------------+
          

  2. (20 Points) Enhance your calculator's functionality by adding keys for ( and ) and allowing the user to string together multiple operations like a regular calculator. Your calculator would need understand the order of operations when parentheses are not present. Examples:

    • 7 × (9 + 54) ÷ 2 =
    • 42 × 90 cos(x) =
    • (522 - 275) ÷ 45 sin(x) =
    • (522 - 275) ÷ 45 sin(x) =
    • 459 + 422 ÷ 10 = should compute to the same value as 459 + (422 ÷ 10) =

Please submit the completed final exam on Blackboard as a zip file of your entire project. No other forms of submission will be accepted.