Skip to content

oliverbarreto/CS193P-A2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

{\rtf1\ansi\ansicpg1252\cocoartf1138
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural

\f0\fs24 \cf0 Required Tasks\
\
1. Update your Calculator\'92s code to use properties wherever possible, including (but not necessarily limited to) UILabel\'92s text property and UIButton\'92s textLabel property as well as using a private property for your brain in your Controller.\
\
2. Fix the memory management problems we had in last week\'92s version of the Calculator, including the Model not getting released in the Controller\'92s dealloc and the leaks associated with waitingOperation.\
\
3. Implement this API for your CalculatorBrain so that it functions as described in the following sections. You may need additional instance variables.\
    @interface CalculatorBrain : NSObject\
    \{\
        double operand;\
        NSString *waitingOperation;\
        double waitingOperand;\
\}\
    - (void)setOperand:(double)aDouble;\
    - (void)setVariableAsOperand:(NSString *)variableName;\
    - (double)performOperation:(NSString *)operation;\
    @property (readonly) id expression;\
    + (double)evaluateExpression:(id)anExpression\
             usingVariableValues:(NSDictionary *)variables;\
    + (NSSet *)variablesInExpression:(id)anExpression;\
    + (NSString *)descriptionOfExpression:(id)anExpression;\
    + (id)propertyListForExpression:(id)anExpression;\
    + (id)expressionForPropertyList:(id)propertyList;\
    @end\
\
4. Modify your CalculatorViewController to add a target/action method which calls setVariableAsOperand: above with the title of the button as the argument. Add at least 3 different variable buttons (e.g. \'93x\'94, \'93a\'94 and \'93b\'94) in Interface Builder and hook them up to this method.\
\
5. Add a target/action method to CalculatorViewController which tests your CalculatorBrain class by calling evaluateExpression:usingVariableValues: with your Model CalculatorBrain\'92s current expression and an NSDictionary with a test set of variable values (e.g. the first variable set to 2, the second to 4, etc.). Create a button in your interface and wire it up to this method. The result should appear in the display.\
\
\
\
Extra Credit Tasks\
\
1. Create@propertystatements(withcorresponding@synthesizestatements)forallof your IBOutlet instance variables in your Controller, then set them all to nil in your viewDidUnload. This will be required on all future assignments, so this is a good opportunity to practice it.\
\
2. Instead of lazily instantiating your Model in your Controller, create it in a method in your Controller named viewDidLoad (it is called as soon as your Interface Builder file is finished loading). Then you can remove your brain method in your Controller and just use the instance variable brain directly.\
\
}

About

CS193P A2 - Calculator Extended - Foundation Calculator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published