资源描述:
《c语言编写学生管理系统的代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#include#include#includestructstudent{charnumber[21];charname[21];intage;charsex[3];charbirthday[8];}studentArray[100];typedefstructstudentstudent;studentstudentArray[100];charputout[5][12]={"学号","姓名","年龄","性别","出生年月"};//为格式
2、化输出做准备intcount=0;//函数声明部分voidexplain();voidreadfile();voidsearchStudent();voidmodifyStudent();voidaddStudent();voiddelStudent();voidprintAllstudent();voidsave();voidquit();voidinitial();voidinitial(){FILE*fp;charchoice='y';inti=0;fp=fopen("e:\students.txt","r");if(!fp){printf("创建文件失败,即
3、将返回");return;}for(;fread(&studentArray[i],sizeof(structstudent),1,fp)!=0;i++);count=i;}//0、说明模块voidexplain(){printf("很高兴能为您服务");printf("1.进入本系统,请先刷新学生信息,再查训");printf("2.您可以根据自己需要的信息键入菜单上的编号");printf("3.修改学生信息后记得退出前保存信息,以免信息流失");printf("4.在各个子菜单里按提示操作");printf("5.
4、谢谢您的使用及支持");}//1、刷新模块voidreadfile(){char*p="students.txt";FILE*fp;inti=0;if((fp=fopen("students.txt","r"))==NULL){printf("打开文件%s出错!请按按任意键返回",p);system("pause");return;}while(fscanf(fp,"%s%s%d%s%s",&studentArray[i].number,&studentArray[i].name,&studentArray[i].age,&studentArray[i].sex,
5、&studentArray[i].birthday)==5){i++;i=i;}fclose(fp);printf("刷新完毕。");}//2、查询模块voidsearchStudent(){inti;intjb;FILE*fp;charstudentNumber[21];charstudentName[21];intflag=0;fp=fopen("e:\students.txt","rb");if(count==0){printf("文件中还没有学生记录,请继续其他操作");return;}printf("1.按学号查询");printf("2.
6、按姓名查询");printf("3.不查询,退出");while(1){printf("请选择子菜单编号:");scanf("%d",&jb);flag=0;switch(jb){case1:printf("请输入要查询的学生的学号:");scanf("%s",&studentNumber);for(i=0;i<=count;i++){if(strcmp(studentNumber,studentArray[i].number)==0){flag=1;printf("要查找的学生相关信息如下:");printf("学号姓名年龄性别出生年月");pr
7、intf("%s%8s%7d%4s%8s",studentArray[i].number,studentArray[i].name,studentArray[i].age,studentArray[i].sex,studentArray[i].birthday);printf("");printf("");}}if(flag==0){printf("没有找到学号为%s的学生",studentNumber);printf("");return;}return;case2:printf("请输入要查询的学生的姓名:");fflus