# Cs193p Solutions Assignment 1

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*

The Graphing Calculator project is a continuation of the previous 2 assignments from the Stanford University CS193P course Developing iOS 8 Apps with Swift, available for free on iTunes. This is the third and final assignment in the Calculator series.

Full source code available here at Github repository

For the other 2 projects, please see:

CalculatorBrain: Assignment 2, Stanford University Winter 2015 (iOS)

Calculator: Assignment 1, Stanford University Winter 2015 (iOS)

This project provides graphing features in addition to the regular calculator functions. Graphs can be plotted by entering expressions where M is the independent variable. Please see examples below.

To plot M, enter:

M, GraphTo plot sin(M), enter:

M, Sin, GraphTo plot M x cos(M), enter:

M, M, cos, x, Graph**Some interesting notes**

- The CalculatorBrain is reused to calculate the values of M for graphing
- Plot values are set in the GraphingViewController as the data source of GraphingView
- To fix the sluggish performance when zoomed out and panned, only the number of plots required for the screen width are calculated
- Graph scale and origin is stored in NSUserDefaults
- Upon device rotation, the graph is centered and adjusted slightly with the width and height change ratio

**Video demo**

### Like this:

LikeLoading...