Coder Social home page Coder Social logo

robhasacamera / codingtogether Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 3.0 250 KB

These are the projects that are part of the Coding Together iTunes course available on [iTunes U](http://itunes.apple.com/us/course/coding-together-apps-for-iphone/id537447071).

Objective-C 100.00%

codingtogether's Introduction

CodingTogether

These are the projects that are part of the Coding Together iTunes course available on iTunes U.

codingtogether's People

Contributors

robhasacamera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

codingtogether's Issues

Cannot handle negative sqrt

The calculator cannot properly hanlde negative square roots. When calculating the square root of a negative number, it gives nan as a result. When graphing y = sqrt(x), it has a line in negative values.

Implement Variables

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 issue #15).

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

Handle Floating Point Numbers

  1. Your calculator already works with floating point numbers (e.g. if you touch the buttons 3 Enter 4 / it will properly show the resulting value of 0.75), however, there is no way for the user to enter a floating point number. Remedy this. Allow only legal floating point numbers to be entered (e.g. “192.168.0.1” is not a legal floating point number). Don’t worry too much about precision in this assignment.

Handle Invalid Operations

  1. If the user performs an operation for which he or she has not entered enough operands, use zero as the missing operand(s) (the code from the walkthrough does this already, so there is nothing to do for this task, it is just a clarification of what is required). Protect against invalid operands though (e.g. divide by zero).

Add Tests

Update the user-interface of your Calculator to test all of the above.

  1. Your UI should already have a UILabel which shows what has been sent to the brain. Change it to now always show the latest description of the program currently in the CalculatorBrain using your descriptionOfProgram: method. It should show the description without substituting variable values (obviously, since descriptionOfProgram: does not take a variable value dictionary as an argument).
  2. Add a few variable buttons (e.g, x, y, foo). These are buttons that push a variable into the CalculatorBrain.
  3. Change your calculator to update its display (as needed) by calling your new runProgram:usingVariableValues: method. The variable values dictionary it passes to this method should be a property in your Controller (let’s call it “testVariableValues”).
  4. Add a UILabel to your UI whose contents are determined by iterating through all the variablesUsedInProgram: and displaying each with its current value from testVariableValues. Example display: “x = 5 y = 4.8 foo = 0”.
  5. Add a few different “test” buttons which set testVariableValues to some preset testing values. One of them should set testVariableValues to nil. Don’t forget to update the rest of your UI when you change testVariableValues by pressing one of these test buttons. Make sure that your preset values are good edge-cases for testing (we are intentionally not telling you what to use since part of good programming is figuring out how to thoroughly test your application).

Implement Methods from Lecture

Your solution to this assignment must include properly functioning implementations for the three public methods added to the CalculatorBrain in lecture. You may change the internal implementations as necessary (though you almost certainly do not want to change the implementation for the @Property), but do not change the public API for these (including whether a method is a class method or not):

@property (readonly) id program;
+ (double)runProgram:(id)program;
+ (NSString *)descriptionOfProgram:(id)program;

Autorotate Support

You do not have to support rotation on all devices, but on the devices where you do support it, the user-interface should look good in all cases (so get your struts and springs right in your storyboard(s)).

UINavigationController

When your application is run on the iPhone, it must present the user-interface of your calculator from Assignment 2 inside a UINavigationController.

Persistent Scale

Once the user picks a scale by pinching or a new origin by panning or tapping, the new value should be stored in NSUserDefaults so that the scale and origin persist as new programs are graphed and even through relaunchings of your program.

Re-implement Description of Program

Re-implement the descriptionOfProgram: method from the last lecture to display the passed program in a more user-friendly manner. Specifically ...

  1. It should display all single-operand operations using “function” notation. For example, 10 sqrt should display as sqrt(10).
  2. It should display all multi-operand operations using “infix” notation if appropriate, else function notation. For example, 3 Enter 5 + should display as 3 + 5.
  3. Any no-operand operations, like π, should appear unadorned. For example, π.
  4. Variables (Ticket #12) should also appear unadorned. For example, x.

Any combination of operations, operands and variables should display properly.
Examples (E means “Enter key”) ...

  1. 3 E 5 E 6 E 7 + * - should display as 3 - (5 * (6 + 7)) or an even cleaner
    output would be 3 - 5 * (6 + 7).
  2. 3 E 5 + sqrt should display as sqrt(3 + 5).
  3. 3 sqrt sqrt should display as sqrt(sqrt(3)).
  4. 3 E 5 sqrt + should display as 3 + sqrt(5).
  5. π r r * * should display as π * (r * r) or, even better, π * r * r.
  6. a a * b b * + sqrt would be, at best, sqrt(a * a + b * b).

As you can see, you will have to use parentheses in your output to correctly display the program. For example, 3 E 5 + 6 * is not 3 + 5 * 6, it is (3 + 5) * 6. Try to keep extraneous parentheses to a minimum though (see Hints).

It might be that there are multiple things on the stack. If so, separate them by commas in the output with the top of the stack first, for example 3 E 5 E would display as “5, 3”. 3 E 5 + 6 E 7 * 9 sqrt would be “sqrt(9), 6 * 7, 3 + 5”.

Get Variables Used

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)

This is dependent on ticket #12.

iOS 5 Walthrough

  1. Follow the walk-through instructions (separate document) to build and run the calculator in the iPhone Simulator. Do not proceed to the next steps unless your calculator functions as expected and builds without warnings or errors.

Graphing View

To implement your new MVC, you must write a custom graphing View which must display the axes of the graph in addition to the plot of the program. Code will be provided on the class website which will draw axes with an origin at a given point and with a given scale, so you will not have to write the Core Graphics code for the axes, only for the graphing of the program itself. You probably will want to examine the provided axes-drawing code to understand how the scaling works before you do this or any of the following Required Tasks.

Divide and Subtract Incorrect Operation Detection

The divide "/" and subtract "-" signs are not being detected properly as double operations in the descriptionOfTopOfStack: method. Likely the isDoubleOperandOperation: method is not detecting them correctly.

This is related to implementing ticket #14.

Avoid "Evaluation" Issues

  1. Avoiding the problems listed in the Evaluation section below is part of the required tasks of every assignment. This list grows as the quarter progresses, so be sure to check it again with each assignment.

Branch Assignment 2

When finished with assignment 2 branch it into a separate branch so the original can be kept while working in the main branch for assignment 3.

Add Clear Button

  1. Add a “C” button that clears everything (for example, the display in your View, the operand stack in your Model, any state you maintain in your Controller, etc.). Make sure 3 7 C 5 results in 5 showing in the display. You will have to add API to your Model to support this feature.

Inverted Y

It looks like y is being inverted, if only a single number is entered (such as 50), a line will be plotted as its inverted value (such as -50).

Add Graphing Function

Add a Graph button to your calculator’s user-interface that, when pressed, segues to a new MVC (that you will have to write) by pushing it onto the UINavigationController’s stack (on the iPhone). The new MVC graphs whatever program was in the calculator when the button was pressed. To draw the graph you will iterate over all the pixels in your view horizontally (x) and use +runProgram:usingVariableValues: to get the corresponding vertical (y) value. You will, of course, have to convert to/from your view’s coordinate system from/to a reasonable graph coordinate system. You will need a scale and origin to do this coordinate system conversion. If the user has not already chosen a scale and origin for the graph (see ticket #27 and #28), pick a reasonable starting scale and origin.

Additional Operations

  1. Add the following 4 operation buttons:
  • sin : calculates the sine of the top operand on the stack.
  • cos : calculates the cosine of the top operand on the stack.
  • sqrt : calculates the square root of the top operand on the stack.
  • π: calculates (well, conjures up) the value of π. Examples: 3 π * should put three times the value of π into the display on your calculator, so should 3 Enter π *, so should π 3 *. Perhaps unexpectedly, π Enter 3 * + would result in 4 times π being shown. You should understand why this is the case. NOTE: This required task is to add π as an operation (an operation which takes no arguments off of the operand stack), not a new way of entering an operand into the display.

Undo Button

Add an Undo button to your calculator. Hitting Undo when the user is in the middle of typing should take back the last digit or decimal point pressed until doing so would clear the display entirely at which point it should show the result of running the brain’s current program in the display (and now the user is clearly not in the middle of typing, so take care of that). Hitting Undo when the user is not in the middle of typing should remove the top item from the program stack in the brain and update the user- interface.

This task can be implemented with 1 method in your Controller (of about 5-6 lines of code, assuming you’ve factored out the updating of your user-interface into a single method somewhere) and 1 method (with 1 line of code) in your Model. If it’s taking much more than that, you might want to reconsider your approach.

Remove Extra Variables and Test Buttons

The only variable button your calculator’s user-interface should present is x (so remove any others you added in Assignment 2 and you can remove your Test buttons and the UILabel which shows the value of the variables being used in the display).

Reusable Graphing View (Protocol)

Your graphing UIView must be generic and reusable (i.e. it should be a generic x-y graphing class and know nothing about a CalculatorBrain). Use a protocol to get the graphing view’s data because Views should not own their data.

Branch Assignment 1

Branch assignment 1 into a separate branch so the original can be kept while working on assignment 2 in the main branch.

Don't Allow Crashes

Don’t let anything crash your program in CalculatorBrain. It should defend against any value being passed through its API.

Gesture Support

Support the following gestures inside your graphing view:

  • Pinching (adjusts your view’s scale).
  • Panning (moves the entire graph, including axes, to follow the touch around).
  • Triple-tapping (moves the origin of the graph to the point of the triple-tap).

iPad Support

Make your Calculator work on the iPad too (in the same application, i.e., a Universal application) by having two storyboards, one for the iPhone (described above) and one for the iPad that uses a UISplitViewController to present your old Calculator MVC on the left of the screen (or in a popover) and your new graphing MVC on the right.

Since both MVCs will be on the screen at the same time, you will not need a segue; instead, you will have to get a pointer to the other MVC using UISplitViewController API. You should only update the right side of the split view when the Graph button is pressed (not continuously as the brain is modified).

Show Description of Program with Graph

Anytime a graph is on screen, the description of the program used to draw it (e.g. the result of your +descriptionOfProgram: method) should also be shown on screen somewhere sensible. This might be a different place on the iPhone versus the iPad.

Display Operand and Operation History

  1. Add a new text label (UILabel) to your user-interface which shows everything that has been sent to the brain (separated by spaces). For example, if the user has entered 6.3 Enter 5 + 2 *, this new text label would show6.3 5 + 2 *. A good place to put this label is to make it a thin strip above the display text label. Don’t forget to have the C button clear this too. All of the code for this task should be in your Controller (no changes to your Model are required for this one). You do not have to display an unlimited number of operations and operands, just a reasonable amount.

Show Description of Program with Graph

Anytime a graph is on screen, the description of the program used to draw it (e.g. the result of your +descriptionOfProgram: method) should also be shown on screen somewhere sensible. This might be a different place on the iPhone versus the iPad.

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.