A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 子文 初级黑马   /  2014-7-2 23:41  /  805 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


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














4 个回复

倒序浏览
不能发到代码里面吗?这样看的好蛋疼啊!
回复 使用道具 举报
把代码搞到代码框里面去
回复 使用道具 举报
楼主要干什么》、?
回复 使用道具 举报
怎么这么多:(
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马