本帖最后由 堕落天使 于 2015-10-19 10:15 编辑
- /*
- 水浒卡登记系统
- 类名:水浒108将(Hero_108)
- 属性:名字(_name),外号(_nickName),排名(_num)职务(_post),武器(_weapon),大招(_skill)。
- 行为:查看人物属性(aboutHero),对某个人放大招(attack)
- */
- #import <Foundation/Foundation.h>
- @interface Hero_108:NSObject
- {
- @public
- NSString *_name;
- NSString *_nickName;
- int _num;
- NSString *_post;
- NSString *_weapon;
- NSString *_skill;
- }
- -(void)aboutHero;
- -(void)attack:(NSString *) enemy;
- @end
- @implementation Hero_108
- -(void)aboutHero{
- NSLog(@"姓名:%@,外号:%@,排名:%d,职务:%@,武器:%@,大招:%@",_name,_nickName,_num,_post,_weapon,_skill);
- }
- -(void)attack:(NSString *) enemy{
- NSLog(@"%@用%@干掉了%@",_name,_skill,enemy);
- }
- @end
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Hero_108 *yanQin=[Hero_108 new];
- yanQin->_name=@"燕青";
- yanQin->_nickName=@"浪子";
- yanQin->_num=36;
- yanQin->_post=@"步军统领兼谍报队长";
- yanQin->_weapon=@"飞燕弩";
- yanQin->_skill=@"夺命扑";
- [yanQin aboutHero];
- [yanQin attack:@"高俅"];
-
-
- }
- return 0;
- }
复制代码 运行结果:- 2015-10-19 10:08:16.293 水浒卡登记[559:31588] 姓名:燕青,外号:浪子,排名:36,职务:步军统领兼谍报队长,武器:飞燕弩,大招:夺命扑
- 2015-10-19 10:08:16.293 水浒卡登记[559:31588] 燕青用夺命扑干掉了高俅
- Program ended with exit code: 0
复制代码
|
|