本帖最后由 S970028126 于 2015-6-24 20:59 编辑
属性: c语言成绩(可读可写)
oc成绩(可读可写)
总分(只读)
平均分(只读)
# import <Foundation/Foundation.h>
@interface Score : NSObject
{
int _cScore; //c语言成绩
int _ocScore; // oc语言成绩
int _totalScore;// 总分
int _averageScore; //平均分
}
- (void)setCScore : (int)cScore;
- (int)cScore;
- (void)setOcScore : (int)ocScore;
- (int)ocScore;
- (int)totalScore;
- (int)averageScore;
@end
@implementation Student
- (void)setCScore : (int)cScore
{
_cScore = cScore;
_totalScore = _cScore + _ocScore;
_averageScore = _totalScore/2;
}
- (int)cScore
{
return _cScore;
}
- (void)setOcScore : (int)ocScore
{
_ocScore = ocScore;
_totalScore = _cScore + _ocScore;
_averageScore = _totalScore/2;
}
- (int)ocScore
{
return _ocScore;
}
- (int)totalScore
{
return _totalScore;
}
- (int)averageScore
{
return _averageScore;
}
@end |
|