1、二、数据结构的设计struct person char name20; long num; float math; float English; float chinese; float average; float sum;student;三、模块:学生成绩管理系统模块四、算法的设计1.在此成绩管理系统中,要求用户输入的只是有字符型和数值型数据,所以我设计了下面函数来处理并对输出的数据进行检验。int N=0;Enter() FILE *fp; char ch; char ch2; char numstr20; struct person student2; clrscr(); fp=fop
2、en(jie.txt,ab); if(fp=NULL) printf(cant open this file.nwait for a second with patience.nthe system is exiting.n getch(); exit(0); else doyour name: gets(student.name);nyour num: gets(numstr); student.num=atol(numstr);nyour math: student.math=atof(numstr);nyour English: student.English=atof(numstr);
3、nyour chinese: student.chinese=atof(numstr); student.sum=student.chinese+student.math+student.English; student.average=student.sum/3; fwrite(&student,sizeof(struct person),1,fp); N+;Do you continue adding other students(Y/N)?n ch=getchar(); getchar(); while(ch=y|ch=YShow all(Y/N)? ch2=getchar(); if(
4、ch2=|ch2=) Listall(); fclose(fp); return_confirm();2.查询学生记录当用户执行此查询任务时,系统会提示用户进行查询字段的选择,即按学号或按姓名进行查询。若此学生记录存在,则会打印输出此学生记录的信息。Search() char choice; char ch1; char ch3; char ch4;*WAYS OF SEARCHING*n-n* 1.name *n* 2.num *n-ngive your choice: choice=getchar(); while(choice2|choice1Sorry.your choice is w
5、rong.nplease give a correct one:3.根据姓名或学号进行查找 switch(choice) case :do Loop1:input the name of students you want to search: gets(name); Search1(name);GO ON SEARCHING BY NAEM(Y/N)? while(ch2=Search by other ways(Y/N)? ch3=getchar(); if(ch3=|ch3= goto Loop2; break; Loop2:input the num of students you w
6、ant to search: num=atol(numstr); Search2(num);GO ON SEARCHING BY NUM(Y/N)? ch1=getchar(); while(ch1=|ch1=Search2(long num) int flag=0; int t;rb flag=0; t=0; while(fread(&student,sizeof(struct person),1,fp) if(num=student.num)namettnumtchinesetEnglishtmathsumtaveragen%-10s%-6ld%-8.2f%-8.2f%-8.2f%-8.2
7、f%-8.2fn,student.name,student.num,student.chinese,student.English,student.math,student.sum,student.average); t=1; if(t=0)Sorry.the student you are searching not existed.n rewind(fp); Search1(char *name) if(strcmp(name,student.name)=0) Delete() struct person student130,student230; int i; int k; int j
8、; int flag;rb+ i=0; j=0;input the name of students you are going to delete.n scanf(%s,name);student,sizeof(struct person),1,fp)=1) if(strcmp(name,student.name)!=0) student2j=student; j+; flag=1;nametttnumtchinesettEnglishttmathtsumtaveragen%-10s%-6ld%8.2f%8.2f%8.2f%8.2f%8.2fnDelete(Y/N)? toupper(ch)
9、; if(ch=N goto Loop; j=%dn,j); k=j; if(flag=0) if(flag=1)Congratulation!you succeednwb+student2i,sizeof(struct person),1,fp); i+; while(i6|chSorry.you put is wrong.nplease input another choice: switch(ch)ass_revise(namenum3math4English5chinesetotal ass_revise(Continue revising the same student(Y/N)? fseek(fp,-offset,1);the following is information of student had been revised: while(fread(&student,sizeof(struct person),1,fp);Sorry.the student of reving not existed.nGO ON Revising(Y/N)? if(ch1= goto again;5.对学生记录进行排序Order() float a30,b30,c30,d30; struct person student130;t open t
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1