运维开发网

c语言版的学生成绩管理系统

运维开发网 https://www.qedev.com 2022-05-06 16:05 出处:网络
本文将C语言版学生成绩管理系统的具体代码分享给大家,供大家参考。具体内容如下


本文将C语言版学生成绩管理系统的具体代码分享给大家,供大家参考。具体内容如下

#includelt;stdio.hgt; #includelt;stdlib.hgt; #includelt;time.hgt; #includelt;conio.hgt; #includelt;string.hgt; #includelt;algorithmgt; char buf[255]; char c=14; char path[]="D:\\data"; char tmp[]="D:\\tmp"; struct Student { char Name; char No[20]; char Dept[20]; char ClassNo[20]; double Math,Chinese,English; double Ave; bool Pass; }students[500]; bool cmp1(Student s1,Student s2) { return s1.Chinesegt;s2.Chinese; } bool cmp2(Student s1,Student s2) { return s1.Mathgt;s2.Math; } bool cmp3(Student s1,Student s2) { return s1.Englishgt;s2.English; } bool cmp4(Student s1,Student s2) { return s1.Avegt;s2.Ave; } //---------------------------------------------------------void Sort(int cmd) /* 1 ChineseSort 2 MathSort 3 EnglishSort 4 AveSort */ int Sort(int cmd) { Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=0; while((n=fread(amp;stu,sizeof(stu),1,fp)gt;0)) { students[cnt++]=stu; } fclose(fp); switch(cmd) { case 1: std::sort(students,students+cnt,cmp1); break; case 2: std::sort(students,students+cnt,cmp2); break; case 3: std::sort(students,students+cnt,cmp3); break; case 4: std::sort(students,students+cnt,cmp4); break; default: exit(0); } return cnt; } //---------------------------------------------------------PrintTitle() void PrintTitle() { printf("%-8s%-12s%-12s%-8s%-7s%-7s%-7s%-7s%-s\n","姓名","班级","学号","系院","语文","数学","英语","平均分","及格"); } //---------------------------------------------------------Print(Student stu) void Print(Student stu) { printf("%-8s%-12s%-12s%-8s%-7.2lf%-7.2lf%-7.2lf%-7.2lf%-s\n",stu.Name,stu.ClassNo,stu.No,stu.Dept,stu.Chinese,stu.Math,stu.English,stu.Ave,stu.Pass#63;"是":"否"); } //---------------------------------------------------------PrintNo(char No[]) void PrintNo(char No[]) { Student stu; int n; bool find=0; FILE *fp=fopen(path,"ab+");//以ab+方式打开防止data文件不存在时发生错误 while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { if(!strcmp(stu.No,No)) { find=1; break; } } fclose(fp); if(find) { PrintTitle(); Print(stu); } else puts("未找到!"); } //---------------------------------------------------------PrintClass(char ClassNo[]) void PrintClass(char ClassNo[]) { Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=0; while((n=fread(amp;stu,sizeof(stu),1,fp)gt;0)) { if(!strcmp(stu.ClassNo,ClassNo)) { if(cnt==0) PrintTitle(); Print(stu); cnt++; } } fclose(fp); if(cnt==0) puts("无数据"); else printf("共%d条\n",cnt); } //---------------------------------------------------------PrintDept(char Dept[]) void PrintDept(char Dept[]) { Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=0; while((n=fread(amp;stu,sizeof(stu),1,fp)gt;0)) { if(!strcmp(stu.Dept,Dept)) { if(cnt==0) PrintTitle(); Print(stu); cnt++; } } fclose(fp); if(cnt==0) puts("无数据"); else printf("共%d条\n",cnt); } //---------------------------------------------------------PrintAll() void PrintAll() { Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=0; while((n=fread(amp;stu,sizeof(stu),1,fp)gt;0)) { if(cnt==0) PrintTitle(); Print(stu); cnt++; } fclose(fp); if(cnt==0) puts("无数据"); else printf("共%d条\n",cnt); } //---------------------------------------------------------Input() Student Input() { Student stu; puts("请输入姓名、班级、学号、系院:"); scanf("%s%s%s%s",amp;stu.Name,amp;stu.ClassNo,amp;stu.No,amp;stu.Dept); puts("请输入各科成绩:语文、数学、英语"); scanf("%lf%lf%lf",amp;stu.Chinese,amp;stu.Math,amp;stu.English); stu.Ave=(stu.Chinese+stu.Math+stu.English)/3; if(stu.Chinesegt;=60amp;amp;stu.Mathgt;=60amp;amp;stu.Englishgt;=60) stu.Pass=1; else stu.Pass=0; return stu; } //---------------------------------------------------------Insert() void Insert() { int cmd; do{ Student stu=Input(); FILE *fp=fopen(path,"ab+"); fwrite(amp;stu,sizeof(stu),1,fp); fclose(fp); puts("录入成功"); puts("继续录入吗?[1]是[0]否"); scanf("%d",amp;cmd); }while(cmd==1); } //---------------------------------------------------------Del() void Del() { int cmd,cmd2; char No[20]; do{ puts("请输入要删除的学号:"); scanf("%s",amp;No); Student stu; FILE *fp=fopen(path,"ab+"); FILE *fp2=fopen(tmp,"wb"); int n,find=0; while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { if(!strcmp(stu.No,No)) { find=1; Print(stu); puts("确定要删除吗?[1]确定[0]取消"); scanf("%d",amp;cmd2); if(cmd2==1) puts("已删除"); else fwrite(amp;stu,sizeof(stu),1,fp2); } else fwrite(amp;stu,sizeof(stu),1,fp2); } fclose(fp); fclose(fp2); if(find==0) { printf("未找到学号%s\n",No); remove(tmp); } else { remove(path); rename(tmp,path); } puts("继续删除吗?[1]是[0]否"); scanf("%d",amp;cmd); }while(cmd==1); } //---------------------------------------------------------Change() void Change() { int cmd; char No[20]; do{ puts("请输入要更改的学号:"); scanf("%s",amp;No); Student stu; int find=0; FILE *fp=fopen(path,"ab+"); FILE *fp2=fopen(tmp,"wb"); int n; while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { if(!strcmp(stu.No,No)) { find=1; stu=Input(); fwrite(amp;stu,sizeof(stu),1,fp2); } else fwrite(amp;stu,sizeof(stu),1,fp2); } fclose(fp); fclose(fp2); if(find) { remove(path); rename(tmp,path); puts("更改成功!"); } else { printf("未找到学号%s\n",No); remove(tmp); } puts("继续更改吗?[1]是[0]否"); scanf("%d",amp;cmd); }while(cmd==1); } //---------------------------------------------------------AboutCourse void Chinese() { double sum=0,ave; int pass=0,fail=0,better=0; Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=Sort(1); while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { sum+=stu.Chinese; if(stu.Chinesegt;=60) { pass++; if(stu.Chinesegt;=80) better++; } else fail++; } ave=sum/cnt; puts("语文成绩分析……"); printf("共有%d学生\n优秀:%d人\n及格:%d人\n不及格:%d人\n及格率:%.2lf%%\n",cnt,better,pass,fail,100.0*pass/cnt); printf("%-8s%-10s%-12s%-s\n","名次","姓名","学号","语文"); for(int i=0;ilt;cnt;i++) { printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].Chinese); } printf("平均分:%.2lf\n",ave); } void Math() { double sum=0,ave; int pass=0,fail=0,better=0; Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=Sort(2); while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { sum+=stu.Math; if(stu.Mathgt;=60) { pass++; if(stu.Mathgt;=80) better++; } else fail++; } ave=sum/cnt; puts("数学成绩分析……"); printf("共有%d学生\n优秀:%d人\n及格:%d人\n不及格:%d人\n及格率:%.2lf%%\n",cnt,better,pass,fail,100.0*pass/cnt); printf("%-8s%-10s%-12s%-s\n","名次","姓名","学号","数学"); for(int i=0;ilt;cnt;i++) { printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].Math); } printf("平均分:%.2lf\n",ave); } void English() { double sum=0,ave; int pass=0,fail=0,better=0; Student stu; FILE *fp=fopen(path,"ab+"); int n,cnt=Sort(3); while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { sum+=stu.English; if(stu.Englishgt;=60) { pass++; if(stu.Englishgt;=80) better++; } else fail++; } ave=sum/cnt; puts("英语成绩分析……"); printf("共有%d学生\n优秀:%d人\n及格:%d人\n不及格:%d人\n及格率:%.2lf%%\n",cnt,better,pass,fail,100.0*pass/cnt); printf("%-8s%-10s%-12s%-s\n","名次","姓名","学号","英语"); for(int i=0;ilt;cnt;i++) { printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].English); } printf("平均分:%.2lf\n",ave); } void Average() { Student stu; int n,cnt=Sort(4); double sum=0; FILE *fp=fopen(path,"ab+"); while((n=fread(amp;stu,sizeof(stu),1,fp))gt;0) { sum+=stu.Chinese; sum+=stu.Math; sum+=stu.English; } puts("平均成绩分析……"); printf("%-8s%-10s%-12s%-s\n","名次","姓名","学号","平均成绩"); for(int i=0;ilt;cnt;i++) { printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].Ave); } printf("平均分:%.2lf\n",sum/cnt/3); } //---------------------------------------------------------Search() void Search() { int cmd,cmd2; while(1) { system("cls"); puts("[1] 按学号查询"); puts("这就是本文的全部内容。希望对大家的学习有帮助,也希望大家能支持一下搜源网。 按班级查询"); puts(" 输出全部"); puts(" 按系别查询"); puts(" 课程分析"); puts("[0] 返回主界面"); scanf("%d",amp;cmd); if(cmd==0) break; switch(cmd) { case 1: { char No[20]; puts("请输入要查询的学号:"); scanf("%s",amp;No); PrintNo(No); } break; case 2: { char ClassNo[20]; puts("请输入要查询班级号:"); scanf("%s",amp;ClassNo); PrintClass(ClassNo); } break; case 3: PrintAll(); break; case 4: { char Dept[20]; puts("请输入要查询的系别:"); scanf("%s",amp;Dept); PrintDept(Dept); } break; case 5: while(1) { puts("[1] 语文成绩分析"); puts("[2] 数学成绩分析"); puts("[3] 英语成绩分析"); puts("[4] 平均成绩分析"); puts("[0] 返回上一级"); scanf("%d",amp;cmd2); if(cmd2==0) break; switch(cmd2) { case 1: Chinese(); break; case 2: Math(); break; case 3: English(); break; case 4: Average(); break; default: puts("不合法指令!"); } } break; default: puts("不合法指令!"); } while(1) { puts("[0] 返回"); puts("[1] 录入"); puts("[2] 删除"); puts("[3] 修改"); scanf("%d",amp;cmd2); if(cmd2==0) break; switch(cmd2) { case 1: Insert(); break; case 2: Del(); break; case 3: Change(); break; default: puts("不合法指令!"); } } } } //---------------------------------------------------------Menu() void ShowMenu1() { int i; puts(""); printf(" "); for(i=0;ilt;14;i++) putchar(c); printf("成绩管理分析系统"); for(i=0;ilt;14;i++) putchar(c); puts(""); printf(" %c %c\n",c,c); printf(" %c 请输入指令 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [0] 退出 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [1] 录入 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [2] 删除 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [3] 查询 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [4] 更改 %c\n",c,c); printf(" %c %c\n",c,c); printf(" "); for(i=0;ilt;44;i++) putchar(c); puts(""); } void ShowMenu2() { int i; puts(""); printf(" "); for(i=0;ilt;14;i++) putchar(c); printf("成绩管理分析系统"); for(i=0;ilt;14;i++) putchar(c); puts(""); printf(" %c %c\n",c,c); printf(" %c 请输入指令 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [0] 退出 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [1] 录入 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [2] 删除 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [3] 查询 %c\n",c,c); printf(" %c %c\n",c,c); printf(" %c [4] 更改 %c\n",c,c); printf(" %c %c\n",c,c); printf(" "); for(i=0;ilt;44;i++) putchar(c); puts(""); } //---------------------------------------------------------void RandColor() void RandColor() { int a,b; char param[20]="color ",param2; do{ a=rand()%16; b=rand()%16; }while(a==b); sprintf(param2,"%x%x",a,b); strcat(param,param2); system(param); } //---------------------------------------------------------main() int main() { int cmd; srand(time(NULL)); for(int i=0;ilt;8;i++) { RandColor(); system("cls"); ShowMenu1(); system("cls"); ShowMenu2(); } system("color 0a"); while(1) { system("cls"); ShowMenu1(); printf("[ ]\b\b"); scanf("%d",amp;cmd); if(cmd==0) break; switch(cmd) { case 1: Insert(); break; case 2: Del(); break; case 3: Search(); break; case 4: Change(); break; default: puts("命令不合法!"); } } return 0; }

[2]


p>

0

精彩评论

暂无评论...
验证码 换一张
取 消