黑马程序员技术交流社区

标题: 代码1 [打印本页]

作者: 子文    时间: 2014-7-2 23:42
标题: 代码1

#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;
}



















欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2