Giter VIP home page Giter VIP logo

calculator-brain's People

Contributors

petervanhoef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ecmscs

calculator-brain's Issues

Question re: Sequence and Memory displays, and @available

Now that I've added the Memory display to the storyboard, I'm having trouble getting my Memory and Sequence displays to render the full width of the display (i.e. like I was able to in Assignment I). I figured out how to add the new Memory display, create a horizontal stack, add constraints, add a blank space in the text field of each (so they at least initially display in the storyboard), however they are bunched up on the left side of the screen, and then automatically resize depending on the text contained in each at a particular time. I've compared my code to yours to no avail, but obviously must be missing something somewhere. Any thoughts on where in my code I should look?

Re: @available, I think I understand what you did, but can you please point me somewhere to read more on deprecation? I don't understand the syntax of @available(*, deprecated, message: "Use evaluate instead"), and was trying to learn more about it - and the Xcode documentation has many "deprecation" entries, but all seemingly very case -specific and no general explanation. Thanks in advance.

Extra Credit 3: Create a launch screen

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.

Task 7: Add buttons →M and M to Calculator’s UI

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.

  1. →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.
  2. →M does not perform setOperand.
  3. Touching M should setOperand(variable: “M”) in the brain and then show the result of calling evaluate in the display.
  4. →M and M are Controller mechanics, not Model mechanics (though they both use the Model mechanic of variables).
  5. 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

Extra Credit 1: Have your calculator report errors

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

Task 3: Allow input of variables to CalculatorBrain

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.

Extra Credit 2: Add app icons

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.

Task 5: Support old API by using function evaluate

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.

Task 10: Add an Undo button

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

Task 4: Add method to evaluate CalculatorBrain

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.

Task 9: C button works properly

Make sure your C button from Assignment 1 works properly in this assignment. In addition, it should discard the Dictionary it was using for the M variable (it should not set M to zero or any other value, just stop using that Dictionary until →M is pressed again). This will allow you to test the case of an “unset” variable.

Thank you very much

I met some problems in the process of Project two. Then I got some inspiration from your code and succeed in finishing it.
Thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.