November 2013
Beginner
325 pages
9h 47m
English
Create a new Foundation Command Line Tool called Stocks. Then create a class called BNRStockHolding to represent a stock that you have purchased. It will be a subclass of NSObject. For instance variables, it will have two floats named _purchaseSharePrice and _currentSharePrice and one int named _numberOfShares. Use properties to create accessor methods and instance variables. Create two other instance methods:
- (float)costInDollars; // purchaseSharePrice * numberOfShares - (float)valueInDollars; // currentSharePrice * numberOfShares
In main(), fill an array with three instances of BNRStockHolding. Then iterate through the array printing out the value of each.
Figure 18.4 An array of BNRStockHolding objects
Read now
Unlock full access