-3
이미 작성된 코드가 있습니다. 그러나이 사이트의 다른 답변에서 찾을 수없는 설명이 필요합니다. 나를 도울 수있는 확실한 모범을 찾지 못했습니다.배열을 반복하여 각 값을 출력하십시오.
올바르게이 배열을 통해 '반복'으로 간주됩니까? 나는 이것이 정말로 하드 코딩 된 것처럼 느낀다. 나는 아직도 배우고있다. 감사합니다
NSMutableArray *stocks = [NSMutableArray array];
BNRStockHolding *A = [[BNRStockHolding alloc]init];
BNRStockHolding *B = [[BNRStockHolding alloc]init];
BNRStockHolding *C = [[BNRStockHolding alloc]init];
[stocks insertObject:A atIndex:0];
[stocks insertObject:B atIndex:1];
[stocks insertObject:C atIndex:2];
for (int i = 0; i < 1; i++)
{
{
[A setNumberOfShares:40];
[B setNumberOfShares:90];
[C setNumberOfShares:210];
[A setPurchaseSharePrice:2.30];
[B setPurchaseSharePrice:12.19];
[C setPurchaseSharePrice:45.10];
[A setCurrentSharePrice:4.50];
[B setCurrentSharePrice:10.56];
[C setCurrentSharePrice:49.51];
float costA = [A costInDollars];
float costB = [B costInDollars];
float costC = [C costInDollars];
NSLog(@"This stock costs %.2f", costA);
NSLog(@"This stock costs %.2f", costB);
NSLog(@"This stock costs %.2f", costC);
NSLog(@"\n");
float valueA = [A valueInDollars];
float valueB = [B valueInDollars];
float valueC = [C valueInDollars];
NSLog(@"The current value of this stock is %.2f", valueA);
NSLog(@"The current value of this stock is %.2f", valueB);
NSLog(@"The current value of this stock is %.2f", valueC);
}
}