Please note, this blog entry is from a previous course. You might want to check out the current one.
Add two new buttons to your Calculator’s keypad: →M and M. These 2 buttons will set and get (respectively) a variable in the CalculatorBrain called M.
- →M sets the value of the variable M in the brain to the current value of the display (if any)
- →M should not perform an automatic ↲ (though it should reset “user is in the middle of typing a number”)
- Touching M should push an M variable (not the value of M) onto the CalculatorBrain
- Touching either button should show the evaluation of the brain (i.e. the result of evaluate()) in the display
- →M and M are Controller mechanics, not Model mechanics (though they both use the Model mechanic of variables).
- This is not a very great “memory” button on our Calculator, but it’s good for testing whether our variable function implemented above is working properly. Examples …
7 M + √ ⇒ description is √(7+M), display is blank because M is not set
9 →M ⇒ display now shows 4 (the square root of 16), description is still √(7+M)
14 + ⇒ display now shows 18, description is now √(7+M)+14
Rename the two remaining blank buttons in storyboard and link them to actions in the view controller:
Continue reading “cs193p – Project #2 Assignment #2 Task #9”