Big Nerd Ranch の Objective-C ガイドを使用していますが、作成したクラスのすべてのアイテムを表示するのに問題があります。詳しくは、第 17 章の株式に関する課題を参照してください。この問題について他にも質問があることは承知していますが、他のすべての修正済みコードを確認しましたが、問題は解決していません。なぜかFacebookの費用しか表示されていません。ここに私の作品があります: StockHolding.h
#import <Foundation/Foundation.h>
@interface StockHolding : NSObject
{
float purchaseSharePrice;
float currentSharePrice;
int numberOfShares;
}
@property float purchaseSharePrice;
@property float currentSharePrice;
@property int numberOfShares;
- (float)costInDollars;
- (float)valueInDollars;
@end
StockHolding.m
#import "StockHolding.h"
@implementation StockHolding
@synthesize purchaseSharePrice;
@synthesize currentSharePrice;
@synthesize numberOfShares;
-(float)costInDollars
{
return numberOfShares*purchaseSharePrice;
}
-(float)valueInDollars
{
return numberOfShares*currentSharePrice;
}
@end
main.m
#import <Foundation/Foundation.h>
#import "StockHolding.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
StockHolding *apple, *google, *facebook = [[StockHolding alloc] init];
[apple setNumberOfShares:43];
[apple setCurrentSharePrice:738.96];
[apple setPurchaseSharePrice:80.02];
[google setNumberOfShares:12];
[google setCurrentSharePrice:561.07];
[google setPurchaseSharePrice:600.01];
[facebook setNumberOfShares:5];
[facebook setCurrentSharePrice:29.33];
[facebook setPurchaseSharePrice:41.21];
NSLog(@"%.2f.", [apple costInDollars]);
NSLog(@"%.2f.", [google costInDollars]);
NSLog(@"%.2f.", [facebook costInDollars]);
}
return 0;
}
ご協力いただきありがとうございます!