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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© YuePr 中级黑马   /  2015-12-7 21:25  /  716 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. #if 1
  2. #import<Foundation/Foundation.h>
  3. @interface Weapon :NSObject
  4. {
  5.     char * _weaponType;
  6.     int _weaponId;
  7. }

  8. -(void)setWeaponType:(char *) weaponType WID: (int)weaponId;

  9. -(int)getWeaponId;
  10. -(char*)getWeaponType;


  11. @end

  12. @implementation Weapon


  13. -(void)setWeaponType :(char *) weaponType WID :(int)weaponId
  14. {

  15.     _weaponType = weaponType;
  16.     _weaponId = weaponId;
  17. }
  18. -(int)getWeaponId
  19. {

  20.     return _weaponId;

  21. }

  22. -(char*)getWeaponType
  23. {
  24.     return _weaponType;
  25. }

  26. @end

  27. @interface Person :NSObject
  28. {

  29.     char *_personName;
  30.     int _personId;
  31.     char *_personSex;
  32.    
  33. }
  34. -(void)setPersonName :(char *)name;
  35. -(char *)getPersonName;

  36. @end
  37. @implementation Person

  38. -(void)setPersonName :(char *)name
  39. {
  40.     _personName = name;
  41. }
  42. -(char *)getPersonName
  43. {
  44.     _personSex = "defaltMAN";
  45.     _personId = 11111;
  46.     NSLog(@"person sex is %s,and ID is %d",_personSex,_personId);
  47.     return _personName;

  48. }

  49. @end

  50. @interface TrafficPolice : Person
  51. {

  52.     Weapon * _gun;
  53.    
  54.     int _policeId;

  55. }

  56. -(void)setWeapon:(Weapon *)weapon;
  57. -(Weapon *)getWeapon;

  58. -(void)setPoliceId:(int) policeid;
  59. -(int)getPoliceId;

  60. @end

  61. @implementation TrafficPolice

  62. -(void)setWeapon:(Weapon *)weapon
  63. {

  64.     _gun = weapon;

  65. }
  66. -(Weapon *)getWeapon
  67. {


  68.     return _gun;


  69. }

  70. -(void)setPoliceId:(int) policeid
  71. {
  72.     _policeId = policeid;

  73. }
  74. -(int)getPoliceId
  75. {
  76.     return _policeId;

  77. }

  78. @end





  79. int main()
  80. {

  81.    
  82.     TrafficPolice *YANGsir = [TrafficPolice new];
  83.     //Weapon *camera;
  84.     Weapon *camera = [Weapon new];
  85.     [camera setWeaponType:("AKseries")WID:8888];
  86.    
  87.    
  88.     //camera->weaponType = "AKseries";
  89.     //camera->weaponId = 8888;
  90.    
  91.     [YANGsir setPoliceId:7007];
  92.     [YANGsir setWeapon :camera];
  93.     NSLog(@"policeID is %d",[YANGsir getPoliceId]);
  94.     NSLog(@"weaponID is %d",[[YANGsir getWeapon] getWeaponId]);
  95.     NSLog(@"weaponType is %s",[[YANGsir getWeapon] getWeaponType]);
  96.     [YANGsir setPersonName:"Yang Yi-Shan"];
  97.     NSLog(@"police name is %s",[YANGsir getPersonName]);
  98.    
  99.    
  100.     return 0;
  101. }
  102. #endif
复制代码

1 个回复

倒序浏览
赞赞赞.
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马