頭檔
#import "LSTStockHolding.h"
@implementation LSTStockHolding
-(float)costInDollars
{
float c = [self purchaseSharePrice];
return c*[self numberOfShares];
}
-(float)valueInDollars
{
return [self currentSharePrice]*[self numberOfShares];
main函數
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
LSTStockHolding *China = [[LSTStockHolding alloc]init];
China.purchaseSharePrice = 4.0;
China.currentSharePrice = 5.0;
China.numberOfShares = 6.0;
float cid =[China costInDollars];
float vid =[China valueInDollars];
NSLog(@"The cid is:%.2f,the vid is:%.2f.",cid,vid);
NSArray *list = @[China];
for(NSString *s in list)
{
NSLog(@"Here is a list:%@",s);
}
}
return 0;
運行結果如圖
2016-09-08 15:36:20.988 20章[863:97992] The cid is:24.00,the vid is:30.00.
2016-24.00,the vid is:30.00.
2016-09-08 15:396963:3966-09-6863:3966990963:39663:39663:396963:39669:39669:396963:396969:3969393993999399399393933位[3933999939分話[ :97992] Here is a list:
我想透過遍歷數組的操作,枚舉數組list的物件並且輸出LSTStockHolding物件的值,該如何操作呢?目前運行結果是回傳了一個位址。 。初學者不太懂🎜
因為印刷的是指針,如果你想要打印更詳細的信息
你可以重寫
LSTStockHolding
类的description
方法,如下教程