您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > C语言学生信息管理系统(附源码)
学生信息管理系统#includestdio.h#includestdlib.h#includeconio.h#includedos.h#includestring.h#defineLENsizeof(structstudent)#defineFORMAT%-12d%-12s%-13.1f%-13.1f%-13.1f%-13.1f\n#defineDATAstu[i].num,stu[i].name,stu[i].chinese,stu[i].math,stu[i].english,stu[i].sum/**************定义学生成绩结构体***********************/structstudent{intnum;charname[15];floatchinese;floatmath;floatenglish;floatsum;};structstudentstu[50];/************函数声明与简介***************/voidinput();voidshow();voidorder();voiddel();voidmodify();voidmenu();voidinsert();voidtotal();voidsearch();intchcode();/***********主函数****************/intmain(){intn;intlogin=chcode();if(!login){printf(登录失败!\n);return0;}printf(登录成功!\n);menu();scanf(%d,&n);while(n){switch(n){case0:exit(0);case1:input();break;case2:search();break;case3:del();break;case4:modify();break;case5:insert();break;case6:order();break;case7:total();break;case8:show();break;default:printf(输入有误,请重新输入:);break;}getch();menu();scanf(%d,&n);}return0;}/*******自定义函数实现菜单功能******/voidmenu(){system(cls);printf(\t\t|-------------学生信息系统----------|\n);printf(\t\t||\n);printf(\t\t|0.退出系统\t\t\t|\n);printf(\t\t|1.输入记录\t\t\t|\n);printf(\t\t|2.查找记录\t\t\t|\n);printf(\t\t|3.删除记录\t\t\t|\n);printf(\t\t|4.修改记录\t\t\t|\n);printf(\t\t|5.插入记录\t\t\t|\n);printf(\t\t|6.记录排序\t\t\t|\n);printf(\t\t|7.记录个数\t\t\t|\n);printf(\t\t|8.显示记录\t\t\t|\n);printf(\t\t|-----------------------------------|\n\n);printf(\t\t请输入你的操作(0-8):);}/*****录入学生信息**/voidinput(){inti,m=0;charch[2];FILE*fp;/*定义指针文件*/if((fp=fopen(stuData.tet,a+))==NULL){printf(打开文件失败\n);return;}while(!feof(fp)){if(fread(&stu[m],LEN,1,fp)==1)m++;}fclose(fp);if(m==0)printf(没有数据!\n);else{system(cls);show();}if((fp=fopen(stuData.txt,wb))==NULL){printf(打开文件失败\n);return;}for(i=0;im;i++){fwrite(&stu[i],LEN,1,fp);}printf(请确认(y/n):);scanf(%s,ch);while(strcmp(ch,Y)==0||strcmp(ch,y)==0){printf(学号:);scanf(%d,&stu[m].num);for(i=0;im;i++)if(stu[i].num==stu[m].num){printf(此学号已存在!);getch();fclose(fp);return;}printf(姓名:);scanf(%s,stu[m].name);printf(语文成绩:);scanf(%f,&stu[m].chinese);printf(数学成绩:);scanf(%f,&stu[m].math);printf(英语成绩:);scanf(%f,&stu[m].english);stu[m].sum=stu[m].chinese+stu[m].math+stu[m].english;if(fwrite(&stu[m],LEN,1,fp)!=1){printf(保存失败!);getch();}else{printf(%s已保存!\n,stu[m].name);m++;}printf(是否继续?(y/n):);scanf(%s,ch);}fclose(fp);printf(操作成功!\n);}/******自定义查找*/voidsearch(){FILE*fp;intsnum,i,m=0;charch[2];if((fp=fopen(stuData.txt,rb))==NULL){printf(打开文件失败\n);return;}while(!feof(fp))if(fread(&stu[m],LEN,1,fp)==1)m++;fclose(fp);if(m==0){printf(文件无记录!\n);return;}printf(请输入需要查找的学生学号:);scanf(%d,&snum);for(i=0;im;i++)if(snum==stu[i].num){printf(学生数据已找到,确认显示?(y/n));scanf(%s,ch);if(strcmp(ch,Y)==0||strcmp(ch,y)==0){printf(学号姓名语文数学英语总分\t\n);printf(FORMAT,DATA);break;}}if(i==m)printf(查找失败!\n);}/*****自定义删除***/voiddel(){FILE*fp;intsnum,i,j,m=0;charch[2];if((fp=fopen(stuData.tet,r+))==NULL){printf(打开文件失败\n);return;}while(!feof(fp))if(fread(&stu[m],LEN,1,fp)==1)m++;fclose(fp);if(m==0){printf(文件无记录!\n);return;}show();printf(请输入需要删除的学生学号:);scanf(%d,&snum);for(i=0;im;i++){if(snum==stu[i].num){printf(数据已经找到,是否确认删除?(y/n));scanf(%s,ch);if(strcmp(ch,Y)==0||strcmp(ch,y)==0){for(j=i;jm;j++)stu[j]=stu[i];m--;if((fp=fopen(stuData.txt,wb))==NULL){printf(打开文件失败\n);return;}for(j=0;jm;j++)if(fwrite(&stu[j],LEN,1,fp)!=1){printf(对不起,保存失败!\n);getch();}fclose(fp);printf(删除成功!\n);return;}else{printf(取消删除!\n);return;}}}printf(没有找到要删除的信息!\n);}/*******自定义修改函数***/voidmodify(){FILE*fp;inti,j,m=0,snum;if((fp=fopen(stuData.txt,r+))==NULL){printf(打开文件失败\n);return;}while(!feof(fp))if(fread(&stu[m],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==stu[i].sum){printf(学生数据已找到,请修改!\n);printf(name);scanf(%s,stu[i].name);printf(chinese);scanf(%f,&stu[i].chinese);printf(math:);scanf(%f,&stu[i].chinese);printf(english:);scanf(%f,&stu[i].english);printf(modifysuccessful!);stu[i].sum=stu[i].chinese+stu[i].math+stu[i].english;if((fp=fopen(stuData.txt,wb))==NULL){printf(保存失败!);getch();}fclose(fp);return;}}printf(没有找到匹配信息);}/********自定义插入函数****/voidinsert(){FILE*fp;inti,j,k,m=0,snum;if((fp=fopen(stuData.txt,r+))==NULL){printf(打开文件失败\n);return;}while(!feof(fp))if(fread(&stu[m],LEN,1,fp)==1)m++;if(m==0){printf(没有数据!\n);fclose(fp);return;}printf(请输入数据插入的位置:\n);scanf(%d,&snum);for(i=0;im;i++)if(snum==stu[i].num)break;for(j=m-1;ji;j--)stu[j+i]=stu[j];printf(请输入待插入数据信息.\n);printf(学号);scanf(%d,&stu[i+1].num);for(k=0;km;k++)if(stu[k].num==stu[m].num){printf(此学号已存在!);getch();fclose(fp);return;}printf(姓名);scanf(%s,stu[i+1].name);printf(语文成绩:);scanf(%f,&stu[i+1].chinese);printf(数学成绩:);scanf(%f,&stu[i+1].math);printf(英语成绩:);scanf(%f,&stu[i+1].english);stu[i+1].sum=stu[i+1].chinese+stu[i+1].math+stu[i+1].english;if((fp=fopen(stuData.txt,wb))==NULL){printf(打开文件失败\n);return;}for(k=0;k=m;k++)if(fwrite(&stu[k],LEN,1,fp)!=1){printf(保存失败!);getch();return;}printf(插入函数成功!);getch();fclose(fp);}//************自定义排序函数****///voidorder(){FILE*fp;structst
本文标题:C语言学生信息管理系统(附源码)
链接地址:https://www.777doc.com/doc-5422667 .html