本帖最后由 77媛儿 于 2014-3-24 13:52 编辑
- //分数类
- #import <Foundation/Foundation.h>
- @interface Scord:NSObject
- {
- @public
- int cScord;
- int ocScord;
- int iosScord;
- }
- - (int)compare_cScordWithother:(Scord *)other;
- - (int)compare_ocScordWithother:(Scord *)other;
- - (int)compare_iosScordWithother:(Scord *)other;
- - (int)sumAll;
- - (int)average;
- @end
- @implementation Scord
- - (int)compare_cScordWithother:(Scord *)other
- {
- return cScord-other->cScord;
- }
- - (int)compare_ocScordWithother:(Scord *)other
- {
- return ocScord-other->ocScord;
- }
- - (int)compare_iosScordWithother:(Scord *)other
- {
- return iosScord-other->iosScord;
- }
- - (int)sumAll
- {
- return cScord+ocScord+iosScord;
- }
- - (int)average
- {
- return (cScord+ocScord+iosScord)/3;
- }
- @end
- //学生类
- @interface Student:NSObject
- {
- @public
- char *name;
- int number;
- Scord *s;
- }
- - (int)compare_cScordWithother:(Student *)other;
- @end
- @implementation Student
- - (int)compare_cScordWithother:(Student *)other
- {
- return [s compare_iosScordWithother:other->s];
- }
- @end
- int main()
- {
-
- Student *a=[Student new];
- Scord *s1=[Scord new];
- a->name="jack";
- a->number=22;
- a->s=s1;
- s1->cScord=90;
- Student *a1=[Student new];
- Scord *s2=[Scord new];
- a1->name="rose";
- a1->number=23;
- a1->s=s2;
- s2->cScord=92;
- int b=[a compare_cScordWithother:a1];
- NSLog(@"%d",b);
- }
- 输出结果不正确,求帮助
复制代码
|