C语言版学生成绩管理系统
本文实例为大家分享了C语言版学生成绩管理系统的具体代码,供大家参考,具体内容如下
#include#include #include #include #include #include charbuf[255]; charc=14; charpath[]="D:\\data"; chartmp[]="D:\\tmp"; structStudent { charName[20]; charNo[20]; charDept[20]; charClassNo[20]; doubleMath,Chinese,English; doubleAve; boolPass; }students[500]; boolcmp1(Students1,Students2) { returns1.Chinese>s2.Chinese; } boolcmp2(Students1,Students2) { returns1.Math>s2.Math; } boolcmp3(Students1,Students2) { returns1.English>s2.English; } boolcmp4(Students1,Students2) { returns1.Ave>s2.Ave; } //---------------------------------------------------------voidSort(intcmd) /* 1ChineseSort 2MathSort 3EnglishSort 4AveSort */ intSort(intcmd) { Studentstu; FILE*fp=fopen(path,"ab+"); intn,cnt=0; while((n=fread(&stu,sizeof(stu),1,fp)>0)) { students[cnt++]=stu; } fclose(fp); switch(cmd) { case1: std::sort(students,students+cnt,cmp1); break; case2: std::sort(students,students+cnt,cmp2); break; case3: std::sort(students,students+cnt,cmp3); break; case4: std::sort(students,students+cnt,cmp4); break; default: exit(0); } returncnt; } //---------------------------------------------------------PrintTitle() voidPrintTitle() { printf("%-8s%-12s%-12s%-8s%-7s%-7s%-7s%-7s%-s\n","姓名","班级","学号","系院","语文","数学","英语","平均分","及格"); } //---------------------------------------------------------Print(Studentstu) voidPrint(Studentstu) { 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?"是":"否"); } //---------------------------------------------------------PrintNo(charNo[]) voidPrintNo(charNo[]) { Studentstu; intn; boolfind=0; FILE*fp=fopen(path,"ab+");//以ab+方式打开防止data文件不存在时发生错误 while((n=fread(&stu,sizeof(stu),1,fp))>0) { if(!strcmp(stu.No,No)) { find=1; break; } } fclose(fp); if(find) { PrintTitle(); Print(stu); } else puts("未找到!"); } //---------------------------------------------------------PrintClass(charClassNo[]) voidPrintClass(charClassNo[]) { Studentstu; FILE*fp=fopen(path,"ab+"); intn,cnt=0; while((n=fread(&stu,sizeof(stu),1,fp)>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(charDept[]) voidPrintDept(charDept[]) { Studentstu; FILE*fp=fopen(path,"ab+"); intn,cnt=0; while((n=fread(&stu,sizeof(stu),1,fp)>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() voidPrintAll() { Studentstu; FILE*fp=fopen(path,"ab+"); intn,cnt=0; while((n=fread(&stu,sizeof(stu),1,fp)>0)) { if(cnt==0) PrintTitle(); Print(stu); cnt++; } fclose(fp); if(cnt==0) puts("无数据"); else printf("共%d条\n",cnt); } //---------------------------------------------------------Input() StudentInput() { Studentstu; puts("请输入姓名、班级、学号、系院:"); scanf("%s%s%s%s",&stu.Name,&stu.ClassNo,&stu.No,&stu.Dept); puts("请输入各科成绩:语文、数学、英语"); scanf("%lf%lf%lf",&stu.Chinese,&stu.Math,&stu.English); stu.Ave=(stu.Chinese+stu.Math+stu.English)/3; if(stu.Chinese>=60&&stu.Math>=60&&stu.English>=60) stu.Pass=1; else stu.Pass=0; returnstu; } //---------------------------------------------------------Insert() voidInsert() { intcmd; do{ Studentstu=Input(); FILE*fp=fopen(path,"ab+"); fwrite(&stu,sizeof(stu),1,fp); fclose(fp); puts("录入成功"); puts("继续录入吗?[1]是[0]否"); scanf("%d",&cmd); }while(cmd==1); } //---------------------------------------------------------Del() voidDel() { intcmd,cmd2; charNo[20]; do{ puts("请输入要删除的学号:"); scanf("%s",&No); Studentstu; FILE*fp=fopen(path,"ab+"); FILE*fp2=fopen(tmp,"wb"); intn,find=0; while((n=fread(&stu,sizeof(stu),1,fp))>0) { if(!strcmp(stu.No,No)) { find=1; Print(stu); puts("确定要删除吗?[1]确定[0]取消"); scanf("%d",&cmd2); if(cmd2==1) puts("已删除"); else fwrite(&stu,sizeof(stu),1,fp2); } else fwrite(&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",&cmd); }while(cmd==1); } //---------------------------------------------------------Change() voidChange() { intcmd; charNo[20]; do{ puts("请输入要更改的学号:"); scanf("%s",&No); Studentstu; intfind=0; FILE*fp=fopen(path,"ab+"); FILE*fp2=fopen(tmp,"wb"); intn; while((n=fread(&stu,sizeof(stu),1,fp))>0) { if(!strcmp(stu.No,No)) { find=1; stu=Input(); fwrite(&stu,sizeof(stu),1,fp2); } else fwrite(&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",&cmd); }while(cmd==1); } //---------------------------------------------------------AboutCourse voidChinese() { doublesum=0,ave; intpass=0,fail=0,better=0; Studentstu; FILE*fp=fopen(path,"ab+"); intn,cnt=Sort(1); while((n=fread(&stu,sizeof(stu),1,fp))>0) { sum+=stu.Chinese; if(stu.Chinese>=60) { pass++; if(stu.Chinese>=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(inti=0;i 0) { sum+=stu.Math; if(stu.Math>=60) { pass++; if(stu.Math>=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(inti=0;i 0) { sum+=stu.English; if(stu.English>=60) { pass++; if(stu.English>=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(inti=0;i 0) { sum+=stu.Chinese; sum+=stu.Math; sum+=stu.English; } puts("平均成绩分析……"); printf("%-8s%-10s%-12s%-s\n","名次","姓名","学号","平均成绩"); for(inti=0;i 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。