黑马程序员技术交流社区
标题:
oc第一天
[打印本页]
作者:
wandehua9108
时间:
2015-9-10 18:09
标题:
oc第一天
#import<Foundation/Foundation.h>
@interface Person: NSObject
{
@public
int _age;
float _weight;
}
-(float) eat:(int)x;
-(float) walk:(int)x;
@end
@implementation Person
-(float) eat:(int)x{
_weight+=0.6*x;
return _weight;
}
-(float) walk:(int)x{
_weight-=0.2*(x/100);
return _weight;
}
@end
int main(){
@autoreleasepool {
Person *person=[Person new];
person->_weight=100;
float eatWeight=[person eat:1];
float walkWeight=[person walk:200];
NSLog(@"eatWeight=%.2f,walkWeight=%.2f",eatWeight,walkWeight);
}
return 0;
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2