欢迎来到天天文库
浏览记录
ID:35342089
大小:53.88 KB
页数:5页
时间:2019-03-23
《实现班级信息程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实现班级信息程序1>定义3个类:OurClass、Teacher^Student□2、Teacher类,属性:姓名、年龄、班级,方法:考试(exam:)。3、Student类,属性:姓名、年龄、学号、成绩,方法:比较年龄。4、OurClass类,属性:老师、学生,方法:添加学生和移除学生。提示:1、Person类作为Student>Teacher类的父类,公共属性和方法写在Person类中。2、Student的成绩为NSMutableDictionary类型,存储课程名称和成绩。3、Teacher的考试内部实现随机为班级每个学生的某一科赋值。4、OurClass的学生为NSMut
2、ableArray类型,内部存Student的对象。@classTeacher,Student;@interfaceOurClass:NSObject@property(nonatomic5retain)Teacher*tea;@property(nonatomic,retain)NSMutableArray*stuAry;-(void)addStu:(Student*)stu;-(void)removeStu:(Student*)stu;@end#importnOurClass.hn#import“Student.h”©implementationOurClass-(insta
3、ncetype)init{self=[superinit];if(self){self.stuAry=[NSMutableArrayarrayWithCapacity:O];}returnself;}-(void)addStu:(Student*)stu{[self.stuAryaddObject:stu];}-(void)removeStu:(Student*)stu{[self.stuAryremoveObject:stu];}-(NSString*)description{return[NSStringstringWithFormat:@n%@-%@n5_tea3_stuA
4、ry];}@end@interfacePerson:NSObject@property(nonatomic5copy)NSString*name;@property(nonatomic5assign)NSIntegerage;-(id)initWithName:(NSString*)nameage:(NSInteger)age;//+(id)personWithName:(NSString*)nameage:(NSInteger)age;@end#importTerson.hn©implementationPerson-(id)initWithName:(NSString*)na
5、meage:(NSInteger)age{self=[superinit];if(self){self.age=age;self.name=name;}returnself;}//+(id)personWithName:(NSString*)nameage:(NSInteger)age{////[[personalloc]initWithName:nameage:age]//}@end#importnPerson.hM@interfaceStudent:Person@property(nonatomic3assign)NSIntegernum;@property(nonatomi
6、c5retain)NSMutableDictionary*score;・(BOOL)compareByAgeWithStu:(Student*)stu;-(id)initWithName:(NSString*)nameage:(NSInteger)agenum:(NSInteger)num;@end©implementationStudent-(id)initWithName:(NSString*)nameage:(NSInteger)agenum:(NSInteger)num{self=[superinitWithName:nameage:age];if(self){self.
7、num=num;self.score=[NSMutableDictionarydictionaryWithCapacity:O];}returnself;}-(BOOL)compareByAgeWithStu:(Student*)stu{if(self.age>stu.age){returnYES;}else{returnNO;}}-(NSString*)description{return[NSStringstringWithFormat:@H%@-%ld-%ld-%@H5se
此文档下载收益归作者所有