Problem Set 1: Getting Started
Assigned: Tuesday January 17, 2012
Due: Friday January 27, 2012
Points: 8
This assignment has some reading, a number of administrative tasks
and a warm-up problem on Objective C. The reading and
administrative tasks are due by classtime Thursday. The
warm-up programming project is due by next Friday January 27 at
5PM.
Reading and Administrative Tasks (Due by classtime Thursday)
- Read About iOS Development and read Chapters 1 and 2 of MNL.
- If you aren't already a member, visit Apple's
iOS Development Center and register for the iOS Developer Program.
- If you haven't already done so,
download and install Xcode.
- Send me an email answering the following questions:
- What year are you and what is your major?
- What CS courses have you taken?
- Have you done any iOS programming? If so, how many
months of experience?
- What programming languages do you know? For each, how
well do you know the language (out of 10 with 10 being expert).
- Do you own a Mac? If so, what kind and what version of
Mac OS X are you running?
- Do you own an iPhone? Do you own an iPad?
- What is the air-speed velocity of an unladen swallow?
- Do you have a app project in mind? If so, please briefly
describe it. (If not, start thinking about it!)
Implementing a Reverse Polish Notation (RPN) Calculator (Due 5PM, 1/27/2012)
|
The first demo from class as well as this first problem set are both adapted
from material presented in the 2011 edition of Paul Hegartys'
CS193P
iPad and iPhone Application Development course at Stanford. It's an excellent
course and I highly recommend the materials. This problem set isn't identical
to CS193P problem set 1, but it's pretty close --- an RPN Calculator makes a
great starter problem for touch sensitive platforms in general and iOS in
particular.
Reverse Polish Notation
Fully parenthesized arithmetic expressions can be evaluated by a method
called reduction and rewriting. The idea is as simple as it is familiar:
evaluate the subexpressions from left-to-right until the value of the
entire expression is obtained. For example, pronouncing "-->" as "rewrites to",
we could evaluate the expression (2 + 3) * (4 - 1) as follows:
((2 + 3) - (2 * 2)) -->
(5 - (2 * 2)) -->
(5 - 4) -->
1
The explicit parenthesization determines the order in which the
operation will be carried out. In the absence of parentheses, we rely
on rules governing the precedence and associativity of the operators,
they cannot simply be evaluated left-to-right. (Try it, on 2 + 3 -
2 * 2.)
|
The Polish mathematician
Jan Lukasiewicz
(pronounced "Yan") recognized that arithmetic expressions could be evaluated
left-to-right without parentheses if the operators were placed
in postfix position. His notation is sometimes called
postfix notation and sometimes called Reverse
Polish in honor of his nationality. According to Lukasiewicz, we
could just as easily write the above as 2 3 + 2 2 * -. We could
then evaluate from left-to-right as follows:
2 3 + 2 2 * - -->
5 2 2 * - -->
5 4 - -->
1
Reverse Polish notation is particularly handy for hand-held
calculators because it allows the user to enter complex arithmetic
expressions without remembering intermediate results. Reverse Polish
notation was used in a very popular line of calculators produced by
Hewlitt-Packard.
Examining the above evaluation sequence, we see in the second line that
when we scan rightward to find the multiplication operator *, we are
effectively using the notation on the left as a stack of operands.
In particular, when we find an operator, we pop the most recent 2 operands
off the stack, combine them with the operator and then push the result
back on the stack and continue scanning. This is the basis of the
RPN calculator that we developed in class.
In the demo code from class, we implemented code that would accept
interaction of the form: number, Enter, number Enter, operator.
In this problem set you are to expand the calculator by adding:
- A . (dot) button --- this button will allow the user to enter
floating point numbers. Note that a floating point number has at most 1
dot!
- A Clear button --- this button should cause erase the display;
- A sqrt button --- this button should compute the square root
of the value on top of the stack;
- A pi button --- this button should push the floating point
number 3.14 onto the stack.
|