美文网首页
【练习】成绩

【练习】成绩

作者: AmberAlbee | 来源:发表于2019-03-12 02:19 被阅读0次

    /*

    成绩类:

    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

    相关文章

      网友评论

          本文标题:【练习】成绩

          本文链接:https://www.haomeiwen.com/subject/scywpqtx.html