您的位置:首页 > 其它

OC学生成绩管理类(一 综述)

2015-11-30 20:34 531 查看
        刚学习了OC两天,用面向对象的思想编写了一个学生成绩管理类来复习总结一下.文件一共有三个类,分别是Classroom教室类,Student学生类和Score分数类.下面详细介绍每一个类.因为当时没有学到属性,所以使用的是成员变量

 Classroom教室类

       保存每个学生的信息,教室的名称,教师姓名等基本信息.

      具有添加学生,按分数排名输出学生信息,输出有不及格成绩的学生信息,输出低于平均分的学生信息,显示班级平均分的方法;

 Student学生类

      保存一个学生的姓名,性别,学号和分数

      有输出当前学生的信息的方法.

Score分数

      保存各科成绩

      具有设置和返回成绩的方法.

下面是main函数,接下来的三个博客会有其他三个类的源代码.

//
// main.m
// 练习 类 学生成绩管理
//
// Created by dllo on 15/11/27.
// Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Student.h"
#import "Classroom.h"
int main(int argc, const char * argv[]) {
// 声明七个学生对象
Student *stu1 = [[Student alloc] initWithName:@"张三" stuId:@"0001" sex:@"男" mathSocre:60 historyScore:50 englishScore:65];
Student *stu2 = [[Student alloc] initWithName:@"李四" stuId:@"0002" sex:@"男" mathSocre:89 historyScore:70 englishScore:65];
Student *stu3 = [[Student alloc] initWithName:@"王五" stuId:@"0003" sex:@"女" mathSocre:89 historyScore:80 englishScore:85];
Student *stu4 = [[Student alloc] initWithName:@"田六" stuId:@"0004" sex:@"女" mathSocre:89 historyScore:70 englishScore:75];
Student *stu5 = [[Student alloc] initWithName:@"年七" stuId:@"0005" sex:@"男" mathSocre:80 historyScore:60 englishScore:65];
Student *stu6 = [[Student alloc] initWithName:@"沙八" stuId:@"0006" sex:@"女" mathSocre:60 historyScore:65 englishScore:65];
Student *stu7 = [[Student alloc] initWithName:@"失九" stuId:@"0007" sex:@"男" mathSocre:50 historyScore:60 englishScore:65];

// 声明一个教室对象
Classroom *classroom = [[Classroom alloc] initWithName:@"一班"];
// 将学生对象添加到教室对象中
[classroom addStudent:stu1];
[classroom addStudent:stu2];
[classroom addStudent:stu3];
[classroom addStudent:stu4];
[classroom addStudent:stu5];
[classroom addStudent:stu6];
[classroom addStudent:stu7];
// 按学号输出所有的学生信息
[classroom printAllStudentInfo];
// 按分数降序输出所有信息
[classroom printAllStudentInfoByDescending];
// 输出有没及格的课的学生信息
[classroom printFailStudent];
// 按学号输出所有的学生信息
[classroom printAllStudentInfo];
// 输出成绩在班级平均分以下的同学
[classroom printStudentScoreUnderAverage];
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: