C348: iPhone Programming

Deliberate Practice Makes Perfect

Problem 11

Student Info
Question 1

Write the code to declare and initialise an array with 3 NSStrings (@“Tom”, @“Dick, @“Harry”)

								
Question 2

Name the two protocols used in a UITableView

								
Question 3

NSArray *array = @[@“Tom”,@“Dick”,@“Harry”];for (int i=[array count]-1;i>=0 ; i—){   NSLog(@"%@ is in position %d", array[i], i);}

Write the output of the NSLog() statement.


								
Question 4

The factorial of an integer n, written n! , is the product of the consecutive integers 1 through n. For example, 5 factorial is calculated as follows: 5! = 5 x 4 x 3 x 2 x 1 = 120Using a for loop, write the code to generate and print a table of the first 10 factorials as follows (no hard coding)

1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720 
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
 

								
Question 5

The method to add two complex numbers is given as:

-(Complex *) add: (Complex *) complexNum;

How many parameter(s) this method takes in?  And what is the return type?


								
Question 6

A Rectangle class is defined as follows:

@interface Rectangle: NSObject@property int width, height;-(int) area;-(int) perimeter;@end

What is the superclass of Rectangle?  
Name the two properties and methods defined by this class.

								
Question 7

You have 3 view controller objects, which you want to switch between them using Tab Bar Controller.  Describe how you will do it in Xcode.