C语言版学生成绩管理系统
本文实例为大家分享了C语言版学生成绩管理系统的具体代码,供大家参考,具体内容如下
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、网站制作、昭苏网络推广、小程序制作、昭苏网络营销、昭苏企业策划、昭苏品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供昭苏建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com
#include#include #include #include #include #include char buf[255]; char c=14; char path[]="D:\\data"; char tmp[]="D:\\tmp"; struct Student { char Name[20]; 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.Chinese>s2.Chinese; } bool cmp2(Student s1,Student s2) { return s1.Math>s2.Math; } bool cmp3(Student s1,Student s2) { return s1.English>s2.English; } bool cmp4(Student s1,Student s2) { return s1.Ave>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(&stu,sizeof(stu),1,fp)>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?"是":"否"); } //---------------------------------------------------------PrintNo(char No[]) void PrintNo(char No[]) { Student stu; int n; bool find=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(char ClassNo[]) void PrintClass(char ClassNo[]) { Student stu; FILE *fp=fopen(path,"ab+"); int n,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(char Dept[]) void PrintDept(char Dept[]) { Student stu; FILE *fp=fopen(path,"ab+"); int n,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() void PrintAll() { Student stu; FILE *fp=fopen(path,"ab+"); int n,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() Student Input() { Student stu; 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; return stu; } //---------------------------------------------------------Insert() void Insert() { int cmd; do{ Student stu=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() void Del() { int cmd,cmd2; char No[20]; do{ puts("请输入要删除的学号:"); scanf("%s",&No); Student stu; FILE *fp=fopen(path,"ab+"); FILE *fp2=fopen(tmp,"wb"); int n,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() void Change() { int cmd; char No[20]; do{ puts("请输入要更改的学号:"); scanf("%s",&No); Student stu; int find=0; FILE *fp=fopen(path,"ab+"); FILE *fp2=fopen(tmp,"wb"); int n; 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 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(&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(int i=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(int i=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(int i=0;i 0) { sum+=stu.Chinese; sum+=stu.Math; sum+=stu.English; } puts("平均成绩分析……"); printf("%-8s%-10s%-12s%-s\n","名次","姓名","学号","平均成绩"); for(int i=0;i
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。
网页标题:C语言版学生成绩管理系统
链接URL:http://abwzjs.com/article/gjppsg.html