//
// main.m
/*
类的创建练习
*/
#import <Foundation/Foundation.h>
@interface Person:NSObject
{
@public
NSString *_name;
int _age;
float _weight;
}
-(void)eat:(NSString *) foodName ;
-(void)walk:(int) num;
@end
@implementation Person
-(void)eat:(NSString *) foodName{
_weight +=0.6f;
NSLog(@"您吃了%@,当前体重为:%.2f",foodName,_weight);
}
-(void)walk:(int)num{
_weight -= num/100*0.2f;
NSLog(@"您走了%d步,当前体重为:%.2f",num,_weight);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *p = [Person new];
p->_name = @"史密斯.李";
p->_weight = 160.0f;
p->_age = 18;
[p eat:@"回锅肉"];
[p eat:@"麻辣烫"];
[p walk:10600];
}
return 0;
} |
|