使用C语言+Visual Studio2022制作一个(控制台应用)校园管理系统-附源码

137 阅读21分钟

学生管理系统C语言的控制台应用

源码地址和笔记已经放在 gitee gitee.com/yang-zhenmi…

开发编辑器

官网链接visualstudio.microsoft.com/zh-hans/

image-20240610175918034.png

后面的安装可能会有几十个G的空间 需要进行预留 安装的时候会有提示

安装之后打开

image-20240610180100351.png

该页面主题是插件实现的

image-20240610180131629.png

image-20240610180155181.png

image-20240610180203988.png

关闭后软件 会自动安装 等待安装完成后 重新打开 就OK了

开始编程

创建

image-20240610180326590.png

image-20240610180426174.png

基础main

    #include<stdio.h>
    ​
    ​
    //程序的主入口文件
    int main()
    {
        printf("hello world");
        return 0;
    }
    ​

各项功能

1.菜单展示

image-20240610185044690.png

主入口文件stidentManageSystem.cpp

    #include<stdio.h>
    #include"studentSysMenu.h"//引入studentSysMenu 的showMenu声明//程序的主入口文件
    int main()
    {
        //printf("hello world");
        //菜单选择
        showMenu();
    ​
        return 0;
    }

头文件studentSysMenu.h

    #pragma once
    //函数菜单定义
    void showMenu();

