Assignment #1 Extra Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

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).

Add the “+/-” button in the storyboard by copying an operation button.

If the user is in the middle of entering a number, we just change the display and the history in operationPressed inside CalculatorViewController.m:
Continue reading “Assignment #1 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #1 Extra Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

When the user hits an operation button, put an = on the end of the text label that is showing what was sent to the brain (required task #4). 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.

Basically we add an equal sign in operationPressed:

    self.history.text = [self.history.text stringByAppendingFormat:@" %@ =", sender.currentTitle];

Continue reading “Assignment #1 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #1 Extra Task #1

Please note, this blog entry is from a previous course. You might want to check out the current one.

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 very user-friendly.

Add a backspace button to the story board and connect it to an action function “backSpace”, which basically does nothing if the user is not in the middle of entering a number, otherwise removes the last digits from display and history or writes a zero to display if there is only one digit left:
Continue reading “Assignment #1 Extra Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #1 Task #6

Please note, this blog entry is from a previous course. You might want to check out the current one.

If the user performs an operation for which he or she has not entered enough operands, use zero as the missing operand(s) (the code from the walkthrough does this already, so there is nothing to do for this task, it is just a clarification of what is required). Protect against invalid operands though (e.g. divide by zero).

As performOperation returns only numbers for the moment we just return 0 for a division through zero or square roots of negative numbers e.g.:

if (!divisor) return 0;
   ....
if (number < 0) return 0;
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #1 Task #5

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add a “C” button that clears everything (for example, the display in your View, the operand stack in your Model, any state you maintain in your Controller, etc.). Make sure 3 7 C 5 results in 5 showing in the display. You will have to add API to your Model to support this feature.

Create a new label above the number display in the storyboard, change the alignment to “right”, remove its text and create a new outlet called “history”. Add a new button called “C” left to the number display and create an action “clearPressed”. Don’t forget to reduce the size of the number display accordingly.
Continue reading “Assignment #1 Task #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Assignment #1 Task #4

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add a new text label (UILabel) to your user-interface which shows everything that has been sent to the brain (separated by spaces). For example, if the user has entered 6.3 Enter 5 + 2 *, this new text label would show6.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 Controller (no changes to your Model are required for this one). You do not have to display an unlimited number of operations and operands, just a reasonable amount.

Create a new label above the number display in the storyboard, change the alignment to “right”, remove its text and create a new outlet called “history”.
Continue reading “Assignment #1 Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail