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;
}
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;
}
相关文章推荐
- RTP-RTCP协议分析
- 基于AFNetworking的网络判断【转载】
- 通过OLE搭建开发环境
- 安卓网络通信框架Volley学习(二)基于Volley高效加载网络图片
- 小白菜系列之多线程(1)——创建线程
- 量化投资环境搭建
- 多线程问题
- IIS内存泄漏
- Windows下使用DOS命令进入MySQL数据库
- 【NDK开发】NDK开发实例1-hellojni
- 欢迎使用CSDN-markdown编辑器
- 将264万次数据的比较运算,运行时间从2.5小时降低到3分钟(R实现)
- BZOJ4140 : 共点圆加强版
- 1035. Password (20)
- UITableView
- 【Java EE (Struts2 + Spring + Hibernate)开发】:Struts2(二)之【控制文件上传和下载】
- C语言根据路径打开文件内容
- win32api大全
- C library function - tmpfile()
- NYOJ 108士兵杀敌(一)