【C语言编写学生管理系统的代码】

上传人:庄** 文档编号:234828244 上传时间:2022-01-04 格式:DOCX 页数:8 大小:14.79KB
返回 下载 相关 举报
【C语言编写学生管理系统的代码】_第1页
第1页 / 共8页
【C语言编写学生管理系统的代码】_第2页
第2页 / 共8页
【C语言编写学生管理系统的代码】_第3页
第3页 / 共8页
【C语言编写学生管理系统的代码】_第4页
第4页 / 共8页
【C语言编写学生管理系统的代码】_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《【C语言编写学生管理系统的代码】》由会员分享,可在线阅读,更多相关《【C语言编写学生管理系统的代码】(8页珍藏版)》请在金锄头文库上搜索。

1、#include#include#include#include#includestruct student char number21;char name21; int age;char sex3; char birthday8;studentArray100;typedef struct student student;student studentArray100;char putout512=学号,姓名,年龄,性别,出生年月; /为格式化输出做准备int count=0;/函数声明部分void explain();void readfile();void searchStudent()

2、;void modifyStudent();void addStudent();void delStudent();void printAllstudent();void save();void quit();void initial();void initial()FILE *fp;char choice=y;int i=0;fp=fopen(e:students.txt,r);if(!fp)printf(创建文件失败,即将返回n);return ;for(;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+);count=i;/0

3、、说明模块void explain()printf(n 很高兴能为您服务n);printf(n1.进入本系统,请先刷新学生信息,再查训n);printf(n2.您可以根据自己需要的信息键入菜单上的编号n);printf(n3.修改学生信息后记得退出前保存信息,以免信息流失n);printf(n4.在各个子菜单里按提示操作n);printf(n5.谢谢您的使用及支持n);/1、刷新模块void readfile() char *p=students.txt; FILE *fp; int i=0; if(fp=fopen(students.txt,r)=NULL) printf(打开文件%s出错!

4、请按按任意键返回,p); system(pause); return ; while(fscanf(fp,%s %s %d %s %s,&studentArrayi.number,&studentArrayi.name,&studentArrayi.age,&studentArrayi.sex,&studentArrayi.birthday)=5) i+; i=i; fclose(fp); printf(刷新完毕。n); /2、查询模块void searchStudent() int i;int jb; FILE *fp;char studentNumber21;char studentNam

5、e21;int flag=0;fp=fopen(e:students.txt,rb);if(count=0)printf(文件中还没有学生记录,请继续其他操作nn);return ;printf(1.按学号查询n); printf(2.按姓名查询n);printf(3.不查询,退出n);while(1) printf(请选择子菜单编号:); scanf(%d,&jb); flag=0; switch(jb) case 1: printf(请输入要查询的学生的学号:n); scanf(%s,&studentNumber); for(i=0;i=count;i+)if(strcmp(student

6、Number,studentArrayi.number)=0) flag=1;printf(要查找的学生相关信息如下:n);printf(学号 姓名 年龄 性别 出生年月n);printf(%s %8s %7d %4s %8sn,studentArrayi.number,studentArrayi.name,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday);printf(n);printf(n);if(flag=0)printf(没有找到学号为%s的学生n, studentNumber);printf(n);return ;

7、return ;case 2: printf(请输入要查询的学生的姓名:n); fflush(stdin);scanf(%s,&studentName);for(i=0;i=count;i+) if(strcmp(studentArrayi.name,studentName)=0) flag=1;printf(要查找的学生相关信息如下:n);printf(学号 姓名 年龄 性别 出生年月n);printf(%s %8s %7d %4s %8sn,studentArrayi.number,studentArrayi.name,studentArrayi.age,studentArrayi.sex

8、,studentArrayi.birthday);printf(n);printf(n);if(flag=0)printf(没有找到名字为%s的学生n, studentName);printf(n);return ;case 3:return;/3、修改模块void modifyStudent()FILE *fp,*fp2;int flag=0;int i;int a,n;char studentNumber21;/char c;student newdata;fp=fopen(e:students.txt,rb);if(count=0)printf(文件中还没有学生信息,即将退出nn);re

9、turn ;fp2=fopen(e:test.txt,wb);if(!fp2)printf(文件创建失败,即将返回n); return ;printf(输入要修改的学生的学号n);fflush(stdin);scanf(%s,&studentNumber);for(n=0;n=count;n+)if(strcmp(studentArrayn.number,studentNumber)=0)a=n;for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+)if(!strcmp(studentArrayi.number,stud

10、entNumber)flag=1;printf(将要要修改的学生信息:n);printf(%s %8s %7d %4s %8sn,studentArraya.number,studentArraya.name,studentArraya.age,studentArraya.sex,studentArraya.birthday);printf(输入要修改后学生的学号、姓名、年龄、性别、出生年月,中间以空格隔开,回车键结束n);printf( (学号格式:001) (出生年月格式:1995-03) n);fflush(stdin);scanf(%s%s%d%s%s,&newdata.number,

11、&newdata.name,&newdata.age,&newdata.sex,&newdata.birthday);fwrite(&newdata,sizeof(struct student),1,fp2);elsefwrite(&studentArrayi,sizeof(struct student),1,fp2);if(flag=0)printf(没有此人,即将退出nn);return ;fclose(fp);fclose(fp2);fp=fopen(e:students.txt,wb);fp2=fopen(e:test.txt,rb);for(i=0;fread(&studentArr

12、ayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeof(struct student),1,fp); printf(nn);fclose(fp);fclose(fp2);printf(已成功修改该学生信息。n);/4、添加模块void addStudent() FILE *fp;char choice=y;int i=0;fp=fopen(e:students.txt,ab);if(!fp)printf(创建文件失败,即将返回nn);return ;while(choice=y)printf(输入学生学号、 姓名、年龄、性别、出生年月,中间以空格隔开,以回车键结束n);printf( (学号格式:001) (出生年月格式:

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 总结/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号