Assignment #2 Task #1

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

The second assignment is a further extension of the calculator built in the previous assignment.

Add the capability to your CalculatorBrain to accept variables as operands (in addition to still accepting doubles as operands). You will need new public API in your CalculatorBrain to support this.

A variable will be specified as an NSString object. To simplify your implementation, you can ignore attempts to push a variable whose name is the same as an operation (e.g. you can ignore an attempt to push a variable named “sqrt”).

The values of the variables will only be supplied when the “program” is “run.” You must add a new version of the runProgram: class method with the following signature …

+ (double)runProgram:(id)program usingVariableValues:(NSDictionary *)variableValues;

The keys in the passed variableValues dictionary are NSString objects corresponding to the names of variables used in the passed program, and the values in the dictionary are NSNumber objects specifying the value of the corresponding variable (for this assignment we will supply “test” values, see Required Task #3).

If there are variables in the specified program for which there are no values in the specified NSDictionary, use a value of 0 for those variables when you run the program. This should be the case if someone calls the original runProgram: method (the one shown in the demo in class).
In addition, create another class method to get all the names of the variables used in a given program (returned as an NSSet of NSString objects) …

+ (NSSet *)variablesUsedInProgram:(id)program;

If the program has no variables return nil from this method (not an empty set).

We will start by implementing the new runProgram method. If we have an actual program meaning array we loop through the program and replace variables by its values and finally run the cleaned up program:
Continue reading “Assignment #2 Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Friday Session #2: Xcode and Source Code Management

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

Between lecture #4 and lecture #5 the second Friday session addressed source control. It can be found on iTunes titled “Xcode and Source Code Management (October 7, 2011)”.

This lecture explains how to use the local source control functionality of Xcode, as well as how to add source control later on if you did not add it when you initially created the project.

If not added initially the git has to activated manually via the terminal. First change into your project directory, find UserInterfaceState.xcuserstate which you have to .gitignore because you do not want to add it to your repository as it changes practically by only looking at Xcode. e.g.:
Continue reading “Friday Session #2: Xcode and Source Code Management”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Lecture #4: Views

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

The forth lecture is called “4. Views (October 6, 2011)” and can be found via iTunes. Its slides are available directly at Stanford.

It starts with an half-an-hour demo/walkthrough preparing the calculator for the second assignment using functionality learned in the previous lectures. When you have finished this part you should have something similar to like our example on github. Alternatively a sample code can be downloaded from Stanford but it does not include all the functionality from the previous assignments.
Continue reading “Lecture #4: Views”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Lecture #3: Objective-C

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

The third lecture is called “3. Objective-C (October 4, 2011)” and can be found via iTunes. Its slides are available directly at Stanford.

It starts with a review what we have learned doing the walkthrough of the last lecture and explains in more detail
Continue reading “Lecture #3: Objective-C”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

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