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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© meijinyu 中级黑马   /  2014-12-1 16:11  /  854 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
3.设计一个”学生“类
1> 属性
* 姓名
* 生日
* 年龄
* 身高(单位是m)
* 体重(单位是kg)
* 性别
* C语言成绩
* OC成绩
* iOS成绩

2> 行为
* 跑步:每跑步一次,身高增加1cm,体重减小0.5kg,输出跑完后的体重
* 吃饭:每吃一次,身高增加1cm,体重增加0.5kg,输出吃完后的体重
* 学习:每学习一次,3可成绩各加1分,输出学习完后的3科成绩
* 睡觉:输出所有的属性
* 比较C语言成绩:跟另外一个学生比较C语言成绩,返回成绩差(自己的成绩 - 其他人的成绩)
* 比较OC成绩:跟另外一个学生比较OC语言成绩,返回成绩差(自己的成绩 - 其他人的成绩)
* 比较iOS成绩:跟另外一个学生比较iOS语言成绩,返回成绩差(自己的成绩 - 其他人的成绩)
* 计算总分:算出3科成绩的总分
* 计算平均分:算出3科成绩的平均分
*/

#import <Foundation/Foundation.h>
// 颜色
typedef struct {
    int year;
    int month;
    int day;
} Date;

// 性别
typedef enum {
    SexMan,
    SexWoman,
    SexUnknow
} Sex;

@interface Student : NSObject
{
    @public
    char *name; // 姓名
    Date birthday; // 生日
    int age; // 年龄
    double height; // 身高
    double weight; // 体重
    Sex sex; // 性别
    int cScore; // C语言成绩
    int ocScore; // OC成绩
    int iosScore; // iOS成绩
}

- (void)run; // 跑
- (void)eat; // 吃
- (void)study; // 学习
- (void)sleep; // 睡觉
- (int)compareCScoreWithOther:(Student *)other; // 比较C成绩
- (int)compareOcScoreWithOther:(Student *)other; // 比较OC成绩
- (int)compareIosScoreWithOther:(Student *)other; // 比较iOS成绩
- (int)totalScore; // 总分
- (int)averageScore; // 平均分
@end

@implementation Student
- (void)run // 跑
{
    height += 0.01;
    weight -= 0.5;
    NSLog(@"学生跑完后的体重是%f公斤", weight);
}
- (void)eat // 吃
{
    height += 0.01;
    weight += 0.5;
    NSLog(@"学生吃完后的体重是%f公斤", weight);
}
- (void)study // 学习
{
    cScore += 1;
    ocScore += 1;
    iosScore += 1;
}
- (void)sleep // 睡觉
{
    NSLog(@"姓名=%s,身高=%f米,体重=%f公斤,生日=%d-%d-%d,年龄=%d岁,性别=%d,C成绩=%d,OC成绩=%d,iOS成绩=%d", name, height, weight, birthday.year, birthday.month, birthday.day, age, sex,
          cScore, ocScore, iosScore);
}
- (int)compareCScoreWithOther:(Student *)other // 比较C成绩
{
    return cScore - other->cScore;
}
- (int)compareOcScoreWithOther:(Student *)other // 比较OC成绩
{
    return ocScore - other->ocScore;
}
- (int)compareIosScoreWithOther:(Student *)other // 比较iOS成绩
{
    return iosScore - other->iosScore;
}
- (int)totalScore // 总分
{
    return cScore + ocScore + iosScore;
}
- (int)averageScore // 平均分
{
    return (cScore + ocScore + iosScore) / 3;
}
@end

请大神帮我看一下那里错了啊?在线等,谢谢!

下面是错我报告:
appledeMacBook-Pro:1201 apple$ cc 03.m -framework Foundation
03.m:67:17: warning: method definition for 'compareCScoreWith:' not found
      [-Wincomplete-implementation]
@implementation Student
                ^
03.m:59:1: note: method 'compareCScoreWith:' declared here
- (int)compareCScoreWith:(Student *)other;//和其他人比较C语言成绩,返回...
^
03.m:67:17: warning: method definition for 'compareOCScoreWith:' not found
      [-Wincomplete-implementation]
@implementation Student
                ^
03.m:60:1: note: method 'compareOCScoreWith:' declared here
- (int)compareOCScoreWith:(Student *)other;//比较OC成绩,返回差值
^
03.m:67:17: warning: method definition for 'compareIOSScoreWith:' not found
      [-Wincomplete-implementation]
@implementation Student
                ^
03.m:61:1: note: method 'compareIOSScoreWith:' declared here
- (int)compareIOSScoreWith:(Student *)other;//比较IOS成绩,返回差值
^
3 warnings generated.

2 个回复

倒序浏览
很明显的报错信息啊,就是没有找到比较C语言成绩的方法,你仔细看看是不是方法名写错来,声明和实现中的方法名必须一致,另外你的代码中怎么有表情的
回复 使用道具 举报
很明显的报错信息啊,就是没有找到比较C语言成绩的方法,你仔细看看是不是方法名写错或者没写冒号什么的,声明和实现中的方法名必须一致,另外你的代码中怎么有表情的
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马