首先,创建一个工程,然后加入两个cocoaclass,分别命名为Student   和 StudentSystem.
   然后就可以开始写代码喽
     1.Student类--Student.h文件
```
 #import <Foundation/Foundation.h>
@interface Student : NSObject<NSCoding>
{
@protected
    int stuID;
    NSString * name;
    int age;
    int score;
}
@property int stuID;
@property NSString * name;
@property int age;
@property int score;
-(id)init;
-(void)inputStudent;
-(void)printStudent;
//-(void)modifyStudent;
@end
  
```
 2.Student类--Student.m文件
```
#import "Student.h"
int allgrades=0;
@implementation Student
//extern int allgrades;
@synthesize stuID,name,age,score;
-(id)init//构造函数
{
    if (self = [super init]) {
        stuID = 0;
        name = nil;
        age = 0;
        score = 0;
    }
    else
    {
        self = nil;
    }
    return self;
}
-(void)inputStudent
{
    NSLog(@"请依次输入学生的姓名,学号,年龄,成绩(格式:ganyu 10086 18 100)");
    char CharName[20];
    int intId;
    int intAge,intScore;
    scanf("%s %d %d %d",CharName,&intId,&intAge,&intScore);
    allgrades+=intScore;
    [self setName:[[NSString alloc]initWithUTF8String:CharName]];
    [self setStuID:intId];
    [self setAge:intAge];
    [self setScore:intScore];
}
-(void)printStudent
{
    NSLog(@"学号:%d,姓名:%@,年龄:%d,成绩: %d",self.stuID,self.name,self.age,self.score);
}
-(void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeInt:stuID forKey:@"id"];
    [aCoder encodeObject:name forKey:@"name"];
    [aCoder encodeInt:age forKey:@"age"];
    [aCoder encodeInt:score forKey:@"score"];
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        self.stuID = [aDecoder decodeIntForKey:@"id"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.age = [aDecoder decodeIntForKey:@"age"];
        self.score = [aDecoder decodeIntForKey:@"score"];
    }
    return self;
}
@end
```
3.StudentSystem类--StudentSystem.h 文件
```
#import <Foundation/Foundation.h>
#import "Student.h"
extern int allgrades;
@interface StudentSystem : NSObject
@property NSMutableArray *studentArray;
-(id)init;
-(void)printStudentArray;
-(void)addStudentArray:(Student *)stu;
-(void)findStudentByStuID;
-(void)removeStudentArrayByStuID;
-(void)writeToFile;
-(void)readFromFile;
-(void)countStudent;
-(void)SortStudentArray;// >0升序,<0降序
-(void)motifyStudent;
@end
```
4.StudentSystem类--StudentSystem.m文件
```
#import "StudentSystem.h"
extern int allgrades;
@implementation StudentSystem
@synthesize studentArray;
-(id)init
{
    if (self = [super init]) {
        studentArray = [[NSMutableArray alloc]init];
    }
    else
        self = nil;
    return self;
}
-(void)countStudent
{
    unsigned long int a=[self.studentArray count];
    NSLog(@"一共有%lu 位同学",a);
    double b=allgrades/a;
    NSLog(@"allgrades的值为:%d",allgrades);
    NSLog(@"大家的平均成绩是%lf",b);
}
-(void)printStudentArray
{
    for (Student *stu in studentArray) {
        [stu printStudent];
    }
    NSLog(@"array 打印完毕.");
}
-(void)addStudentArray:(Student *)stu
{
    [[self studentArray] addObject:stu];
    NSLog(@"添加完成");
}
-(void)findStudentByStuID
{
    NSLog(@"请输入你要查找的同学的学号:");
    int studentID;
    scanf("%d",&studentID);
    for (Student *stu in studentArray) {
        if (stu.stuID == studentID) {
            [stu printStudent];
            return ;
        }
    }
    NSLog(@"未找到学号为%d的学生.",studentID);
}
-(void)removeStudentArrayByStuID
{
    NSLog(@"请输入你要删除的同学的学号:");
    int studentID;
    scanf("%d",&studentID);
    for (Student *stu in studentArray) {
        if (stu.stuID == studentID) {
            [studentArray removeObject:stu];
            allgrades-=stu.score;
            NSLog(@"删除完成.");
            return ;
        }
    }
    NSLog(@"未找到学号为%d的学生.",studentID);
}
-(void)SortStudentArray// >0升序,<0降序
{
    NSLog(@"按照学号排序请输入 (id)");
    NSLog(@"按姓名排序请输入(name)");
    NSLog(@"按照年龄排序请输入(age)");
    NSLog(@"按照成绩排序请输入(score)");
    char charKey[10] ;
    scanf("%s",charKey);
    NSString *tempkey = [NSString stringWithUTF8String:charKey];
    NSString *key = [tempkey lowercaseString];
    BOOL ascending = NO;
if ([key isEqualToString:@"id"]) {
        NSSortDescriptor *sortByID = [NSSortDescriptor sortDescriptorWithKey:@"stuID" ascending:ascending];
        [studentArray sortUsingDescriptors:[NSArray arrayWithObject:sortByID]];
    }
    else if([key isEqualToString:@"name"])
    {
        NSSortDescriptor *sortByName= [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:ascending];
        [studentArray sortUsingDescriptors:[NSArray arrayWithObject:sortByName]];
    }
    else if([ key isEqualToString:@"age"])
    {
        NSSortDescriptor *sortByAge = [NSSortDescriptor sortDescriptorWithKey:@"age" ascending:ascending];
        [studentArray sortUsingDescriptors:[NSArray arrayWithObject:sortByAge]];
    }
    else if ([key isEqualToString:@"score"])
    {
        NSSortDescriptor *sortByScore = [NSSortDescriptor sortDescriptorWithKey:@"score" ascending:ascending];
        [studentArray sortUsingDescriptors:[NSArray arrayWithObject:sortByScore]];
    }
}
-(void)writeToFile
{
    NSString *path = [NSString stringWithFormat:@"/Users/len/Desktop"];
    NSLog(@"请输入你所要写入的文件名字:");
    char sfilename[20];
    scanf("%s",sfilename);
    NSString *filename = [NSString stringWithUTF8String:sfilename];
    NSString *filepath = [path stringByAppendingPathComponent:filename];
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:studentArray ];
    [data writeToFile:filepath atomically:YES];
}
-(void)readFromFile
{
    NSString *path = [NSString stringWithFormat:@"/Users/len/Desktop"];
    NSLog(@"请输入你所要读取的文件名字:");
    char sfilename[20];
    scanf("%s",sfilename);
    NSString *filename = [NSString stringWithUTF8String:sfilename];
    NSString *filepath = [path stringByAppendingPathComponent:filename];
    //NSMutableData *data = [[NSMutableData alloc]initWithContentsOfFile:filepath];
    NSMutableData *Data = [NSMutableData dataWithContentsOfFile:filepath];
    self.studentArray = [NSKeyedUnarchiver unarchiveObjectWithData:Data];
}
-(void)motifyStudent
{
    NSLog(@"请输入你要修改的同学的学号:");
    int studentID;
    scanf("%d",&studentID);
    for (Student *stu in studentArray) {
        if (stu.stuID == studentID) {
            NSLog(@"修改学号为%d的姓名,年龄,成绩(格式:ganyu 10086 18 100)",studentID);
            allgrades-=[stu score];
            char CharName[20];
            int intId;
            int intAge,intScore;
            scanf("%s %d %d %d",CharName,&intId,&intAge,&intScore);
            [stu setName:[[NSString alloc]initWithUTF8String:CharName]];
            [stu setStuID:intId];
            [stu setAge:intAge];
            [stu setScore:intScore];
            allgrades+=[stu score];
            return ;
        }
    }
    NSLog(@"未找到学号为%d的学生.",studentID);
}
@end
```
5.main文件
```
#import <Foundation/Foundation.h>
#import "Student.h"
#import "StudentSystem.h"
int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSLog(@"欢迎来到计科某班考试成绩管理系统");
        StudentSystem *class= [[StudentSystem alloc]init];
        while (YES) {
            NSLog(@"1:增加 2:打印");
            NSLog(@"3:删除 4:查找");
            NSLog(@"5:写入 6:读出");
            NSLog(@"7:统计 8:排序");
            NSLog(@"9:修改 0:退出");
            int c;
            scanf("%d",&c);
            switch (c) {
                case 1:
                {
                    Student *stuTemp = [[Student alloc]init];
                    [stuTemp inputStudent];
                    [class addStudentArray:stuTemp];
                    break;
                }
                case 2:
                    [class printStudentArray];
                    break;
                case 3:
                    [class removeStudentArrayByStuID];
                    break;
                case 4:
                    [class findStudentByStuID];
                    break;
                case 5:
                    [class writeToFile];
                    break;
                case 6:
                    [class readFromFile];
                    break;
                case 7:
                    [class countStudent];
                    break;
                case 8:
                    [class SortStudentArray];
                    NSLog(@"已排序");
                    break;
                case 9:
                    [class motifyStudent];
                    break;
                case 0:
                    return 0;
                default:
                    break;
            }
        }
    }
    return 0;
}
```
//关于上面还有一些功能没有实现,有兴趣的话可以尝试一下呦

