您的位置:首页 > 其它

OC学生成绩管理类(三 Student学生类)

2015-11-30 21:01 375 查看
Student.h文件

//
//  Student.h
//  练习 类 学生成绩管理
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Score.h"
@interface Student : NSObject
{
// 特征
NSString *_stuName;
NSString *_stuId;
NSString *_stuSex;
Score *_score;
}

// 自定义的初始化方法
- (id)initWithName:(NSString *)stuName
stuId:(NSString *)stuId
sex:(NSString *)sex
mathSocre:(CGFloat)mathScore
historyScore:(CGFloat)historyScore
englishScore:(CGFloat)englishScore;
// 自定义的初始化方法2
- (id)initWithName:(NSString *)stuName
stuId:(NSString *)stuId
sex:(NSString *)sex
score:(Score *)score;
// 输出当前学生的所有信息
- (void)printInfo;

// 设置器和访问器
// name
- (void)setName:(NSString *)name;
- (NSString *)name;
// stuId
- (void)setStuId:(NSString *)stuId;
- (NSString *)stuId;
// sex
- (void)setSex:(NSString *)sex;
- (NSString *)sex;
// score
- (void)setScore:(Score *)score;
- (Score *)score;
@end


Student.m文件

//
//  Student.m
//  练习 类 学生成绩管理
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "Student.h"

@implementation Student
// 自定义初始化方法
- (id)initWithName:(NSString *)stuName
stuId:(NSString *)stuId
sex:(NSString *)sex
mathSocre:(CGFloat)mathScore
historyScore:(CGFloat)historyScore
englishScore:(CGFloat)englishScore{

self = [super init];
if(self){
_stuName = stuName;
_stuId = stuId;
_stuSex = sex;
// 创建Score类的对象
Score *score = [[Score alloc] initWithId:stuId englishScore:englishScore historyScore:historyScore mathScore:mathScore];
_score = score;
}
return self;
}

- (id)initWithName:(NSString *)stuName
stuId:(NSString *)stuId
sex:(NSString *)sex
score:(Score *)score{
self = [super init];
if(self){
_stuName = stuName;
_stuId = stuId;
_stuSex = sex;
_score = score;
}
return self;
}
// 设置器和访问器
// name
- (void)setName:(NSString *)name{
_stuName = name;
}
- (NSString *)name{
return _stuName;
}
// stuId
- (void)setStuId:(NSString *)stuId{
_stuId = stuId;
}
- (NSString *)stuId{
return _stuId;
}
// sex
- (void)setSex:(NSString *)sex{
_stuSex = sex;
}
- (NSString *)sex{
return _stuSex;
}
// score
- (void)setScore:(Score *)score{
_score = score;
}
- (Score *)score{
return _score;
}

// 输出当前学生的所有信息
- (void)printInfo{
NSLog(@" %@ %@ %@ Math:%0.2f History:%0.2f English:%0.2f Ave:%0.2f Total:%0.2f",
_stuName,
_stuId,
_stuSex,
[_score mathScore],
[_score historyScore],
[_score englishScore],
[_score averageScore],
[_score totalScore]);

}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: