#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;
}
|
|