oc实现小型学生管理系统的更多相关文章

  1. Java 小型学生管理系统心得

    这个学生管理系统相对来说比较简单,主要就是复习下java怎么连接数据库,然后你怎么来实现这个功能,我简单的说下思路吧. 首先你要构思好这个界面,他包括增删查改这些基本功能,然后你去分析这些功能都能怎么 ...

  2. 【IOS开发笔记02】学生管理系统

    端到端的机会 虽然现在身处大公司,但是因为是内部创业团队,产品.native.前端.服务器端全部坐在一起开发,大家很容易做零距离交流,也因为最近内部有一个前端要转岗过来,于是手里的前端任务好像可以抛一 ...

  3. 【IOS开发笔记01】学生管理系统(上)

    端到端的机会 虽然现在身处大公司,但是因为是内部创业团队,产品.native.前端.服务器端全部坐在一起开发,大家很容易做零距离交流,也因为最近内部有一个前端要转岗过来,于是手里的前端任务好像可以抛一 ...

  4. C程序范例(2)——学生管理系统”链表“实现

    1.对于学生管理系统,能够实现的方法有许多,但是今天我们用链表的方法来实现.虽然初学者很可能看不懂,但是不要紧,这是要在整体的系统的学习完C语言之后,我才编写出的程序.所以大家不必要担心.在这里与大家 ...

  5. jsp学习之基于mvc学生管理系统的编写

    mvc开发模式:分别是 model层 view层 Control层 在学生管理系统中,model层有学生实体类,数据访问的dao层,view层主要是用于显示信息的界面,Control层主要是servl ...

  6. java版本的学生管理系统

    import java.awt.BorderLayout; import java.awt.Color; import java.awt.Frame; import java.awt.event.Ac ...

  7. 学生管理系统-火车订票系统 c语言课程设计

    概要: C 语言课程设计一---学生管理系统 使使用 C 语言实现学生管理系统.系统实现对学生的基本信息和考试成绩的 管理.采用终端命令界面,作为系统的输入输出界面.采用文件作为信息存储介质. 功能描 ...

  8. Java学生管理系统项目案例

    这是一个不错的Java学生管理系统项目案例,希望能够帮到大家的学习吧. 分代码如下 package com.student.util; import java.sql.Connection; impo ...

  9. Java+Mysql+学生管理系统

    最近正在学java和数据库,想起以前写的学生管理系统,都是从网上下载,敷衍了事.闲来无事,也就自己写了一个,不过功能实现的不是很多. 开发语言:java: 开发环境:Mysql, java: 开发工具 ...

