:geek:
I’m not sure about this, I did it the best way I understood how. Please correct me if I’m wrong and point out the flaws. Thank you.
[code]
#import <Foundation/Foundation.h>
#import “BNRStockHolding.h”
int main(int argc, const char * argv[])
{
@autoreleasepool {
// StockHolding first instance
BNRStockHolding *newStock1 = [[BNRStockHolding alloc] init];
// Asigning values to first instance
newStock1.purchaseSharePrice = 2.30;
newStock1.currentSharePrice = 4.50;
newStock1.numberOfShares = 40;
// StockHolding second instance
BNRStockHolding *newStock2 = [[BNRStockHolding alloc] init];
// Asigning values to second instance
newStock2.purchaseSharePrice = 12.19;
newStock2.currentSharePrice = 10.56;
newStock2.numberOfShares = 90;
// StockHolding third instance
BNRStockHolding *newStock3 = [[BNRStockHolding alloc] init];
// Asigning values to third instance
newStock3.purchaseSharePrice = 45.10;
newStock3.currentSharePrice = 49.51;
newStock3.numberOfShares = 210;
// Initiating an NSMutableArray to hold above
// created stock instances
NSMutableArray *stockHolder = [[NSMutableArray alloc] init];
// Adding StockHolding instance objects to
// the stockHolder mutable array
[stockHolder addObject:newStock1];
[stockHolder addObject:newStock2];
[stockHolder addObject:newStock3];
// Looping through the stockHolder array
for(BNRStockHolding *holderArray in stockHolder) {
// Displaying cost and value in dollars.
NSLog(@"Cost In Dollars is:%f\n", holderArray.costInDollars);
NSLog(@"Value In Dollars is:%f\n", holderArray.valueInDollars);
}
}
return 0;
}[/code]