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.

Add a new API to CalculatorBrain.h:

- (void)clearStack;

and its implementation to CalculatorBrain.m:

- (void) clearStack
{
    [self.operandStack removeAllObjects];
}

Finally enter the code for clearPressed in CalculatorViewController.m:

- (IBAction)clearPressed {
    self.display.text = @"0";
    self.history.text = @"";
    self.userIsInTheMiddleOfEnteringANumber = NO;
    self.userIsInTheMiddleOfEnteringAFloat = NO;
    [self.brain clearStack];
}
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *