#import <Foundation/Foundation.h>
@interface Score : NSObject
{
int _c;
int _oc;
int _total;//知道哪些成员变量是可读可写,总分平均是可读不可写 只有get。
int _average;
}
- (void)setC:(int)c;
- (void)setOc:(int)oc;
- (int)total;
- (int)average;
- (int)oc;
- (int)c;
@end
@implementation Score
- (void)setC:(int)c
{
_c = c;
_total = _c + _oc;
_average = _total/2;
}
- (void)setOc:(int)oc
{
_oc = oc;
_total = _c + _oc;
_average = _total/2;
}
- (int)oc
{
return _oc;
}
- (int)c
{
return _c;
}
- (int)total
{
return _total;
}
- (int)average
{
return _average;
}
@end
int main()
{
Score *s = [Score new];
[s setC:54];
[s setOc:30];
[s total];
[s average];
NSLog(@"c语言的分数是%d",[s c]);
NSLog(@"c语言的分数是%d",[s oc]);
NSLog(@"总分数是%d",[s total]);
NSLog(@"平均分数是%d",[s average]);
return 0;
}
|
|