【练习】成绩

2019-03-12  本文已影响0人  AmberAlbee

/*

成绩类:

C语言成绩(可读可写)

OC成绩(可读可写)

总分(只读)

平均分(只读)

*/

main.h

#import <Foundation/Foundation.h>

#import "Score.h"

int main(int argc, const char * argv[])

{

Score *c = [Score new];

[c setOcScore:90];

int b = [c ocScore];

NSLog(@"oc=%d",b);

[c setCScore:96];

int d = [c ocScore];

NSLog(@"c=%d",d);

int e = [c allScore];

NSLog(@"allScore=%d",e);

int f = [c aveScore];

NSLog(@"aveScore=%d",f);

return 0;

}


Score.h

#import <Foundation/Foundation.h>

@interface Score : NSObject

{

int _cScore;

int _ocScore;

int _allScore;

int _aveScore;

}

- (void)setCScore:(int)cScore;

- (int)cScore;

- (void)setOcScore:(int)ocScore;

- (int)ocScore;

- (int)allScore;

- (int)aveScore;

@end


Score.m

#import <Score.h>

@implementation Score

- (void)setCScore:(int)cScore

{

_cScore = cScore;

 _allScore = _cScore+_ocScore;

_aveScore = _allScore/2;

//

}

- (int)cScore

{

return _cScore;

}

- (void)setOcScore:(int)ocScore

{

_ocScore = ocScore;

}

- (int)ocScore

{

return _ocScore;

}

- (int)allScore

{

//  return _cScore+_ocScore;

//  不这样写,每调用一次方法就要完成一次加法

return _allScore;

}

- (int)aveScore

{

//  return (_cScore + _ocScore)/2;

return _aveScore;

//  return [self allScore]/2;

}

@end

上一篇下一篇

猜你喜欢

热点阅读