资源描述:
《学生成绩管理系统.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/*学生成绩管理系统*/#include#include#defineSWN3/*课程数*/#defineNAMELEN20/*姓名最大字符数*/#defineCODELEN10/*学号最大字符数*/#defineFNAMELEN80/*文件名最大字符数*/#defineBUFLEN80/*缓冲区最大字符数*//*课程名称表*/charschoolwork[SWN][NAMELEN+1]={"Chinese","Mathematic","English"};structrecord{charname[NAMELEN+1];/*姓名*/c
2、harcode[CODELEN+1];/*学号*/intmarks[SWN];/*各课程成绩*/inttotal;/*总分*/}stu;inttotal[SWN];/*各课程总分*///全局变量//FILE*stfpt;/*文件指针*/charstuf[FNAMELEN];/*文件名*//*从指定文件读入一个记录*/intreadrecord(FILE*fpt,structrecord*rpt){charbuf[BUFLEN];inti;if(fscanf(fpt,"%s",buf)!=1)return0;/*文件结束*/strncpy(rpt->name,buf,NAME
3、LEN);fscanf(fpt,"%s",buf);strncpy(rpt->code,buf,CODELEN);for(i=0;imarks[i]);for(rpt->total=0,i=0;itotal+=rpt->marks[i];return1;}/*对指定文件写入一个记录*/writerecord(FILE*fpt,structrecord*rpt){inti;fprintf(fpt,"%s",rpt->name);fprintf(fpt,"%s",rpt->code
4、);for(i=0;imarks[i]);}/*显示学生记录*/displaystu(structrecord*rpt){inti;printf("Name:%s",rpt->name);printf("Code:%s",rpt->code);printf("Marks:");for(i=0;imarks[i]);printf("Total:%4d",rpt->total);}/*计算各单科总
5、分*/inttotalmark(char*fname){FILE*fp;structrecords;intcount,i;if((fp=fopen(fname,"r"))==NULL){printf("Can'topenfile%s.",fname);return0;}for(i=0;i6、*返回记录数*/}/*列表显示学生信息*/voidliststu(char*fname){FILE*fp;structrecords;if((fp=fopen(fname,"r"))==NULL){printf("Can'topenfile%s.",fname);return;}while(readrecord(fp,&s)!=0){displaystu(&s);printf("PressENTERtocontinue...");while(getchar()!='');}fclose(fp);return;}/*按学生姓名查找学生记录*/intretrie
7、vebyn(char*fname,char*key){FILE*fp;intc;structrecords;if((fp=fopen(fname,"r"))==NULL){printf("Can'topenfile%s.",fname);return0;}c=0;while(readrecord(fp,&s)!=0){if(strcmp(s.name,key)==0){displaystu(&s);c++;}}fclose(fp);if(c==0)printf("Thestudent%sisnotinthefi