#import <Foundation/Foundation.h>
typedef enum {iColoryellow,iColorwhite,iColorblack} iColor;
typedef enum {kSexman,kSexwoman,kSexyao} iSex;
@interface Dog:NSObject
{ @public
iColor _color;
int _speed;
iSex _sex;
float _weight;
}
-(void)eat;
-(void)bark;
-(void)run;
-(int)isComparColor:(iColor) otherColor;
-(int)isComparSpeed:(int) otherSpeed;
@end
@implementation Dog
-(void)eat
{
NSLog(@"%.2f",_weight+=0.5);
}
-(void)bark
{
NSLog(@"%d,%d,%d,%.2f",_color,_speed,_sex,_weight);
}
-(void)run
{
NSLog(@"%d,%.2f",_speed,_weight-=0.5);
}
-(int)isComparColor:(iColor) otherColor
{
if (_color-otherColor==0)
{
return 0;
}else return 1;
}
-(int)isComparSpeed:(int) otherSpeed
{
return _speed-otherSpeed;
}
@end
@interface Person : NSObject
{ @public
NSString *_name;
Dog *_dog;
}
-(void)feeddog;
-(void)walkdog;
@end
@implementation Person
-(void)feeddog
{
[_dog eat];
}
-(void)walkdog
{
[_dog run];
}
@end
int main()
{
@autoreleasepool {
Dog *tangtang=[Dog new];
tangtang->_color=iColoryellow;
tangtang->_speed=10;
tangtang->_sex=kSexman;
tangtang->_weight=8.9;
Person *wanwan=[Person new];
wanwan->_dog=tangtang;
[wanwan feeddog];
[wanwan walkdog];
[wanwan feeddog];
[wanwan feeddog];
[wanwan feeddog];
[wanwan walkdog];
[wanwan walkdog];
}
return 0;
}