Cs193p Assignment 2 Operations

Provides RPL (Reverse Polish Notation) calculator, where numbers are entered first then operations. For example, to add 6 and 4, you would:

This assignment solution covers all the required tasks including the ones listed under extra credit. Solution is Swift 2.0 and iOS 9.0 compatible.

Source code available at Github

Notes:

1. Overloaded the enter function for user input, because we want add to add it the history. The enter function is also called from other places in the code where we don’t want to add to history.

2. As mentioned in the assignment hints, floating point implementation was possible to add with a single-line of code:

3. Pi implementation does not use the performOperation function but inline code since it’s easy to add:

Video Demo:

Like this:

LikeLoading...

Related

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

0 thoughts on “Cs193p Assignment 2 Operations

Leave a Reply

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