A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© wandehua9108 中级黑马   /  2015-9-10 18:09  /  613 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马