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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© king、小白 中级黑马   /  2016-5-7 14:11  /  815 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

Student.h
#import<Foundation/Foundation.h>
@interface Student:NSObject
/*@property(nonatomic,copy)NSString *name;
@property(nonatomic,assign)int age;
@property(nonatomic,assign)int score;*/
{
NSString *_name;
int _age;
int _score;
}
-(void)setName:(NSString *)name;
-(NSString *)NSString *name;

-(void)setAge:(int)age;
-(int)intage;

-(void)setScore:(int)score;
-(int)intscore;

-(id)initWithName:(NSString *)name andAge:(int)age andScore:(int)score;

-(void)printinfo;
@end
Student.m
#import"Student.h"
@implementation Student
-(void)setName:(NSString *)name
{
if(_name != name){
[_name release];
_name=[name retain];
}
}
-(NSString *)NSString *name
{
return _name;
}

-(void)setAge:(int)age
{
_age=age;
}
-(int)intage{
return _age;
}

-(void)setScore:(int)score{
_score=score;
}
-(int)intscore
{
return _score;
}

-(id)initWithName:(NSString *)name andAge:(int)age andScore:(int)score
{
if(self = [super init]){
_name =name;
_age = age;
_score = score;
}
return self;
}

-(void)printinfo{
NSLog(@"My Name Is %@ Age Is %d Score Is %d",self.name,self.age,self.score);
}
-(NSString *)description
{
return[NSString stringWithFormat:@"xingming=%@,nianling=%d,chengji=%d",_name,_age,_score];
}
-(void)dealloc
{
[_name release];
[super dealloc];
NSLog(@"%@",__func__);
}

mian.m
#import<Foundation/Foundation.h>
#import"Student.h"
int main(){
Student *stu1=[[Student alloc]initWithName:@"s1" andAge:11 andScore:87];
Student *stu2=[[Student alloc]initWithName:@"s2" andAge:22 andScore:97];
Student *stu3=[[Student alloc]initWithName:@"s3" andAge:33 andScore:100];
[stu1 printinfo];
[stu2 printinfo];
[stu3 printinfo];



[stu1 release];
[stu2 release];
[stu3 release];
return 0;
}

0 个回复

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