具体功能实现studentSysMenu.cpp

    //这是展示菜单的功能
    #include<stdio.h>
    ​
    ​
    //函数 具体实现
    void showMenu() {
        //显示可操作的菜单
        int selectValue = 0;
        do {
            printf("\n-----------------------------\n");
            printf("\n--  欢迎使用学生管理系统   --\n");
            printf("\n-----------------------------\n");
            printf("\n|1.学生管理                --\n");
            printf("\n|2.班级管理                --\n");
            printf("\n|3.老师管理                --\n");
            printf("\n|4.书本管理                --\n");
            printf("\n|5.部门管理                --\n");
            printf("\n|6.退出管理***             --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
            
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****学生管理****   --\n");
    ​
    ​
                break;
            case 2:
                printf("\n|  ****班级管理****   --\n");
                break;
            case 3:
                printf("\n|  ****老师管理****   --\n");
                break;
            case 4:
                printf("\n|  ****书本管理****   --\n");
                break;
            case 5:
                printf("\n|  ****部门管理****   --\n");
                break;
            case 6:
                printf("\n|  ****正在退出....   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 6);
    ​
        printf("\n-----------------------------\n");
        printf("\n|感谢您的使用^_^           --\n");
        printf("\n-----------------------------\n");
    }

测试结果

image-20240610185503869.png

2.学生管理

需要一个学生的管理

当从主页面进入学生管理后那么 需要展示学生的信息菜单

总体代码

image-20240611224339462.png

studentObj.cpp 学生管理的功能实现

    //这里是学生管理的实现//菜单展示
    #include <stdio.h>
    #include <string.h>
    //定义学生的结构体
    typedef struct 
    {
        char name[20];
        int age;
        int sex;
        char classname[50];
        char address[100];
    }Student;
    ​
    //定义一个全局的学生列表
    //每个班级50人
    Student studentList[50] = {};
    //记录当前班级人数
    int currentStuCount = 0;
    ​
    //添加学生
    void addStudent(Student *pstulist) {
        char answer = 'Y';
        do {
            printf("\n|请输入学生的信息 姓名 年龄 性别(1男0女) 班级 家庭住址     --\n");
            Student s;
            scanf("%s %d %d %s %s",&s.name,&s.age,&s.sex,&s.classname,&s.address);
            //把数据推送到studentList
            pstulist[currentStuCount] = s;
            currentStuCount++;
            printf("\n|是否继续天加学生Y/N     --\n");
            //getchar();//吸收回车
            //printf("answer%c\n", answer);
            getchar();//吸收回车
            scanf("%c", &answer);
            printf("answer%c", answer);
        } while (answer=='Y'|| answer == 'y');
        return;
    }
    //查看学生void showStudentMes(Student* pstulist) {
        char answer = 'Y';
        do {
            printf("\n|学生信息如下:     --\n");
            printf("\n姓名 | 年龄 | 性别 | 班级 | 家庭住址 |\n");
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
            }
            printf("\n|------完成------ --\n");
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    //修改学生
    void changeStudentMes(Student* pstulist) {
        char answer = 'Y';
        do {
            printf("\n|学生信息如下:     --\n");
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要修改的学生名字     --\n");
            char name[40];
            scanf("%s", name);
            printf("\n|请输入要修改内容姓名 年龄 性别(1男0女) 班级 家庭住址       --\n");
            getchar();//吸收回车
            Student s;
            scanf("%s %d %d %s %s", &s.name, &s.age, &s.sex, &s.classname, &s.address);
            printf("%s %d %d %s %s", s.name, s.age, s.sex, s.classname, s.address);
    ​
            //替换
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n|名字%s    --\n", pstulist[i].name);
                if (strcmp(pstulist[i].name,name)==0  ) {
                    printf("\n|马上修改%s     --\n", pstulist[i].name);
                    pstulist[i] = s;
                    printf("\n|修改完成     --\n");
                    printf("%s %d %d %s %s", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
                    break;
                }
                
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'N');
        return;
    }
    ​
    //删除学生
    void romoveStudentMes(Student* pstulist) {
        char answer = 'Y';
        do {
            printf("\n|学生信息如下:     --\n");
            printf("\n姓名 | 年龄 | 性别 | 班级 | 家庭住址 |\n");
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要删除的学生名字     --\n");
            char name[40];
            scanf("%s", name);
            
            //替换
            for (int i = 0; i < currentStuCount; i++)
            {
    ​
                if (strcmp(pstulist[i].name, name) == 0) {
                    printf("\n相等名字%s总长度%d\n", name, currentStuCount);
                    int j;
                    for (j = i; j < currentStuCount-1; j++)
                    {
                        //如果是最后一个 不需要交换了
                        if (i == (currentStuCount - 1))
                        {
                            printf("\n删除最后一个\n");
                            pstulist[j] = {0,0,0,0,0};
                            break;
                        }
                        pstulist[j] = pstulist[j+1];
                        //因为是数组 需要位移
                        printf("\n%d前移\n", j+1);
                    }
                    pstulist[j] = { 0,0,0,0,0};
                    currentStuCount--;
                    printf("\n|删除完成     --\n");
                    break;
                }
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    ​
    ​
    void showStudentMenu() {
        int selectValue = 0;
        do{
            printf("\n---------------------------------\n");
            printf("\n--          学生管理           --\n");
            printf("\n---------------------------------\n");
            printf("\n|1.添加学生                --\n");
            printf("\n|2.查看学生                --\n");
            printf("\n|3.修改学生                --\n");
            printf("\n|4.删除学生                --\n");
            printf("\n|5.返回                    --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
    ​
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****添加学生****   --\n");
                addStudent(studentList);
    ​
                break;
            case 2:
                printf("\n|  ****查看学生****   --\n");
                showStudentMes(studentList);
                break;
            case 3:
                printf("\n|  ****修改学生****   --\n");
                changeStudentMes(studentList);
                break;
            case 4:
                printf("\n|  ****删除学生****   --\n");
                romoveStudentMes(studentList);
                break;
            case 5:
                printf("\n|  ****返回****   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 5);
    }
    ​
    ​
    void studenMain() {
        showStudentMenu();
    ​
    }
    ​
    ​

studentObj.h 学生的头文件

    #pragma once
    typedef struct
    {
        char name[20];
        int age;
        int sex;
        char classname[50];
        char address[100];
    }Student;
    ​
    void addStudent(Student* pstulist);
    void showStudentMes(Student* pstulist);
    void changeStudentMes(Student* pstulist);
    void romoveStudentMes(Student* pstulist);
    void showStudentMenu();
    void studenMain();

studentSysMenu.cpp 引入头文件使用功能

    //这是展示菜单的功能
    #include<stdio.h>
    #include"studentObj.h"
    #include"classnameObj.h"
    ​
    ​
    ​
    //函数 具体实现
    void showMenu() {
        //显示可操作的菜单
        int selectValue = 0;
        do {
            printf("\n--------------------------------------\n");
            printf("\n--       欢迎使用学生管理系统       --\n");
            printf("\n--------------------------------------\n");
            printf("\n|1.学生管理                --\n");
            printf("\n|2.班级管理                --\n");
            printf("\n|3.老师管理                --\n");
            printf("\n|4.书本管理                --\n");
            printf("\n|5.部门管理                --\n");
            printf("\n|6.退出管理***             --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
            
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****学生管理****   --\n");
                studenMain();
                break;
            case 2:
                printf("\n|  ****班级管理****   --\n");
                classnameMain();
                break;
            case 3:
                printf("\n|  ****老师管理****   --\n");
                break;
            case 4:
                printf("\n|  ****书本管理****   --\n");
                break;
            case 5:
                printf("\n|  ****部门管理****   --\n");
                break;
            case 6:
                printf("\n|  ****正在退出....   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 6);
    ​
        printf("\n-----------------------------\n");
        printf("\n|感谢您的使用^_^           --\n");
        printf("\n-----------------------------\n");
    }
    ​
    ​

stidentManageSystem.cpp入口文件

    #include<stdio.h>
    #include"studentSysMenu.h"//程序的主入口文件
    int main()
    {
        //printf("hello world");
        //菜单选择
        showMenu();
    ​
        return 0;
    }
    ​

学生菜单业务

    void showStudentMenu() {
        int selectValue = 0;
        do{
            printf("\n---------------------------------\n");
            printf("\n--          学生管理           --\n");
            printf("\n---------------------------------\n");
            printf("\n|1.添加学生                --\n");
            printf("\n|2.查看学生                --\n");
            printf("\n|3.修改学生                --\n");
            printf("\n|4.删除学生                --\n");
            printf("\n|5.返回                    --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
    ​
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****添加学生****   --\n");
                addStudent(studentList);
    ​
                break;
            case 2:
                printf("\n|  ****查看学生****   --\n");
                showStudentMes(studentList);
                break;
            case 3:
                printf("\n|  ****修改学生****   --\n");
                changeStudentMes(studentList);
                break;
            case 4:
                printf("\n|  ****删除学生****   --\n");
                romoveStudentMes(studentList);
                break;
            case 5:
                printf("\n|  ****返回****   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 5);
    }
    ​

创建一个对外暴露的函数调用studenMain

    void studenMain() {
        showStudentMenu();
    ​
    }

定义结构体

    //定义学生的结构体
    typedef struct 
    {
        char name[20];
        int age;
        int sex;
        char classname[50];
        char address[100];
    }Student;
    ​
    //定义一个全局的学生列表
    //每个班级50人
    Student studentList[50] = {};
    //记录当前班级人数
    int currentStuCount = 0;

添加学生

    //添加学生
    void addStudent(Student *pstulist) {
        char answer = 'Y';
        do {
            printf("\n|请输入学生的信息 姓名 年龄 性别(1男0女) 班级 家庭住址     --\n");
            Student s;
            scanf("%s %d %d %s %s",&s.name,&s.age,&s.sex,&s.classname,&s.address);
            //把数据推送到studentList
            pstulist[currentStuCount] = s;
            currentStuCount++;
            printf("\n|是否继续天加学生Y/N     --\n");
            //getchar();//吸收回车
            //printf("answer%c\n", answer);
            getchar();//吸收回车
            scanf("%c", &answer);
            printf("answer%c", answer);
        } while (answer=='Y'|| answer == 'y');
        return;
    }

查看学生

    //查看学生void showStudentMes(Student* pstulist) {
        char answer = 'Y';
        do {
            printf("\n|学生信息如下:     --\n");
            printf("\n姓名 | 年龄 | 性别 | 班级 | 家庭住址 |\n");
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
            }
            printf("\n|------完成------ --\n");
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }

修改学生

    //修改学生
    void changeStudentMes(Student* pstulist) {
        char answer = 'Y';
        do {
            printf("\n|学生信息如下:     --\n");
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要修改的学生名字     --\n");
            char name[40];
            scanf("%s", name);
            printf("\n|请输入要修改内容姓名 年龄 性别(1男0女) 班级 家庭住址       --\n");
            getchar();//吸收回车
            Student s;
            scanf("%s %d %d %s %s", &s.name, &s.age, &s.sex, &s.classname, &s.address);
            printf("%s %d %d %s %s", s.name, s.age, s.sex, s.classname, s.address);
    ​
            //替换
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n|名字%s    --\n", pstulist[i].name);
                if (strcmp(pstulist[i].name,name)==0  ) {
                    printf("\n|马上修改%s     --\n", pstulist[i].name);
                    pstulist[i] = s;
                    printf("\n|修改完成     --\n");
                    printf("%s %d %d %s %s", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
                    break;
                }
                
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'N');
        return;
    }

删除学生

    //删除学生
    void romoveStudentMes(Student* pstulist) {
        char answer = 'Y';
        do {
            printf("\n|学生信息如下:     --\n");
            printf("\n姓名 | 年龄 | 性别 | 班级 | 家庭住址 |\n");
            for (int i = 0; i < currentStuCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pstulist[i].name, pstulist[i].age, pstulist[i].sex, pstulist[i].classname, pstulist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要删除的学生名字     --\n");
            char name[40];
            scanf("%s", name);
            
            //替换
            for (int i = 0; i < currentStuCount; i++)
            {
    ​
                if (strcmp(pstulist[i].name, name) == 0) {
                    printf("\n相等名字%s总长度%d\n", name, currentStuCount);
                    int j;
                    for (j = i; j < currentStuCount-1; j++)
                    {
                        //如果是最后一个 不需要交换了
                        if (i == (currentStuCount - 1))
                        {
                            printf("\n删除最后一个\n");
                            pstulist[j] = {0,0,0,0,0};
                            break;
                        }
                        pstulist[j] = pstulist[j+1];
                        //因为是数组 需要位移
                        printf("\n%d前移\n", j+1);
                    }
                    pstulist[j] = { 0,0,0,0,0};
                    currentStuCount--;
                    printf("\n|删除完成     --\n");
                    break;
                }
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }

3班级管理

classnameObj.cpp

    //班级的管理业务
    //这里是学生管理的实现//菜单展示
    #include <stdio.h>
    #include <string.h>
    //定义学生的结构体
    typedef struct
    {
        char name[20];//班级名字
        int count;//班级人数
        char classTeacher[20];//班主任
        char classSay[50];//班级宣言
        char address[100];//班级地址
    }ClassName;
    ​
    //定义一个全局的学生列表
    //每个班级50人
    ClassName classnameList[50] = {};
    //记录当前班级人数
    int currentClassCount = 0;
    ​
    //添加学生
    void addClass(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|请输入班级的信息 名称 人数 班主任 宣言 班级地址     --\n");
            ClassName s;
            scanf("%s %d %s %s %s", &s.name, &s.count, &s.classTeacher, &s.classSay, &s.address);
            //把数据推送到studentList
            pClassNameList[currentClassCount] = s;
            currentClassCount++;
            printf("\n|是否继续添加班级Y/N     --\n");
            //getchar();//吸收回车
            //printf("answer%c\n", answer);
            getchar();//吸收回车
            scanf("%c", &answer);
            printf("answer%c", answer);
        } while (answer == 'Y' || answer == 'y');
        return;
    }
    //查看学生void showClassMes(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|班级信息如下:     --\n");
            printf("\n|名称 | 人数 | 班主任 | 宣言 | 班级地址 |\n");
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n%s | %d | %s | %s | %s |\n", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
            }
            printf("\n|------完成------ --\n");
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    //修改学生
    void changeClassMes(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|班级信息如下:     --\n");
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n%s | %d | %s | %s | %s |\n", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要修改的班级名字     --\n");
            char name[40];
            scanf("%s", name);
            printf("\n|请输入要修改内容名称: 人数 班主任 宣言 班级地址       --\n");
            getchar();//吸收回车
            ClassName s;
            scanf("%s %d %s %s %s", &s.name, &s.count, &s.classTeacher, &s.classSay, &s.address);
            printf("%s %d %s %s %s", s.name, s.count, s.classTeacher, s.classSay, s.address);
    ​
            //替换
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n|名字%s    --\n", pClassNameList[i].name);
                if (strcmp(pClassNameList[i].name, name) == 0) {
                    printf("\n|马上修改%s     --\n", pClassNameList[i].name);
                    pClassNameList[i] = s;
                    printf("\n|修改完成     --\n");
                    printf("%s %d %s %s %s", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
                    break;
                }
    ​
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'N');
        return;
    }
    ​
    //删除学生
    void romoveStudentMes(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|班级信息如下:     --\n");
            printf("\n|名称 | 人数 | 班主任 | 宣言 | 班级地址 |\n");
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n%s | %d | %s | %s | %s |\n", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要删除的班级名字     --\n");
            char name[40];
            scanf("%s", name);
    ​
            //替换
            for (int i = 0; i < currentClassCount; i++)
            {
    ​
                if (strcmp(pClassNameList[i].name, name) == 0) {
                    printf("\n相等名字%s总长度%d\n", name, currentClassCount);
                    int j;
                    for (j = i; j < currentClassCount - 1; j++)
                    {
                        //如果是最后一个 不需要交换了
                        if (i == (currentClassCount - 1))
                        {
                            printf("\n删除最后一个\n");
                            pClassNameList[j] = { 0,0,0,0,0 };
                            break;
                        }
                        pClassNameList[j] = pClassNameList[j + 1];
                        //因为是数组 需要位移
                        printf("\n%d前移\n", j + 1);
                    }
                    pClassNameList[j] = { 0,0,0,0,0 };
                    currentClassCount--;
                    printf("\n|删除完成     --\n");
                    break;
                }
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    ​
    ​
    void showClassnameMenu() {
        int selectValue = 0;
        do {
            printf("\n---------------------------------\n");
            printf("\n--          班级管理           --\n");
            printf("\n---------------------------------\n");
            printf("\n|1.添加班级                --\n");
            printf("\n|2.查看班级                --\n");
            printf("\n|3.修改班级                --\n");
            printf("\n|4.删除班级                --\n");
            printf("\n|5.返回                    --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
    ​
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****添加班级****   --\n");
                addClass(classnameList);
    ​
                break;
            case 2:
                printf("\n|  ****查看班级****   --\n");
                showClassMes(classnameList);
                break;
            case 3:
                printf("\n|  ****修改班级****   --\n");
                changeClassMes(classnameList);
                break;
            case 4:
                printf("\n|  ****删除班级****   --\n");
                romoveStudentMes(classnameList);
                break;
            case 5:
                printf("\n|  ****返回****   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 5);
    }
    ​
    ​
    void classnameMain() {
        showClassnameMenu();
    ​
    }

classnameObj.h

    #pragma oncetypedef struct
    {
        char name[20];//班级名字
        int count;//班级人数
        char classTeacher[20];//班主任
        char classSay[50];//班级宣言
        char address[100];//班级地址
    }ClassName;
    ​
    void addClass(ClassName* pClassNameList);
    void showClassMes(ClassName* pClassNameList);
    void changeClassMes(ClassName* pClassNameList);
    void romoveStudentMes(ClassName* pClassNameList);
    void showClassnameMenu();
    void classnameMain();

类型

    #include <stdio.h>
    #include <string.h>
    //定义学生的结构体
    typedef struct
    {
        char name[20];//班级名字
        int count;//班级人数
        char classTeacher[20];//班主任
        char classSay[50];//班级宣言
        char address[100];//班级地址
    }ClassName;
    ​
    //定义一个全局的学生列表
    //每个班级50人
    ClassName classnameList[50] = {};
    //记录当前班级人数
    int currentClassCount = 0;

添加班级

    //添加班级
    void addClass(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|请输入班级的信息 名称 人数 班主任 宣言 班级地址     --\n");
            ClassName s;
            scanf("%s %d %s %s %s", &s.name, &s.count, &s.classTeacher, &s.classSay, &s.address);
            //把数据推送到studentList
            pClassNameList[currentClassCount] = s;
            currentClassCount++;
            printf("\n|是否继续添加班级Y/N     --\n");
            //getchar();//吸收回车
            //printf("answer%c\n", answer);
            getchar();//吸收回车
            scanf("%c", &answer);
            printf("answer%c", answer);
        } while (answer == 'Y' || answer == 'y');
        return;
    }

查看班级

    //查看班级void showClassMes(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|班级信息如下:     --\n");
            printf("\n|名称 | 人数 | 班主任 | 宣言 | 班级地址 |\n");
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n%s | %d | %s | %s | %s |\n", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
            }
            printf("\n|------完成------ --\n");
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }

修改班级

    //修改班级
    void changeClassMes(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|班级信息如下:     --\n");
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n%s | %d | %s | %s | %s |\n", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要修改的班级名字     --\n");
            char name[40];
            scanf("%s", name);
            printf("\n|请输入要修改内容名称: 人数 班主任 宣言 班级地址       --\n");
            getchar();//吸收回车
            ClassName s;
            scanf("%s %d %s %s %s", &s.name, &s.count, &s.classTeacher, &s.classSay, &s.address);
            printf("%s %d %s %s %s", s.name, s.count, s.classTeacher, s.classSay, s.address);
    ​
            //替换
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n|名字%s    --\n", pClassNameList[i].name);
                if (strcmp(pClassNameList[i].name, name) == 0) {
                    printf("\n|马上修改%s     --\n", pClassNameList[i].name);
                    pClassNameList[i] = s;
                    printf("\n|修改完成     --\n");
                    printf("%s %d %s %s %s", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
                    break;
                }
    ​
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'N');
        return;
    }

删除班级

//删除班级
    void romoveStudentMes(ClassName* pClassNameList) {
        char answer = 'Y';
        do {
            printf("\n|班级信息如下:     --\n");
            printf("\n|名称 | 人数 | 班主任 | 宣言 | 班级地址 |\n");
            for (int i = 0; i < currentClassCount; i++)
            {
                printf("\n%s | %d | %s | %s | %s |\n", pClassNameList[i].name, pClassNameList[i].count, pClassNameList[i].classTeacher, pClassNameList[i].classSay, pClassNameList[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要删除的班级名字     --\n");
            char name[40];
            scanf("%s", name);
    ​
            //替换
            for (int i = 0; i < currentClassCount; i++)
            {
    ​
                if (strcmp(pClassNameList[i].name, name) == 0) {
                    printf("\n相等名字%s总长度%d\n", name, currentClassCount);
                    int j;
                    for (j = i; j < currentClassCount - 1; j++)
                    {
                        //如果是最后一个 不需要交换了
                        if (i == (currentClassCount - 1))
                        {
                            printf("\n删除最后一个\n");
                            pClassNameList[j] = { 0,0,0,0,0 };
                            break;
                        }
                        pClassNameList[j] = pClassNameList[j + 1];
                        //因为是数组 需要位移
                        printf("\n%d前移\n", j + 1);
                    }
                    pClassNameList[j] = { 0,0,0,0,0 };
                    currentClassCount--;
                    printf("\n|删除完成     --\n");
                    break;
                }
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }

4.教师管理

teacherObj.cpp

    //这里是老师管理的实现//菜单展示
    #include <stdio.h>
    #include <string.h>
    //定义老师的结构体
    typedef struct
    {
        char name[20];//老师名字
        int age;//年龄
        int sex;//性别
        char classname[50];//班级
        char address[100];//住址
    }Teacher;
    ​
    //定义一个全局的老师列表
    //每个班级50人
    Teacher TeacherList[50] = {};
    //记录当前班级人数
    int currentTeaCount = 0;
    ​
    //添加老师
    void addTeacher(Teacher* pteacherlist) {
        char answer = 'Y';
        do {
            printf("\n|请输入老师的信息 姓名 年龄 性别(1男0女) 班级 家庭住址     --\n");
            Teacher s;
            scanf("%s %d %d %s %s", &s.name, &s.age, &s.sex, &s.classname, &s.address);
            //把数据推送到TeacherList
            pteacherlist[currentTeaCount] = s;
            currentTeaCount++;
            printf("\n|是否继续天加老师Y/N     --\n");
            //getchar();//吸收回车
            //printf("answer%c\n", answer);
            getchar();//吸收回车
            scanf("%c", &answer);
            printf("answer%c", answer);
        } while (answer == 'Y' || answer == 'y');
        return;
    }
    //查看老师void showTeacherMes(Teacher* pteacherlist) {
        char answer = 'Y';
        do {
            printf("\n|老师信息如下:     --\n");
            printf("\n姓名 | 年龄 | 性别 | 班级 | 家庭住址 |\n");
            for (int i = 0; i < currentTeaCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pteacherlist[i].name, pteacherlist[i].age, pteacherlist[i].sex, pteacherlist[i].classname, pteacherlist[i].address);
            }
            printf("\n|------完成------ --\n");
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    //修改老师
    void changeTeacherMes(Teacher* pteacherlist) {
        char answer = 'Y';
        do {
            printf("\n|老师信息如下:     --\n");
            for (int i = 0; i < currentTeaCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pteacherlist[i].name, pteacherlist[i].age, pteacherlist[i].sex, pteacherlist[i].classname, pteacherlist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要修改的老师名字     --\n");
            char name[40];
            scanf("%s", name);
            printf("\n|请输入要修改内容姓名 年龄 性别(1男0女) 班级 家庭住址       --\n");
            getchar();//吸收回车
            Teacher s;
            scanf("%s %d %d %s %s", &s.name, &s.age, &s.sex, &s.classname, &s.address);
            printf("%s %d %d %s %s", s.name, s.age, s.sex, s.classname, s.address);
    ​
            //替换
            for (int i = 0; i < currentTeaCount; i++)
            {
                printf("\n|名字%s    --\n", pteacherlist[i].name);
                if (strcmp(pteacherlist[i].name, name) == 0) {
                    printf("\n|马上修改%s     --\n", pteacherlist[i].name);
                    pteacherlist[i] = s;
                    printf("\n|修改完成     --\n");
                    printf("%s %d %d %s %s", pteacherlist[i].name, pteacherlist[i].age, pteacherlist[i].sex, pteacherlist[i].classname, pteacherlist[i].address);
                    break;
                }
    ​
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'N');
        return;
    }
    ​
    //删除老师
    void romoveTeacherMes(Teacher* pteacherlist) {
        char answer = 'Y';
        do {
            printf("\n|老师信息如下:     --\n");
            printf("\n姓名 | 年龄 | 性别 | 班级 | 家庭住址 |\n");
            for (int i = 0; i < currentTeaCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pteacherlist[i].name, pteacherlist[i].age, pteacherlist[i].sex, pteacherlist[i].classname, pteacherlist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要删除的老师名字     --\n");
            char name[40];
            scanf("%s", name);
    ​
            //替换
            for (int i = 0; i < currentTeaCount; i++)
            {
    ​
                if (strcmp(pteacherlist[i].name, name) == 0) {
                    printf("\n相等名字%s总长度%d\n", name, currentTeaCount);
                    int j;
                    for (j = i; j < currentTeaCount - 1; j++)
                    {
                        //如果是最后一个 不需要交换了
                        if (i == (currentTeaCount - 1))
                        {
                            printf("\n删除最后一个\n");
                            pteacherlist[j] = { 0,0,0,0,0 };
                            break;
                        }
                        pteacherlist[j] = pteacherlist[j + 1];
                        //因为是数组 需要位移
                        printf("\n%d前移\n", j + 1);
                    }
                    pteacherlist[j] = { 0,0,0,0,0 };
                    currentTeaCount--;
                    printf("\n|删除完成     --\n");
                    break;
                }
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    ​
    ​
    void showTeacherMenu() {
        int selectValue = 0;
        do {
            printf("\n---------------------------------\n");
            printf("\n--          老师管理           --\n");
            printf("\n---------------------------------\n");
            printf("\n|1.添加老师                --\n");
            printf("\n|2.查看老师                --\n");
            printf("\n|3.修改老师                --\n");
            printf("\n|4.删除老师                --\n");
            printf("\n|5.返回                    --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
    ​
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****添加老师****   --\n");
                addTeacher(TeacherList);
    ​
                break;
            case 2:
                printf("\n|  ****查看老师****   --\n");
                showTeacherMes(TeacherList);
                break;
            case 3:
                printf("\n|  ****修改老师****   --\n");
                changeTeacherMes(TeacherList);
                break;
            case 4:
                printf("\n|  ****删除老师****   --\n");
                romoveTeacherMes(TeacherList);
                break;
            case 5:
                printf("\n|  ****返回****   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 5);
    }
    ​
    ​
    void teacherMain() {
        showTeacherMenu();
    ​
    }
    ​

teacherObj.h

    #pragma once
    typedef struct
    {
        char name[20];//老师名字
        int age;//年龄
        int sex;//性别
        char classname[50];//班级
        char address[100];//住址
    }Teacher;
    ​
    void addTeacher(Teacher* pteacherlist);
    ​
    void addTeacher(Teacher* pteacherlist);
    void showTeacherMes(Teacher* pteacherlist);
    void changeTeacherMes(Teacher* pteacherlist);
    void romoveTeacherMes(Teacher* pteacherlist);
    void showTeacherMenu();
    void teacherMain();

5.书本管理

bookObj.cpp

    //这里是书本管理的实现//菜单展示
    #include <stdio.h>
    #include <string.h>
    //定义书本的结构体
    typedef struct
    {
        char name[20];//书名
        int price;//价格
        int count;//数量
        char classname[50];//使用班级使用
        char address[100];//出版社
    }Book;
    ​
    //定义一个全局的书本列表
    //每个使用班级50人
    Book bookList[50] = {};
    //记录当前使用班级人数
    int currentBookCount = 0;
    ​
    //添加书本
    void addBook(Book* pbooklist) {
        char answer = 'Y';
        do {
            printf("\n|请输入书本的信息 书名 价格 数量 使用班级 出版社     --\n");
            Book s;
            scanf("%s %d %d %s %s", &s.name, &s.price, &s.count, &s.classname, &s.address);
            //把数据推送到bookList
            pbooklist[currentBookCount] = s;
            currentBookCount++;
            printf("\n|是否继续天加书本Y/N     --\n");
            //getchar();//吸收回车
            //printf("answer%c\n", answer);
            getchar();//吸收回车
            scanf("%c", &answer);
            printf("answer%c", answer);
        } while (answer == 'Y' || answer == 'y');
        return;
    }
    //查看书本void showBookMes(Book* pbooklist) {
        char answer = 'Y';
        do {
            printf("\n|书本信息如下:     --\n");
            printf("\n书名 | 价格 | 性别 | 使用班级 | 出版社 |\n");
            for (int i = 0; i < currentBookCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pbooklist[i].name, pbooklist[i].price, pbooklist[i].count, pbooklist[i].classname, pbooklist[i].address);
            }
            printf("\n|------完成------ --\n");
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    //修改书本
    void changeBookMes(Book* pbooklist) {
        char answer = 'Y';
        do {
            printf("\n|书本信息如下:     --\n");
            for (int i = 0; i < currentBookCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pbooklist[i].name, pbooklist[i].price, pbooklist[i].count, pbooklist[i].classname, pbooklist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要修改的书本名字     --\n");
            char name[40];
            scanf("%s", name);
            printf("\n|请输入要修改内容书名 价格 数量 使用班级 出版社       --\n");
            getchar();//吸收回车
            Book s;
            scanf("%s %d %d %s %s", &s.name, &s.price, &s.count, &s.classname, &s.address);
            printf("%s %d %d %s %s", s.name, s.price, s.count, s.classname, s.address);
    ​
            //替换
            for (int i = 0; i < currentBookCount; i++)
            {
                printf("\n|名字%s    --\n", pbooklist[i].name);
                if (strcmp(pbooklist[i].name, name) == 0) {
                    printf("\n|马上修改%s     --\n", pbooklist[i].name);
                    pbooklist[i] = s;
                    printf("\n|修改完成     --\n");
                    printf("%s %d %d %s %s", pbooklist[i].name, pbooklist[i].price, pbooklist[i].count, pbooklist[i].classname, pbooklist[i].address);
                    break;
                }
    ​
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'N');
        return;
    }
    ​
    //删除书本
    void romoveBookMes(Book* pbooklist) {
        char answer = 'Y';
        do {
            printf("\n|书本信息如下:     --\n");
            printf("\n书名 | 价格 | 性别 | 使用班级 | 出版社 |\n");
            for (int i = 0; i < currentBookCount; i++)
            {
                printf("\n%s | %d | %d | %s | %s |\n", pbooklist[i].name, pbooklist[i].price, pbooklist[i].count, pbooklist[i].classname, pbooklist[i].address);
            }
            printf("\n|------完成------ --\n");
    ​
            printf("\n|请输入要删除的书本名字     --\n");
            char name[40];
            scanf("%s", name);
    ​
            //替换
            for (int i = 0; i < currentBookCount; i++)
            {
    ​
                if (strcmp(pbooklist[i].name, name) == 0) {
                    printf("\n相等名字%s总长度%d\n", name, currentBookCount);
                    int j;
                    for (j = i; j < currentBookCount - 1; j++)
                    {
                        //如果是最后一个 不需要交换了
                        if (i == (currentBookCount - 1))
                        {
                            printf("\n删除最后一个\n");
                            pbooklist[j] = { 0,0,0,0,0 };
                            break;
                        }
                        pbooklist[j] = pbooklist[j + 1];
                        //因为是数组 需要位移
                        printf("\n%d前移\n", j + 1);
                    }
                    pbooklist[j] = { 0,0,0,0,0 };
                    currentBookCount--;
                    printf("\n|删除完成     --\n");
                    break;
                }
            }
    ​
            printf("\n|是否退出Y/N     --\n");
            getchar();//吸收回车
            scanf("%c", &answer);
        } while (answer == 'N' || answer == 'n');
        return;
    }
    ​
    ​
    ​
    void showBookMenu() {
        int selectValue = 0;
        do {
            printf("\n---------------------------------\n");
            printf("\n--          书本管理           --\n");
            printf("\n---------------------------------\n");
            printf("\n|1.添加书本                --\n");
            printf("\n|2.查看书本                --\n");
            printf("\n|3.修改书本                --\n");
            printf("\n|4.删除书本                --\n");
            printf("\n|5.返回                    --\n");
            printf("\n-----------------------------\n");
            printf("\n|请输入你的选择            --\n");
            printf("\n-----------------------------\n");
    ​
            scanf("%d", &selectValue);
    ​
            switch (selectValue)
            {
            case 1:
                printf("\n|  ****添加书本****   --\n");
                addBook(bookList);
    ​
                break;
            case 2:
                printf("\n|  ****查看书本****   --\n");
                showBookMes(bookList);
                break;
            case 3:
                printf("\n|  ****修改书本****   --\n");
                changeBookMes(bookList);
                break;
            case 4:
                printf("\n|  ****删除书本****   --\n");
                romoveBookMes(bookList);
                break;
            case 5:
                printf("\n|  ****返回****   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 5);
    }
    ​
    ​
    void bookMain() {
        showBookMenu();
    ​
    }
    ​
    ​

bookObj.h

    #pragma once
    typedef struct
    {
        char name[20];//书名
        int price;//价格
        int count;//数量
        char classname[50];//使用班级使用
        char address[100];//出版社
    }Book;
    
    void addBook(Book* pbooklist);
    void showBookMes(Book* pbooklist);
    void changeBookMes(Book* pbooklist);
    void romoveBookMes(Book* pbooklist);
    void showBookMenu();
    void bookMain();

6.部门管理

    switch (selectValue)
            {
            case 1:
                printf("\n|  ****学生管理****   --\n");
                studenMain();
                break;
            case 2:
                printf("\n|  ****班级管理****   --\n");
                classnameMain();
                break;
            case 3:
                printf("\n|  ****老师管理****   --\n");
                teacherMain();
                break;
            case 4:
                printf("\n|  ****书本管理****   --\n");
                bookMain();
                break;
            case 5:
                printf("\n|  ****部门管理****   --\n");
                printf("\n|  暂未开设部门管理功能,该业务暂未需求   --\n");//----------------------------
                break;
            case 6:
                printf("\n|  ****正在退出....   --\n");
                break;
            default:
                printf("\n|输入有误,重新输入            --\n");
                break;
            }
        } while (selectValue != 6);

7.完结

image-20240611231349715.png