本帖最后由 僞誰學ザ乖 于 2016-4-13 23:06 编辑
老师说这是一个经典题型,我就敲了发上来
- #import <Foundation/Foundation.h>
- @interface HMPerson : NSObject
- {
- @public
- NSString *_name;
- int _age;
- NSString *_playGame;
- int _IQ;
- float _weight;
- }
- - (void)introduce;
- - (void)paShanIn:(NSString *)location;
- - (void)study;
- - (void)playGameWith:(NSString *)game;
- - (void)eatFoodWith:(NSString *)food;
- @end
- @implementation HMPerson
- - (void)introduce
- {
- NSLog(@"我的名字是%@,今年%d岁.智商是%d,体重是%.2f",_name,_age,_IQ,_weight);
- }
- - (void)paShanIn:(NSString *)location
- {
- NSLog(@"我今天登上了%@,好开心.",location);
- _weight--;
- NSLog(@"登山值后,我的体重减轻到了%.2f",_weight);
- }
- - (void)study
- {
- NSLog(@"不要命的敲了一天的代码,感觉自己变聪明了.");
- _IQ++;
- NSLog(@"经过不要命的努力,我的智商提高到了%d",_IQ);
- }
- - (void)playGameWith:(NSString *)game
- {
- NSLog(@"呦西,今天玩%@爆了一把魔剑.",game);
- _IQ--;
- NSLog(@"高兴过渡,智商又下降到了%d,好伤心.",_IQ);
- }
- - (void)eatFoodWith:(NSString *)food
- {
- NSLog(@"恩,今天吃的%@还不错.",food);
- _weight++;
- NSLog(@"一不小心就体重就增加到%.2f",_weight);
- }
- @end
- int main(){
- HMPerson *ren = [HMPerson new];
- ren->_name = @"小明";
- ren->_age = 20;
- ren->_weight = 60.0;
- ren->_IQ = 70;
- [ren introduce];
- [ren playGameWith:@"DNF"];
- [ren eatFoodWith:@"面皮"];
- [ren study];
- [ren paShanIn:@"珠穆拉玛峰"];
-
-
- return 0;
- }
复制代码
|