随机推荐

  1. css未知高度垂直居中

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  2. 🙀Java 又双叒叕发布新版本,这么多版本如何灵活管理?

    文章来源:http://1t.click/bjAG 前言 不知不觉 JDK13 发布已有两个月,不知道各位有没有下载学习体验一番?每次下载安装之后,需要重新配置一下 Java 环境变量.等到运行平时的 ...

  3. 【集合系列】- 深入浅出的分析 WeakHashMap

    一.摘要 在集合系列的第一章,咱们了解到,Map 的实现类有 HashMap.LinkedHashMap.TreeMap.IdentityHashMap.WeakHashMap.Hashtable.P ...

  4. MySQL锁会不会,你就差看一看

    数据库锁知识 不少人在开发的时候,应该很少会注意到这些锁的问题,也很少会给程序加锁(除了库存这些对数量准确性要求极高的情况下),即使我们不会这些锁知识,我们的程序在一般情况下还是可以跑得好好的.因为这 ...

  5. PHP中Redis扩展无法加载问题

    问题: 在重启php-fpm的过程中,发生了如下的错误,redis.so无法载入 1 2 3 4 [root@brand009 modules]# /usr/sbin/php-fpm /usr/sbi ...

  6. vuejs之路由应用之一

    什么是‘路由’,路由相当于一个映射,一个url地址对应一个组件,当url地址A变为url地址B,那么对应地址A的组件就会改变为对应地址B的组件.应用于spa,即:单页应用,url地址改变,它不会跳转页 ...

  7. Springboot操作Elasticsearch

    常见的日志系统是基于logstach+elasticsearch+kibna框架搭建的,但是有时候kibana的查询无法满足我们的要求,因此有时需要代码去操作es,本文后续都以es代替elastics ...

  8. python的time、datetime和calendar

    datetime模块主要是用来表示日期的,就是我们常说的年月日时分秒,calendar模块主要是用来表示年月日,是星期几之类的信息,time模块主要侧重点在时分秒,从功能简单来看,我们可以认为三者是一 ...

  9. 小白学 Python 爬虫(9):爬虫基础

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...

  10. oracle查询练习

    1成绩表score如下,查询出每门课都大于80分的学生姓名 准备数据 -建表- SQL> create table score(   2  name varchar(50),   3  kech ...