Score.h文件
//
// Score.h
// 练习 类 学生成绩管理
//
// Created by dllo on 15/11/27.
// Copyright © 2015年 dllo. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Score : NSObject
{
// 特征
NSString *_stuId;
CGFloat _englishScore;
CGFloat _historyScore;
CGFloat _mathScore;
CGFloat _averageScore;
CGFloat _totalScore;
}
// 行为
// 返回平均分
- (CGFloat)averageScore;
// 返回总分
- (CGFloat)totalScore;
// 自定义的初始化方法
- (id)initWithId:(NSString *)stuId
englishScore:(CGFloat)englisgScore
historyScore:(CGFloat)historyScore
mathScore:(CGFloat)mathScore;
// 对所有变量赋值的赋值语句
- (void)setStuId:(NSString *)stuId
englishScore:(CGFloat)englishScore
mathScore:(CGFloat)mathScore
historyScore:(CGFloat)historyScore;
// 设置器和访问器
// stuId
- (void)setStuId:(NSString *)stuId;
- (NSString *)stuId;
// englishScore
- (void)setEnglishScore:(CGFloat)englishScore;
- (CGFloat)englishScore;
// mathScore
- (void)setMathScore:(CGFloat)mathScore;
- (CGFloat)mathScore;
// historyScore
- (void)setHistoryScore:(CGFloat)historyScore;
- (CGFloat)historyScore;
@end
Score.m文件
//
// Score.m
// 练习 类 学生成绩管理
//
// Created by dllo on 15/11/27.
// Copyright © 2015年 dllo. All rights reserved.
//
#import "Score.h"
@implementation Score
// 返回平均分
- (CGFloat)averageScore{
_totalScore = _mathScore + _historyScore + _englishScore;
_averageScore = _totalScore / 3.0;
return _averageScore;
}
// 返回总分
- (CGFloat)totalScore{
_totalScore = _mathScore + _historyScore + _englishScore;
return _totalScore;
}
// 自定义的初始化方法
- (id)initWithId:(NSString *)stuId
englishScore:(CGFloat)englisgScore
historyScore:(CGFloat)historyScore
mathScore:(CGFloat)mathScore{
self = [super init];
if(self){
_stuId = stuId;
_englishScore = englisgScore;
_historyScore = historyScore;
_mathScore = mathScore;
}
return self;
}
// 设置器和访问器
// stuId
- (void)setStuId:(NSString *)stuId{
_stuId = stuId;
}
- (NSString *)stuId{
return _stuId;
}
// englishScore
- (void)setEnglishScore:(CGFloat)englishScore{
_englishScore = englishScore;
}
- (CGFloat)englishScore{
return _englishScore;
}
// mathScore
- (void)setMathScore:(CGFloat)mathScore{
_mathScore = mathScore;
}
- (CGFloat)mathScore{
return _mathScore;
}
// historyScore
- (void)setHistoryScore:(CGFloat)historyScore{
_historyScore = historyScore;
}
- (CGFloat)historyScore{
return _historyScore;
}
// 对所有变量赋值的赋值语句
- (void)setStuId:(NSString *)stuId
englishScore:(CGFloat)englishScore
mathScore:(CGFloat)mathScore
historyScore:(CGFloat)historyScore{
_stuId = stuId;
_englishScore = englishScore;
_mathScore = mathScore;
_historyScore = historyScore;
}
@end