Profile cover photo
Profile photo
cs193p assignment solutions et al
11 followers -
everything iOS ... mostly ...
everything iOS ... mostly ...

11 followers
About
Posts

Post has attachment
#cs193p #assignment2 #extraTask3

Create a launch screen for your Calculator in LaunchScreen.storyboard.Remember that you will want to use some simple autolayout to make your launch screen look good on all platforms.

https://cs193p.m2m.at/cs193p-assignment-2-extra-task-3-winter-2017/
Photo
Add a comment...

Post has attachment
#cs193p #assignment2 #extraTask2

Add app icons to your Assets.xcassets file (which we moved to Supporting Files in Lecture 1). The only trick here is to provide versions of your icon in all the right sizes.

https://cs193p.m2m.at/cs193p-assignment-2-extra-task-2-winter-2017/
Photo
Add a comment...

Post has attachment
#cs193p #assignment2 #extraTask1

Have your calculator report errors. For example, the square root of a negative number or divide by zero. There are a number of ways to go about “detecting” these errors (maybe add an associated value to the unary/binaryOperation cases which is a function that detects an error or perhaps have the function that is associated with a unary/binaryOperation return something that is either an error or a result or ???). How you report any discovered errors back to users of the CalculatorBrain API will require some API design on your part, but don’t force users of the CalculatorBrain API to deal with errors if they don’t want to (i.e. allow Controllers that want to display errors to do so, but let those that don’t just deal with NaN and +∞ appearing in their UI). In other words, don’t break any callers of the API described above (who don’t care about errors) to support this feature (i.e., add methods/ properties as needed instead). You are allowed to violate Required Task 11 to implement this Extra Credit item, but not Required Task 1 (you can enhance that data structure, but not switch to a new one).

https://cs193p.m2m.at/cs193p-assignment-2-extra-task-1-winter-2017/

Photo
Add a comment...

Post has attachment
#cs193p #assignment 2 #task 10

Add an Undo button to your Calculator. In Assignment 1’s Extra Credit, you might have added a “backspace” button. Here we’re talking about combining both backspace and actual undo into a single button. If the user is in the middle of entering a number, this Undo button should be backspace. When the user is not in the middle of entering a number, it should undo the last thing that was done in the CalculatorBrain. Do not undo the storing of M’s value (but DO undo the setting of a variable as an operand).

https://cs193p.m2m.at/cs193p-assignment-2-task-10-winter-2017/
Photo
Add a comment...

Post has attachment
#assignment #2 #task #8

Show the value of M (if set) in your UI somewhere.

https://cs193p.m2m.at/cs193p-assignment-2-task-8-winter-2017/
Photo
Add a comment...

Post has attachment
#assignment #2 #task #6

Add two new buttons to your Calculator’s UI: →M and M. Don’t sacrifice any of the required operation buttons from Assignment 1 to add these (though you may add yet more operations buttons if you want). These two buttons will set and get (respectively) a variable in the CalculatorBrain called M.
a. →M calls evaluate in your Model with a Dictionary which has a single entry whose key is M and whose value is the current value of the display, and then updates the display to show the result that comes back from evaluate. Until this button (or the clear button) is pressed again, this same Dictionary should be used every time evaluate is called.
b. →M does not perform setOperand.
c. Touching M should setOperand(variable: “M”) in the brain and then show the
result of calling evaluate in the display.
d. →M and M are Controller mechanics, not Model mechanics (though they both use
the Model mechanic of variables).
e. This is not a very great “memory” button on our Calculator, but it can be used for testing whether our variable function implemented in our Model is working properly. Examples …
9 + M = √ ⇒ description is √(9+M), display is 3 because M is not set (thus 0.0).
7 →M ⇒ display now shows 4 (the square root of 16), description is still √(9+M) + 14 = ⇒ display now shows 18, description is now √(9+M)+14

https://cs193p.m2m.at/cs193p-assignment-2-task-7-winter-2017/
Photo
Add a comment...

Post has attachment
#assignment #2 #task #5

We made the result, description and resultIsPending vars non-private API in Assignment 1. That means we signed up to continue to support them even though we are now adding a new feature (variables) in this assignment which sort of makes them irrelevant. Really what we want to do is deprecate these (you’ll see all sorts of deprecated iOS API in Xcode), but for now we will keep the old result, description and resultIsPending vars around and just implement each of them by calling evaluate with the argument nil (i.e. they will give their answer assuming the value of any variables is zero). However, do not use any of these vars anywhere in your code in this assignment. Use evaluate instead.

https://cs193p.m2m.at/cs193p-assignment-2-task-5-winter-2017/
Add a comment...

Post has attachment
#assignment #2 #task #4

Now that you allow variables to be entered as operands, add a method to evaluate the CalculatorBrain (i.e. calculate its result) by substituting values for those variables found in a supplied Dictionary …

func evaluate(using variables: Dictionary<String,Double>? = nil)
-> (result: Double?, isPending: Bool, description: String)

Note that this takes an Optional Dictionary (with Strings as keys and Doubles as values) as its argument and that that argument defaults to nil if not supplied when this method is called. Also note that it returns a tuple (the first element of which is an Optional Double). This method is not mutating and you are not allowed to make it so. If a variable that has been set as an operand is not found in the Dictionary, assume its value is zero.

https://cs193p.m2m.at/cs193p-assignment-2-task-4-winter-2017/
Add a comment...

Post has attachment
#assignment #2 #task #3

Add the capability to your CalculatorBrain to allow the input of variables. Do so by implementing the following API in your CalculatorBrain …

func setOperand(variable named: String)

This must do exactly what you would imagine it would: it inputs a “variable” as the operand (e.g. setOperand(variable: “x”) would input a variable named x). Setting the operand to x and then performing the operation cos would mean cos(x) is in your CalculatorBrain.

https://cs193p.m2m.at/cs193p-assignment-2-task-3-winter-2017/
Add a comment...

Post has attachment
#assignment #1 #extraTask #3

Make one of your operation buttons be “generate a #randomDoublePrecision floating point number between 0 and 1”. This operation button is not a constant (since it changes each time you invoke it). Nor is it a unary operation (since it does not operate on anything). Probably the easiest way to generate a random number in iOS is the global Swift function arc4random() which generates a random number between 0 and the largest possible 32-bit integer (UInt32.max). You’ll have to get to double precision floating point number from there, of course.

https://cs193p.m2m.at/cs193p-assignment-1-extra-task-3-winter-2017/

Photo
Add a comment...
Wait while more posts are being loaded