cover picture cover picture


Final Exam

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


This Final Is Due By 11:59 PM on Monday December 19, 2015

Objective

In this exam, you will create a calculator application in Objective C.

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, we will call it Calculator , will allow the user to perform basic calculations like addition, subtraction, multiplication, division, and square root.

  2. The second tab, we will call it Scientific Calculator , will allow the user to perform all the same operations as the first tab, but will add the logarithm functions ln and log as well as the the trigonometric functions sin, cos and tan.

Required Tasks (100 points)

  1. The calculator will have buttons arranged in a standard layout with buttons for:

    • The digits 0-9
    • π
    • e
    • +
    • -
    • ×
    • ÷
    • 1/x
    • =
    • c (for clear)
    calculator

    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. However, the unary operations like √ and 1/x are still postfix operations. Examples:

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

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

  4. The scientific calculator, in addition to all the basic operations of calculator, will add 5 additional buttons:

    • log [Which is log10. In Objective C it is log10()]
    • ln [Which is the natural log, or loge. In Objective C it is log()]
    • sin
    • cos
    • tan
    scientific calculator

  5. The scientific calculator should allow the user to make simple postfix operations. Examples:
    • π sin
    • 2.45 cos
    • 1.234 tan
    • e ln
    • 100 log

  6. After completing a calculation, by pressing the = sign, or by pressing any of the unary operators: √, 1/x, ln, log, sin, cos, or tan. 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.

  7. Both calculators must work in both portrait and landscape mode.

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

  9. 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 of the application. All calculations and the state of the calculator should be maintained in CalculatorBrain and not in your ViewController.

  10. 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        |
    	       +--------------------+
          
  11. 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.

  12. Each calculator maintains its own history.

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

Extra Credit

  1. (5 Points) Allow the user to enter a chain of calculations without having to press the = sign until the end. Order of operations need not be a concern. Examples:

    • 17 ÷ 3 + 69 - 23 = 51.66666666666667
    • 3 × 5 ÷ 2 × 15 ÷ 3 = 37.5
    • 10 ÷ 4 × 6 ÷ 8 + 99 × 15 = 1513.125

  2. (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        |
    	       +--------------------+
          

  3. (10 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 to 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.