学生信息管理系统

一、需求

基于C语言编写一个学生信息管理系统来实现对学生成绩的管理(数学、C语言、英语),系统要能够实现基本的增、删、改、查等功能,在此基础上还可以自由发挥,要求使用到数组、文件、排序算法等操作。

二、功能

本系统在实现增、删、改、查等基本功能后又实现了新手注册、登录、修改密码、找回密码、冻结账户、解冻账户等功能。

三、说明

此次更新解决了一些已知的bug,修改了部分功能的底层逻辑,并且添加了登录时输入密码回显星号的功能。

四、运行结果和代码

1.安装包:

2.登录界面展示:

初始化界面、可直接打开你自己定义的音乐:

登录菜单栏:

功能区菜单栏:

部分功能展示:




整体代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <io.h>
#include <conio.h>
#include <direct.h>
#include <windows.h>/*定义结构体变量*/
struct student
{char name[20]; //学生姓名char sex[4];   //学生性别char num[15];  //学号int math;    //数学成绩int c;        //c语言成绩int eng;     //英语成绩int sum;      //总成绩int counts;    //记录学生排名情况double aver;   //平均成绩} str[10000];
/*文件表头变量*/
char id[] = "学号";
char name[] = "姓名";
char sex[] = "性别";
char math[] = "数学";
char c[] = "c语言";
char eng[] = "英语";
char score[] = "总分";
char aver[] = "平均分";
char rank[] = "排名";/*定义全局变量*/
char choice;    //功能选择
char numb[20];  //存储存注册的账号
char numbs[20]; //存储用户输入的账号
char numb1[20];
char password[6];                           //存储用户注册的密码
char passwords[6];                          //存储用户输入的密码
char password1[6];                          //用于存储修改密码时用户第一次输入的密码
char password2[6];                          //用于存储修改密码时用户第二次输入的密码
char phone[20];                             //存储用户注册的手机号码
char phones[20];                            //存储用户输入的手机号
char card[20];                              //存储用户注册的身份证号
char cards[20];                             //存储用户输入的身份证号
char filename[40];                          //存储文件名
char back[] = {"######"};                    //用于强制退出系统的
char back_s[] = {"@@@@@@@@@@"};                //用于强制退出系统
int verificationCode_1, verificationCode_2; //分别用来存储系统产生的验证码和用户输入的验证码
int count = 0;                             //计数器
int i = 0;/*************************************函数的声明*************************************/
void loginMenu();                          //登录界面菜单
void loginInteraction();                   //登录交互模块
void mainMenu();                           //功能选型菜单
void functionalInteraction();              //功能交互模块
void login();                              //登录的方法
void logon();                              //账户注册的方法
void forgetPassword();                     //忘记密码的方法
void welcome(char m[]);                    //实现欢迎界面
void welcome_s();                          //欢迎界面
void sound();                              //声音提示功能
void talk();                               //登录友好提示功能
void fun0();                               //退出信息系统
void fun1();                               //输入学生信息
void fun2();                               //显示学生信息
void fun3();                               //查询学生信息
void fun4();                               //保存学生信息(以二进制保存)
void fun5();                               //读取学生信息(以二进制读取)
void fun6();                               //保存学生信息(以文本式保存)
void fun7();                               //读取学生信息(以文本式读取)
void fun8();                               //查询不及格数
void fun9();                               //删除学生信息
void fun10();                              //清空学生信息文件
void fun11();                              //打开学生信息文件
void fun12();                              //修改学生信息
void fun13();                              //添加学生信息
void sort(int count);                      //排序算法
void count_1();                            //添加信息到文件(二进制)
void count_2();                            //添加信息到文件(文本式)
void input();                              //输入密码
void retrievePassword();                   //找回密码
void frozenAccount();                      //冻结账号
void unfreezeAccount();                    //解冻账号
void changePassword();                     //修改密码
void reWritePassword();                    //修改密码的方法
void clearData();                          //冻结账户的方法
void wipeData();                           //用于擦除解冻后残留的账户信息
void guide();                              //新手指南
void creatFolder();                        //创建项目保存路径(在所在路径下创建项目文件夹)
void judge(char numb[]);                   //判断账号长度的方法
void judge_s(char passwords[]);            //判断密码长度的方法
void compare(int count);                   //判断输入的信息是否重复的方法
void out(char nums[], char back_s[]);      //强制退出系统
void out_s(char passwords[], char back[]); //强制退出系统
void part_out(char cards[], char out[]);   //退出部分功能/*************************************登录菜单设计*************************************/
void loginMenu() /*登录界面*/
{printf("------------------------------【学生信息管理系统】--------------------------------------\n");printf("\t\t\t  1.登录\t\t2.注册\n");printf("\t\t\t  3.修改密码\t\t4.忘记密码\n");printf("\t\t\t  5.退出系统\t\t6.解冻账号\n");printf("\t\t\t  7.新手在线指南\t8.创建项目保存路径\n");printf("----------------------------------------------------------------------------------------\n");
}
/*************************************功能菜单设计*************************************/
void mainMenu() /*菜单界面*/
{printf("-----------------------------------【学生信息管理系统】----------------------------------------------------\n");printf("\t\t  0.退出信息系统.\t\t\t1.输入学生信息.\t\n");printf("\t\t  2.显示学生信息.\t\t\t3.查询学生信息.\t\n");printf("\t\t  4.保存学生信息(以二进制保存).\t\t5.读取学生信息(以二进制读取).\t\n");printf("\t\t  6.保存学生信息(以文本式保存).\t\t7.读取学生信息(以文本式读取).\t\n");printf("\t\t  8.查询不及格数.\t\t\t9.删除学生信息.\t\n");printf("\t\t  10.清空学生信息文件.\t\t\t11.打开学生信息文件.\t\n");printf("\t\t  12.修改学生信息.\t\t\t13.添加学生信息\n");printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************登录选择模块*************************************/
void loginInteraction() /*登录菜单选项*/
{while (1){printf("请选择你要进行的服务:");scanf("%d", &choice);switch (choice){case 1:login();return;case 2:logon();break;case 3:changePassword();break;case 4:forgetPassword();break;case 5:fun0();break;case 6:unfreezeAccount();break;case 7:guide();break;case 8:creatFolder();break;default:printf("请在1-8之间选择:\n");break;}}
}
/*************************************菜单选择模块*************************************/
void functionalInteraction() /*功能菜单选项*/
{printf("请选择您要办理的业务:");scanf("%d", &choice);switch (choice){case 0:fun0();break;case 1:fun1();break;case 2:fun2();break;case 3:fun3();break;case 4:fun4();break;case 5:fun5();break;case 6:fun6();break;case 7:fun7();break;case 8:fun8();break;case 9:fun9();break;case 10:fun10();break;case 11:fun11();break;case 12:fun12();break;case 13:fun13();break;default:printf("请在0-13之间选择!\n");break;}
}
/*************************************登录*************************************/
/*登录友好提示*/
void talk()
{for (i = 0; i < 3; i++){printf("·");Sleep(500);}printf("\n");
}
/*判断账号长度*/
void judge(char numbs[])
{while ((int)strlen(numbs) > 10 || (int)strlen(numbs) < 10){sound();printf("请输入10位数的账号!\n");printf("请再次输入你的账号:");scanf("%s", numbs);if (strlen(numbs) == 10){break;}}
}
/*测定密码长度*/
void judge_s(char passwords[])
{while ((int)strlen(passwords) > 6 || (int)strlen(passwords) < 6){sound();printf("请输入六位数的密码!\n");printf("请再次输入您的密码:");scanf("%s", passwords);if (strlen(numbs) == 6){break;}}
}
/*强制退出系统*/
void out(char nums[], char back_s[])
{if (strcmp(numbs, back_s) == 0){sound();printf("注意:三秒后将强制退出系统!\n");talk();printf("已强制退出系统.\n");exit(0);}
}
void out_s(char passwords[], char back[])
{if (strcmp(passwords, back) == 0){sound();printf("注意:三秒后将强制退出系统!\n");talk();printf("已强制退出系统.\n");exit(0);}
}
/*输入密码*/
void input()
{for (i = 0; i < (int)strlen(password); i++){passwords[i] = getch();printf("*");}printf("\n");
}
/*登录功能*/
void login()
{FILE *fp, *sp;printf("-------------------------------【登录功能】---------------------------------------------\n");printf("注意:{当输入的账号为十个“@”或密码为六个“#”时强制退出系统.}\n");fp = fopen("账户信息.txt", "r");sp = fopen("密码.txt", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("账户信息.txt", "w");fclose(fp);printf("可能由于您是初次使用,尚未创建账户信息,现已为您创建账户信息,五秒后将退出系统,请重新进入系统。\n");fun0();exit(0);}if (sp == NULL){sound();printf("数据错误!\n");sp = fopen("密码.txt", "w");fclose(sp);printf("可能由于您是初次使用,尚未创建账户信息,现已为您创建账户信息,五秒秒后将退出系统,请重新进入系统。\n");fun0();exit(0);}fscanf(fp, "%s", numb, card, phone);fscanf(sp, "%s", password);printf("请输入您的帐号:");scanf("%s", numbs);judge(numbs);       //判断账号长度out(numbs, back_s); //判断是否强制退出printf("请输入您的密码:");input();judge_s(passwords);      //判断密码长度(并非强制性)out_s(passwords, back); //判断是否强制退出while (1){if (strcmp(numbs, back_s) == 0 || strcmp(passwords, back) == 0){sound();printf("注意:三秒后将强制退出系统!\n");talk();printf("已强制退出系统.\n");exit(0);}else if (strcmp(numbs, numb) == 0 && strcmp(passwords, password) == 0){printf("登陆中\n");talk();break;}else if (strcmp(numbs, numb) != 0 && strcmp(passwords, password) != 0){sound();printf("您输入的账号和密码不存在,请重新输入:");scanf("%s %s", numbs, passwords);judge(numbs);       //判断账号长度judge_s(passwords); //判断密码长度}else if (strcmp(numbs, numb) != 0 && strcmp(passwords, password) == 0){sound();printf("您输入的帐号不存在,请重新输入:");scanf("%s", numbs);judge(numbs); //判断账号长度}else if (strcmp(passwords, password) != 0 && strcmp(numbs, numb) == 0){sound();printf("您输入的密码错误,请重新输入:");scanf("%s", passwords);judge_s(passwords); //判断密码长度}}fclose(fp);fclose(sp);printf("----------------------------------------------------------------------------------------\n");system("cls");
}
/*************************************注册*************************************/
void logon() /*注册功能*/
{FILE *fp, *sp;srand(time(NULL));printf("-------------------------------【注册信息】---------------------------------------------\n");printf("注意:{账号的长度为10位数,密码的长度为6位数。}\n");sp = fopen("密码.txt", "w");fp = fopen("账户信息.txt", "w");if ((fp = fopen("账户信息.txt", "w")) == NULL){sound();printf("数据错误!\n");fp = fopen("账户信息.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}if (sp == NULL){sound();printf("数据错误!\n");sp = fopen("密码.txt", "w");fclose(sp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}verificationCode_1 = rand() % 10001; //产生四位数的二维码printf("请输入您的账号:");scanf("%s", numb);judge(numb); //判断账号长度是否合法printf("请输入您的密码:");for (i = 0; i < 6; i++){password[i] = getch();printf("*");}printf("\n");judge_s(password); //判断密码长度是否合法printf("请输入您的身份证号:");scanf("%s", card);printf("请输入您的手机号码:");scanf("%s", phone);printf("【验证码】:%04d.(您正在使用注册信息功能,此验证码仅用于验证身份,请勿泄露给他人).\n", verificationCode_1);printf("请输入验证码:");while (1){scanf("%d", &verificationCode_2);if (verificationCode_2 == verificationCode_1){fprintf(fp, "%s\t%s\t%s", numb, card, phone);fprintf(sp, "%s", password);fclose(fp);fclose(sp);printf("账户注册中\n");talk();printf("注册成功!\n");break;}elsesound();printf("您输入的验证码有误!\n");printf("请重新输入验证码:");}printf("----------------------------------------------------------------------------------------\n");system("pause");
}
/*************************************修改密码*************************************/
void reWritePassword() //重写密码文件
{FILE *sp;sp = fopen("密码.txt", "w");if (sp == NULL){sound();printf("数据错误!\n");exit(0);}fprintf(sp, "%s", password2);fclose(sp);
}
void changePassword() //修改密码
{FILE *fp;int verificationCode_1, verificationCode_2;srand(time(NULL));                  //rand的种子(seek),用于生成验证码。verificationCode_1 = rand() % 10001; //生成验证码。printf("-------------------------------【修改密码】---------------------------------------------\n");fp = fopen("密码.txt", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("密码.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}fscanf(fp, "%s", password);while (1){printf("请输入您的当前密码:");input();if (strcmp(password, passwords) != 0){sound();printf("密码不正确,可能是密码长度不够或其他原因,请再试一次.\n");}else if (strcmp(passwords, password) == 0){fclose(fp);printf("请输入您的新密码:");scanf("%s", password1);judge_s(password); //判断密码长度是否合法while (1){printf("请重新输入您的新密码:");scanf("%s", password2);if (strcmp(password1, password2) != 0){sound();printf("两次密码不一致,");}else if (strcmp(password1, password2) == 0){printf("【验证码】:%04d.(您正在使用修改密码功能,此验证码仅用于验证身份,请勿泄露给他人).\n", verificationCode_1);printf("请输入验证码:");while (1){scanf("%d", &verificationCode_2);if (verificationCode_1 != verificationCode_2){sound();printf("您输入的验证码有误,请重新输入:");}else if (verificationCode_1 == verificationCode_2){reWritePassword();printf("密码修改中\n");talk();printf("密码修改成功!\n");break;}}printf("----------------------------------------------------------------------------------------\n");system("pause");return;}}}}
}
/*************************************忘记密码*************************************/
void forgetPassword()
{printf("-------------------------------【忘记密码】---------------------------------------------\n");printf("1.找回密码\t2.冻结账号\n");while (1){printf("请选择您要办理的业务:");scanf("%d", &choice);switch (choice){case 1:retrievePassword();return;case 2:frozenAccount();return;default:printf("请输入1-2\n");break;}}printf("----------------------------------------------------------------------------------------\n");
}
/*************************************找回密码*************************************/
/*退出该项功能*/
void part_out(char cards[], char out[])
{if (strcmp(cards, out) == 0){printf("已返回主菜单.\n");return;}
}
void retrievePassword()
{FILE *fp, *sp;int verificationCode_1, verificationCode_2;char out[] = {"0"};srand(time(NULL));verificationCode_1 = rand() % 10001;printf("-------------------------------【找回密码】---------------------------------------------\n");printf("注意:{当输入的手机号或身份证号为0时退出该功能.}\n");fp = fopen("账户信息.txt", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("账户信息.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}fscanf(fp, "%s\t%s\t%s", numb, card, phone);printf("请输入您的身份证号:");scanf("%s", cards);printf("请输入您的手机号:");scanf("%s", phones);while (1){if (strcmp(cards, out) == 0 || strcmp(phones, out) == 0){printf("已返回主菜单.\n");break;}else if (strcmp(phone, phones) == 0 && strcmp(cards, card) == 0){printf("【验证码】:%04d.(您正在使用找回密码功能,此验证码仅用于验证身份,请勿泄露给他人).\n", verificationCode_1);printf("请输入验证码:");scanf("%d", &verificationCode_2);while (1){if (strcmp(phones, phone) == 0 && strcmp(cards, card) == 0 && verificationCode_1 == verificationCode_2){sp = fopen("密码.txt", "r");if (sp == NULL){sound();printf("数据错误!\n");exit(0);}fscanf(sp, "%s", password);printf("正在找回密码\n");talk();printf("您的密码为:%s\n", password);fclose(sp);printf("----------------------------------------------------------------------------------------\n");return;}else if (verificationCode_1 != verificationCode_2){sound();printf("您输入的验证码有误,请重新输入:");scanf("%d", &verificationCode_2);}}}else if (strcmp(phone, phones) != 0 && strcmp(cards, card) != 0){sound();printf("您输入的身份证号和手机号不存在,请重新输入:");scanf("%s %s", cards, phones);}else if (strcmp(phone, phones) != 0 && strcmp(cards, card) == 0){sound();printf("您输入的手机号不存在,请重新输入:");scanf("%s", phones);}else if (strcmp(cards, card) != 0 && strcmp(phones, phone) == 0){sound();printf("您输入的身份证号不存在,请重新输入:");scanf("%s", cards);part_out(cards, out);}}printf("----------------------------------------------------------------------------------------\n");fclose(fp);system("pause");
}
/*************************************冻结账号*************************************/
void clearData(char min[])
{FILE *fp;fp = fopen("账户信息.txt", "w");if (fp == NULL){sound();printf("数据错误!\n");exit(0);}fprintf(fp, "%s", min);fclose(fp);
}
void frozenAccount()
{FILE *fp, *sp;char min[] = {" "};char out[] = {"0"};int verificationCode_1, verificationCode_2;srand(time(NULL));verificationCode_1 = rand() % 10001;printf("-------------------------------【冻结账户】---------------------------------------------\n");printf("注意:{当输入的手机号或身份证号为0时退出该功能.}\n");fp = fopen("账户信息.txt", "r");sp = fopen("账户信息(1).txt", "w");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("账户信息.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}if (sp == NULL){sound();printf("数据错误!\n");exit(0);}fscanf(fp, "%s\t%s\t%s", numb, card, phone);printf("请输入您的身份证号:");scanf("%s", cards);printf("请输入您的手机号:");scanf("%s", phones);while (1){if (strcmp(cards, out) == 0 || strcmp(phones, out) == 0){printf("已返回主菜单.\n");break;}else if (strcmp(phone, phones) == 0 && strcmp(cards, card) == 0){printf("【验证码】:%04d.(您正在使用冻结账户功能,此验证码仅用于验证身份,请勿泄露给他人).\n", verificationCode_1);printf("请输入验证码:");scanf("%d", &verificationCode_2);while (1){if (strcmp(phone, phones) == 0 && strcmp(card, cards) == 0 && verificationCode_1 == verificationCode_2){fprintf(sp, "%s\t%s\t%s", numb, card, phone);fclose(fp);fclose(sp);clearData(min);printf("账户冻结中\n");talk();printf("您的账户已冻结,重启后生效.\n");printf("1.立即重启\t2.稍后重启\n");printf("请选择是否重启:");scanf("%d", &choice);switch (choice){case 1:sound();printf("注意:三秒后将退出系统\n");talk();printf("成功退出系统。\n");exit(0);return;case 2:printf("已返回主菜单.\n");printf("----------------------------------------------------------------------------------------\n");return;default:printf("请输入1—2!\n");break;}}else if (verificationCode_1 != verificationCode_2){sound();printf("您输入的验证码有误,请重新输入:");scanf("%d", &verificationCode_2);}}}else if (strcmp(phone, phones) != 0 && strcmp(cards, card) != 0){sound();printf("您输入的身份证号和手机号不存在,请重新输入:");scanf("%s %s", cards, phones);}else if (strcmp(phone, phones) != 0 && strcmp(cards, card) == 0){sound();printf("您输入的手机号不存在,请重新输入:");scanf("%s", phones);}else if (strcmp(cards, card) != 0 && strcmp(phones, phone) == 0){sound();printf("您输入的身份证号不存在,请重新输入:");scanf("%s", cards);part_out(cards, out);}}printf("----------------------------------------------------------------------------------------\n");
}
/*************************************解冻账号*************************************/
/*擦除冻结后的账户信息*/
void wipeData(char min[])
{FILE *fp;fp = fopen("账户信息(1).txt", "w");if (fp == NULL){sound();printf("数据错误!\n");exit(0);}fprintf(fp, "%s", min);fclose(fp);
}
void unfreezeAccount()
{FILE *fp, *sp;int verificationCode_1, verificationCode_2;char min[] = {" "};char out[] = {"0"};printf("-------------------------------【解冻账户】---------------------------------------------\n");srand(time(NULL));verificationCode_1 = rand() % 10001;printf("注意:{当输入的手机号或身份证号为0时退出该功能.}\n");fp = fopen("账户信息.txt", "w");sp = fopen("账户信息(1).txt", "r");if (fp == NULL){sound();printf("数据错误!\n");exit(0);}if (sp == NULL){sound();printf("数据错误!\n");sp = fopen("账户信息(1).txt", "w");fclose(sp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}fscanf(sp, "%s\t%s\t%s", numb, card, phone);printf("请输入您的身份证号:");scanf("%s", cards);printf("请输入您的手机号:");scanf("%s", phones);while (1){if (strcmp(cards, out) == 0 || strcmp(phones, out) == 0){printf("已返回主菜单.\n");break;}else if (strcmp(phone, phones) == 0 && strcmp(cards, card) == 0){printf("【验证码】:%04d.(您正在使用解冻账户功能,此验证码仅用于验证身份,请勿泄露给他人).\n", verificationCode_1);printf("请输入验证码:");scanf("%d", &verificationCode_2);while (1){if (strcmp(phones, phone) == 0 && strcmp(cards, card) == 0 && verificationCode_1 == verificationCode_2){fprintf(fp, "%s\t%s\t%s", numb, card, phone);fclose(fp);fclose(sp);wipeData(min);printf("账户解冻中\n");talk();printf("您的账户解冻成功!\n");return;}else if (verificationCode_1 != verificationCode_2){sound();printf("您输入的验证码有误,请重新输入:");scanf("%d", &verificationCode_2);}}}else if (strcmp(phone, phones) != 0 && strcmp(cards, card) != 0){sound();printf("您输入的身份证号和手机号不存在,请重新输入:");scanf("%s %s", cards, phones);}else if (strcmp(phone, phones) != 0 && strcmp(cards, card) == 0){sound();printf("您输入的手机号不存在,请重新输入:");scanf("%s", phones);}else if (strcmp(cards, card) != 0 && strcmp(phones, phone) == 0){sound();printf("您输入的身份证号不存在,请重新输入:");scanf("%s", cards);}}printf("----------------------------------------------------------------------------------------\n");
}
/*************************************新手在线指南*****************************************/
void guide()
{printf("----------------------------------【新手在线指南】--------------------------------------\n");printf("正在尝试打开新手指南");for (i = 0; i < 3; i++){printf("->");Sleep(500);}printf("\n");system("start 学生信息管理系统指南.txt");printf("----------------------------------------------------------------------------------------\n");
}
/*************************************创建项目保存路径*************************************/
void creatFolder()
{char foldername[20];printf("-------------------------------【创建项目保存路径】-------------------------------------\n");printf("请输入要创建的文件夹名称:");scanf("%s", foldername);if (_access(foldername, 0) == -1){_mkdir(foldername);}printf("路径创建中\n");talk();printf("路径创建成功.\n");printf("----------------------------------------------------------------------------------------\n");
}
/*************************************退出系统*************************************/
void fun0()
{printf("注意:五秒后将退出系统!\n");for (i = 0; i < 5; i++){printf("·");Sleep(1000);}printf("\n");printf("已成功退出系统!\n");exit(0);
}
/*************************************排序算法*************************************/
void sort(int count)
{int i, j;struct student temp;for (j = 0; j < count - 1; j++){for (i = 0; i < count - 1 - j; i++){if (str[i].sum < str[i + 1].sum){temp = str[i];str[i] = str[i + 1];str[i + 1] = temp;}}}
}
/*************************************录入信息*************************************/
void compare(int count) //判断输入的信息是否重复
{int i;int flag = 0;while (1){for (i = 0; i < count; i++){if (strcmp(str[i].num, str[count].num) == 0){flag = 1; //如果输入的学号和已经存入的学号相同则让flag=1;}}if (flag){flag = 0;printf("您输入的学号已存在,请重新输入:");scanf("%s", str[count].num);continue;}elsereturn;}
}
void fun1()
{int i = 0;char com[] = "0";printf("说明:当输入的学号为零时结束信息输入\n");while (1){printf("------------------------------------【录入信息】-----------------------------------------------------------\n");printf("开始输入第%d个学生信息\n", i + 1);printf("请输入学号:");scanf("%s", str[i].num);if (strcmp(str[i].num, com) == 0){break;}if (i >= 1){compare(i);}printf("请输入姓名:");scanf("%s", str[i].name);printf("请输入性别:");scanf("%s", str[i].sex);printf("请输入数学成绩:");scanf("%d", &str[i].math);printf("请输入C语言成绩:");scanf("%d", &str[i].c);printf("请输入英语成绩:");scanf("%d", &str[i].eng);str[i].sum = str[i].math + str[i].c + str[i].eng;str[i].aver = str[i].sum / 3;i++;system("cls");}count = i;sort(count); //对成绩排序printf("总共输入了%d个学生信息.\n", count);printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************排名信息*************************************/
void fun2()
{int i;printf("count=%d\n", count);printf("-----------------------------------【显示学生信息】--------------------------------------------------------\n");sort(count);if (count != 0){printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");for (i = 0; i < count; i++){str[i].counts = i + 1;printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);}}else if (count == 0){sound();printf("当前尚未输入学生信息!\n");}printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************查询信息*************************************/
void fun3()
{int i;char num[20], k = -1;printf("count=%d\n", count);printf("------------------------------------【查询学生信息】-------------------------------------------------------\n");printf("请输入要查找的学号:");scanf("%s", num);printf("查询结果如下:\n");if (count == 0){sound();printf("\t\t您输入的学号不存在.\n");}else if (count != 0){printf("-----------------------------------------------------------------------------------------------------------\n");for (i = 0; i < count; i++){if (strcmp(num, str[i].num) == 0){printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);k = i;}}if (k == -1){sound();printf("\t\t未找到符合条件的学生信息.\n");}}printf("-----------------------------------------------------------------------------------------------------------\n");
}/*************************************保存学生信息(二进制)*************************************/void fun4()
{FILE *fp;int i;printf("count=%d\n", count);printf("-----------------------------------【保存学生信息】-------------------------------------------------------\n");printf("默认保存在:D\\Cworkspace\\学生成绩信息.txt下\n");sort(count);fp = fopen("学生成绩信息.txt", "w");if (fp == NULL){sound();printf("文件打开失败!\n");fp = fopen("学生成绩信息.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的学生信息创建失败,已为您重新建立学生信息。\n");}for (i = 0; i < count; i++){fwrite(&str[i], sizeof(struct student), 1, fp);}fclose(fp);printf("正在保存中\n");talk();printf("信息已保存在:D\\Cworkspace\\学生成绩信息.txt下.\n");printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************打开学生文件信息(二进制)*************************************/
void fun5()
{FILE *fp;int i = 0, flag;printf("-----------------------------------【读取学生信息】--------------------------------------------------------\n");fp = fopen("学生成绩信息.txt", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("学生成绩信息.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的学生信息创建失败,已为您重新建立学生信息。\n");return;}while (1){flag = fread(&str[i], sizeof(struct student), 1, fp);if (flag == 0)break;i++;}count = i;printf("正在读取中\n");talk();printf("从文件中成功读取%d条记录!\n", i);sort(count);printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");for (i = 0; i < count; i++){str[i].counts = i + 1;printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, i + 1);}fclose(fp);printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************保存学生文件信息(文本式)*************************************/
void fun6()
{FILE *fp;int i;printf("-----------------------------------【保存学生信息】--------------------------------------------------------\n");printf("默认保存在:D\\Cworkspace\\学生成绩信息(1).txt下\n");sort(count);fp = fopen("学生成绩信息(1).csv", "w");if (fp == NULL){sound();printf("文件打开失败!\n");fp = fopen("学生成绩信息(1).csv", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的学生信息创建失败,已为您重新建立学生信息。\n");return;}fprintf(fp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", id, name, sex, math, c, eng, score, aver, rank);for (i = 0; i < count; i++){fprintf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);}fclose(fp);printf("正在保存中\n");talk();printf("信息已保存在D\\Cworkspace\\学生成绩信息(1).txt下\n");printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************打开学生文件信息(文本式)*************************************/
void fun7()
{FILE *fp;int i = 0, flag;printf("-----------------------------------【读取学生信息】--------------------------------------------------------\n");fp = fopen("学生成绩信息(1).csv", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("学生成绩信息(1).csv", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的学生信息创建失败,已为您重新建立学生信息。\n");return;}fscanf(fp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", id, name, sex, math, c, eng, score, aver, rank); //读取文件表头while (1){flag = fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, &str[i].math, &str[i].c, &str[i].eng, &str[i].sum, &str[i].aver, &str[i].counts);if (flag == EOF)break;i++;}count = i;printf("正在读取中\n");talk();printf("成功读取%d条记录!\n", count);sort(count); //再次对成绩排序printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");for (i = 0; i < count; i++){str[i].counts = i + 1;printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);}fclose(fp);printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************查询不及格数*************************************/
void fun8()
{FILE *fp;int i = 0, flag, count_s = 0;printf("-----------------------------------【查询不及格数】--------------------------------------------------------\n");printf("注意:{仅从文本式文件中读取学生信息.}\n");fp = fopen("学生成绩信息(1).txt", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("学生成绩信息(1).txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的学生信息创建失败,已为您重新建立学生信息。\n");return;}fscanf(fp, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", id, name, sex, math, c, eng, score, aver, rank); //读取文件表头while (1){flag = fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d", &str[i].num, str[i].name, str[i].sex, &str[i].math, &str[i].c, &str[i].eng, &str[i].sum, &str[i].aver, &str[i].counts);if (flag == EOF)break;i++;}count = i;printf("正在查询中\n");talk();printf("不及格情况如下:\n");printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");for (i = 0; i < count; i++){if (str[i].sum < 180 || str[i].math < 60 || str[i].c < 60 || str[i].eng < 60){ //如果单个成绩小于60总分低于180就记为不及格count_s++;printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);}}printf("不及格人数为:%d人\n", count_s);printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************删除学生信息*************************************/
void fun9()
{int i = 0, j, sum = -1;char num_s[20];char choice[2];char yes[] = {"是"};char no[] = {"否"};printf("-----------------------------------【删除学生信息】--------------------------------------------------------\n");printf("请输入要删除的学生的学号:");scanf("%s", num_s);if (count == 0){sound();printf("\t\t未找到符合条件的学生的信息.\n");}else if (count != 0){for (i = 0; i < count; i++){if (strcmp(num_s, str[i].num) == 0){sum = i;printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);printf("确认要删除该学生信息(是/否):");scanf("%s", choice);if (strcmp(choice, yes) == 0){for (j = i; j < count; j++){str[j] = str[j + 1];}count -= 1; //学生人数减一printf("正在删除中\n");talk();printf("信息删除成功.\n");}else if (strcmp(choice, no) == 0){printf("已返回主菜单.\n");}}}if (sum == -1){sound();printf("\t\t未找到符合条件的学生信息.\n");}}printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************清空文件信息*************************************/
void fun10()
{FILE *fp;char dele[] = {"\n"};char choice_s[2];char yes[] = {"是"};char no[] = {"否"};printf("-----------------------------------【清空学生信息】--------------------------------------------------------\n");printf("请输入要删除的文件名:");scanf("%s", filename);printf("执行此操作将失去文件中的所有数据,是否要清空文件(是/否):");scanf("%s", choice_s);if (strcmp(choice_s, yes) == 0){fp = fopen(filename, "w");if (fp == NULL){sound();printf("您输入的文件名不存在!\n");return;}fprintf(fp, "%s", dele);fclose(fp);printf("正在清除中\n");talk();printf("数据已清空.\n");}else if (strcmp(choice_s, yes) != 0){printf("已返回主菜单\n");}printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************打开信息文件*************************************/
void fun11()
{printf("-----------------------------------【打开信息文件】--------------------------------------------------------\n");printf("正在尝试打开文件");for (i = 0; i < 3; i++){printf("->");Sleep(1000);}printf("\n");system("start 学生成绩信息.txt");system("start 学生成绩信息(1).txt");printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************修改学生信息*************************************/
void fun12()
{int i;int sum = -1;char num_s[20];char choice[4];char yes[] = {"是"};char no[] = {"否"};printf("-----------------------------------【修改学生信息】--------------------------------------------------------\n");printf("请输入要修改的学生的学号:");scanf("%s", num_s);if (count == 0){sound();printf("未找到符合条件的学生信息.\n");}else if (count != 0){for (i = 0; i < count; i++){if (strcmp(num_s, str[i].num) == 0){sum = i;printf("学号\t姓名\t性别\t数学\tc语言\t英语\t总分\t平均分\t\t排名\n");printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);printf("确认要修改该学生信息(是/否):");scanf("%s", choice);if (strcmp(choice, yes) == 0){printf("请输入学号:");scanf("%s", str[i].num);printf("请输入姓名:");scanf("%s", str[i].name);printf("请输入性别:");scanf("%s", str[i].sex);printf("请输入数学成绩:");scanf("%d", &str[i].math);printf("请输入C语言成绩:");scanf("%d", &str[i].c);printf("请输入英语成绩:");scanf("%d", &str[i].eng);str[i].sum = str[i].math + str[i].c + str[i].eng;str[i].aver = str[i].sum / 3;printf("正在导入修改后的信息\n");talk();printf("信息已修改成功.\n");break;}else if (strcmp(choice, no) == 0){printf("已返回主菜单.\n");break;}}}if (sum == -1){sound();printf("未找到符合条件的学生.\n");}}printf("-----------------------------------------------------------------------------------------------------------\n");
}
/*************************************添加学生信息*************************************/
void count_1(int count_m) //添加到二进制文件
{FILE *kp;int i;kp = fopen("学生成绩信息.txt", "a");if (kp == NULL){sound();printf("数据错误!\n");exit(0);}for (i = 0; i < count_m; i++){fwrite(&str[i], sizeof(struct student), 1, kp);}fclose(kp);
}
void count_2(int count_m) //添加到文本式文件
{FILE *lp;int i;lp = fopen("学生成绩信息(1).txt", "a");if (lp == NULL){sound();printf("数据错误!\n");exit(0);}for (i = 0; i < count_m; i++){fprintf(lp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf \t%d\n", str[i].num, str[i].name, str[i].sex, str[i].math, str[i].c, str[i].eng, str[i].sum, str[i].aver, str[i].counts);}fclose(lp);
}
void fun13()
{FILE *fp, *sp;int i = 0, count_m;char com[] = "0";printf("注意:当输入的学号为零时结束该功能.\n");printf("-----------------------------------【添加学生信息】--------------------------------------------------------\n");while (1){printf("开始添加第%d个学生信息\n", i + 1);printf("请输入学号:");scanf("%s", str[i].num);if (strcmp(com, str[i].num) == 0){break;}if (i >= 1){ //判断输入的信息是否重复compare(i);}printf("请输入姓名:");scanf("%s", str[i].name);printf("请输入性别:");scanf("%s", str[i].sex);printf("请输入数学成绩:");scanf("%d", &str[i].math);printf("请输入C语言成绩:");scanf("%d", &str[i].c);printf("请输入英语成绩:");scanf("%d", &str[i].eng);str[i].sum = str[i].math + str[i].c + str[i].eng;str[i].aver = str[i].sum / 3;i++;system("cls");}sort(count);count_m = i;count_1(count_m); //添加信息(二进制)count_2(count_m); //添加信息(文本式)fp = fopen("学生成绩信息.txt", "r");sp = fopen("学生成绩信息(1).txt", "r");if (fp == NULL){sound();printf("数据错误!\n");fp = fopen("学生成绩信息.txt", "w");fclose(fp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}if (sp == NULL){sound();printf("数据错误!\n");sp = fopen("学生成绩信息(1).txt", "w");fclose(sp);printf("可能由于您是初次使用或误删系统文件,导致您的账户信息创建失败,已为您重新建立账户信息。\n");return;}fread(&str[i], sizeof(struct student), 1, fp);sort(count);fclose(fp);fscanf(sp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%lf\t\t%d", str[i].num, str[i].name, str[i].sex, &str[i].math, &str[i].c, &str[i].eng, &str[i].sum, &str[i].aver, &str[i].counts);sort(count);fclose(sp);printf("正在导入添加的学生信息\n");talk();printf("成功添加了%d个学生信息.\n", count_m);printf("-----------------------------------------------------------------------------------------------------------\n");
}
/********************************************欢迎界面***********************************/
void welcome(char m[])
{int i;system("color 6");for (i = 0; i < (int)strlen(m); i++){Sleep(1);printf("%c", m[i]);}printf("\n");
}
void welcome_s()
{char welcome1[] = {"\t\t\t\t\t欢迎使用学生信息管理系统!"};char explor[] = {"\t\t\t\t为了使您能够有更好的体验,使用前请先阅读新手指南。"};char name[] = {"\t\t\t\t\t作者:往事随风。"};welcome(welcome1);welcome(explor);welcome(name);system("start 有人.mp3");system("pause");system("cls");
}
/**********************************声音提示功能********************************************/
void sound()
{printf("\007");
}
/**********************************主函数(功能实现区)************************************/
int main()
{welcome_s();system("title 学生信息管理系统");system("color f5");loginMenu();loginInteraction();while (1){mainMenu();functionalInteraction();system("pause");system("cls");}return 0;
}

答疑资料qq群:1007576722

基于C语言的学生信息管理系统_(更新版)_(附源码和安装包)_课程设计_☆*往事随風*☆的博客相关推荐

  1. 基于JAVA学生信息管理系统录像演示2021计算机毕业设计源码+系统+数据库+lw文档+部署

    基于JAVA学生信息管理系统录像演示2021计算机毕业设计源码+系统+数据库+lw文档+部署 基于JAVA学生信息管理系统录像演示2021计算机毕业设计源码+系统+数据库+lw文档+部署 本源码技术栈 ...

  2. [源码和文档分享]基于C语言的学生信息管理系统

    一 需求分析 利用c语言的链表或结构体数组实现学生信息的管理,编写有登录界面的学生信息管理系统,可以实现学生信息的录入,显示,删除,排序,统计,文件读写等功能. 二 概要设计 系统功能模块结构如下图所 ...

  3. C语言制作个人通讯录管理系统—超详解(附源码)

    之前利用C语言完成了一个关于个人通讯录管理系统的课题,主要是关于联系人的添加.查找.删除.修改.输出以及文件的写入与读出,还有一个甜点功能-模拟通话,它的实现原理也很容易理解,文章末尾会介绍到. 主框 ...

  4. 赶紧进来看看---C语言实现学生信息管理系统(3.0文件存储版)

    本文主要介绍了将学生信息管理系统改造为文件存储版本- 主要涉及文件操作函数–将学生信息导入文件和从文件读取学生信息到程序中,从而达到数据持久化的效果 文章最后有源码展示 学生信息管理系统1.0静态版- ...

  5. c语言结构体编辑学生成绩管理,C语言基于结构体的学生信息管理系统实现

    宋福英 摘  要: 中国高校为保证学生信息安全,各分院的学生信息都在一个相对封闭的闭环内共享.中国高校在校生人数逐年递增,给高校的信息管理带来不小压力.C语言兼具高级语言和汇编语言的特点,简洁.紧凑. ...

  6. java毕业设计——基于JSP+sqlserver的学生信息管理系统设计与实现(毕业论文+程序源码)——学生信息管理系统

    基于JSP+sqlserver的学生信息管理系统设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于JSP+sqlserver的学生信息管理系统设计与实现,文章末尾附有本毕业设计的论文和源码下 ...

  7. 基于文件操作的学生信息管理系统(含登录验证)

    本人C++大一小白,最近有闲着的时间,就写了个学生信息管理系统,全文件操作,有些地方复杂度太大,还有很大的修改空间. 功能结构图 后期关于成绩修改和信息修改实现没写,思想跟已经实现的修改密码一样,你若 ...

  8. 基于PHP+MySQL的学生信息管理系统(源码)

    项目名称:基于PHP+MySQL的学生信息管理系统 本系统是一个用于管理学生信息的管理系统,包括基本的增删改查,系统使用PHP语言开发,使用MySQL数据库,可以供初学者参考使用. 系统环境 MySQ ...

  9. 学生信息管理系统java的总结,基于Java web的学生信息管理系统

    源码编号:B-E00012  点击查看分类规则 项目类型:Java EE项目(java web项目) 项目名称:基于java web的学生信息管理系统(StudentManagerWeb) 当前版本: ...

最新文章

  1. Jmeter性能测试之while控制器的使用
  2. ExtJS学习笔记3:载入、提交和验证表单
  3. 如何使用Elasticsearch groovy script脚本更新数据
  4. MyBatisPlus条件构造器带条件排序方法orderBy、orderByDesc、orderByAsc使用
  5. 北京大学孙俊教授课题组深度视频研究室招收2021级博士生
  6. python从txt拿取数据_python requests + xpath 获取分页详情页数据存入到txt文件中
  7. 如何保证消息队列里的数据顺序执行?
  8. mysql ascii ord_MySQL ORD()函数使用实例介绍
  9. 单片机练习 - 计时器
  10. 写给音响工程师的科普文章(二)——从模电角度去了解调音台话放
  11. 【FPGA】精品FPGA书籍推荐
  12. matlab元胞数组
  13. 背离意味着趋势正在减弱
  14. Python---猜年龄
  15. 沟通的艺术:看人入里,看出人外 - part 1
  16. 聚焦科技创新产业升级 中国联通和腾讯签署新战略合作协议
  17. mysql @的使用
  18. 镜像与复制有什么区别_开发者如何快速精简容器云镜像?| 技术头条
  19. Chapter7 循环神经网络-2
  20. matlab saber协同仿真,saber中文使用教程SaberSimulink协同仿真

热门文章

  1. Spring注解(包含SpringBoot)
  2. PDF转图片在线怎么操作?几个方法轻松解决
  3. C++程序设计原理与实践 习题答案 第二十一章 第21章习题答案
  4. 用友NC63界面新增按钮实现方法(转)
  5. Android apk动态调式以及UI定位
  6. 数据库中varchar类型 最大长度是多少?
  7. 二十五个顶级PHP模板引擎
  8. Luogu P4933 大师(dp)
  9. vue问题三:element ui的upload组件上传图片成功和移除事件
  10. 2018年高考结束后做什么?当然是学做微信小程序开发啦!