1、. .学生信息管理系统#include#include#include#include#include#define LEN sizeof(struct student)#define FORMAT %-12d%-12s%-13.1f%-13.1f%-13.1f%-13.1fn#define DATA stui.num,stui.name,stui.chinese,stui.math,stui.english,stui.sum/*定义学生成绩构造体*/struct studentint num;char name15;float chinese;float math;float english
2、;float sum;struct student stu50;/*函数声明与简介*/void input();void show();void order();void del();void modify();void menu();void insert();void total();void search();int chcode();/*主函数*/int main()int n;int login = chcode();if(!login)printf(登录失败!n);return 0;printf(登录成功!n);menu();scanf(%d,&n);while(n)switch(
3、n) case 0: exit(0);case 1: input();break; case 2: search();break; case 3: del();break; case 4: modify();break; case 5: insert();break; case 6: order();break; case 7: total();break; case 8: show();break; default:printf(输入有误,请重新输入:);break;getch();menu();scanf(%d,&n);return 0;/*自定义函数实现菜单功能*/void menu()
4、system(cls);printf(tt|-学生信息系统-|n);printf(tt| |n);printf(tt| 0. 退出系统ttt |n);printf(tt| 1. 输入记录ttt |n);printf(tt| 2. 查找记录ttt |n);printf(tt| 3. 删除记录ttt |n);printf(tt| 4. 修改记录ttt |n);printf(tt| 5. 插入记录ttt |n);printf(tt| 6. 记录排序ttt |n);printf(tt| 7. 记录个数ttt |n);printf(tt| 8. 显示记录ttt |n);printf(tt|-|nn);p
5、rintf(tt请输入你的操作0-8:);/*录入学生信息*/void input()int i,m=0;char ch2;FILE *fp;/*定义指针文件*/if(fp=fopen(stuData.tet,a+)=NULL)printf(翻开文件失败n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;fclose(fp);if(m=0)printf(没有数据!n);elsesystem(cls);show();if(fp=fopen(stuData.txt,wb)=NULL)printf(翻开文件失败n);return;for(i=
6、0;im;i+)fwrite(&stui,LEN,1,fp);printf(请确认(y/n):);scanf(%s,ch);while(strcmp(ch,Y)=0|strcmp(ch,y)=0)printf(学号:);scanf(%d,&stum.num);for(i=0;im;i+)if(stui.num=stum.num)printf(此学号已存在!);getch();fclose(fp);return;printf(XX:);scanf(%s,stum.name);printf(语文成绩:);scanf(%f,&stum.chinese);printf(数学成绩:);scanf(%f,
7、&stum.math);printf(英语成绩:);scanf(%f,&stum.english);stum.sum=stum.chinese+stum.math+stum.english;if(fwrite(&stum,LEN,1,fp)!=1)printf(保存失败!);getch();elseprintf(%s 已保存!n,stum.name);m+;printf(是否继续?y/n:);scanf(%s,ch);fclose(fp);printf(操作成功!n);/*自定义查找*/void search()FILE *fp;int snum,i,m=0;char ch2;if(fp=fo
8、pen(stuData.txt,rb)=NULL)printf(翻开文件失败n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;fclose(fp);if(m=0)printf(文件无记录!n);return;printf(请输入需要查找的学生学号:);scanf(%d,&snum);for(i=0;im;i+)if(snum=stui.num)printf(学生数据已找到,确认显示?y/n);scanf(%s,ch);if(strcmp(ch,Y)=0|strcmp(ch,y)=0)printf(学号XX语文数学英语总分tn);pri
9、ntf(FORMAT,DATA);break;if(i=m)printf(查找失败!n); /*自定义删除*/void del()FILE*fp;int snum,i,j,m=0;char ch2;if(fp=fopen(stuData.tet,r+)=NULL)printf(翻开文件失败n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;fclose(fp);if(m=0)printf(文件无记录!n);return;show();printf(请输入需要删除的学生学号:);scanf(%d,&snum);for(i=0;im;i+)
10、if(snum=stui.num)printf(数据已经找到,是否确认删除?(y/n);scanf(%s,ch);if(strcmp(ch,Y)=0|strcmp(ch,y)=0)for(j=i;jm;j+)stuj=stui;m-;if(fp=fopen(stuData.txt,wb)=NULL)printf(翻开文件失败n);return;for(j=0;jm;j+)if(fwrite(&stuj,LEN,1,fp)!=1)printf(对不起,保存失败!n);getch();fclose(fp);printf(删除成功!n);return;elseprintf(取消删除!n);retur
11、n;printf(没有找到要删除的信息!n);/*自定义修改函数*/void modify()FILE *fp;int i,j,m=0,snum;if(fp=fopen(stuData.txt,r+)=NULL)printf(翻开文件失败n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;if(m=0)printf(文件无记录!n);fclose(fp);return;show();printf(请输入你要修改的的学生学号n);printf(学号是:);scanf(%d,&snum);for(i=0;im;i+)if(snum=stui
12、.sum)printf(学生数据已找到,请修改!n);printf(name);scanf(%s,stui.name);printf(chinese);scanf(%f,&stui.chinese);printf(math:);scanf(%f,&stui.chinese);printf(english:);scanf(%f,&stui.english);printf(modify successful!);stui.sum=stui.chinese+stui.math+stui.english;if(fp=fopen(stuData.txt,wb)=NULL)printf(保存失败!);ge
13、tch();fclose(fp);return;printf(没有找到匹配信息);/*自定义插入函数*/void insert()FILE *fp;int i,j,k,m=0,snum;if(fp=fopen(stuData.txt,r+)=NULL)printf(翻开文件失败n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;if(m=0)printf(没有数据!n);fclose(fp);return;printf(请输入数据插入的位置:n);scanf(%d,&snum);for(i=0;ii;j-)stuj+i=stuj;pri
14、ntf(请输入待插入数据信息.n);printf(学号);scanf(%d,&stui+1.num);for(k=0;km;k+)if(stuk.num=stum.num)printf(此学号已存在!);getch();fclose(fp);return;printf(XX);scanf(%s,stui+1.name);printf(语文成绩:);scanf(%f,&stui+1.chinese);printf(数学成绩:);scanf(%f,&stui+1.math);printf(英语成绩:);scanf(%f,&stui+1.english);stui+1.sum=stui+1.chin
15、ese+stui+1.math+stui+1.english;if(fp=fopen(stuData.txt,wb)=NULL)printf(翻开文件失败n);return;for(k=0;k=m;k+)if(fwrite(&stuk,LEN,1,fp)!=1)printf(保存失败!);getch();return;printf(插入函数成功!);getch();fclose(fp);/*自定义排序函数*/void order()FILE *fp;struct student t;int i=0,j=0,m=0;if(fp=fopen(stuData.txt,r+)=NULL)printf(
16、翻开文件失败!n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;fclose(fp);if(m=0)printf(无记录!n);return;if(fp=fopen(stuData.txt,wb)=NULL)printf(翻开文件失败n);return;for(i=0;im-1;i+)if(fwrite(&stui,LEN,1,fp)!=1)printf(%s 保存失败!n);getch();fclose(fp);printf(操作成功n);/*显示学生总人数*/void total()FILE *fp;int m=0;if(fp=f
17、open(stuData.txt,r+)=NULL)printf(翻开文件失败n);return;while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;if(m=0)printf(文件无记录!n);fclose(fp);return;printf(学生总数为 %d 位!n,m);fclose(fp);/*显示学生信息*/void show()FILE *fp;int i,m=0;fp=fopen(stuData.txt,rb);while(!feof(fp)if(fread(&stum,LEN,1,fp)=1)m+;fclose(fp);printf(学号X
18、X语文数学英语总分tn);for(i=0;im;i+)printf(FORMAT,DATA);int chcode() char pw50,ch;char *syspw = 1234; / 原始密码int i,m = 0; printf(请输入密码:); while(m 0) printf(b b);-i;else if(ch != b) pwi+ = ch;printf(*);pwi = 0;printf(n);if(strcmp(pw,syspw) != 0) printf(密码错误,请重新输入!n);m+;else printf(密码正确!n);system(pause);return 1;printf(连续3次输入错误,退出!n);system(pause);return 0;. .word.zl.