目录
序
嗨!这里是狐狸~~
一、需求分析说明
二、概要设计说明
三、详细设计说明
1)主函数模块
2)声明模块
3)查询模块
4)输入模块
5)增加模块
6)删除模块
7)插入模块
8)统计模块
9)数据保存
四、总结
视频讲解
序
其实我就是想找一个谈得来,合脾气,在一起舒坦,分开久了有点想念的人,爱情如此,友情同理。
嗨!这里是狐狸~~大家的期末课设要来了吧,有想法做什么了嘛,有没有为此熬夜,有没有为此努力呢,今天,我们来写一个学生成绩管理系统,一方面是让大家复习一下自己学过的知识,一方面是为了给大家的期末课设提供一点思路。前面讲的都是一些项目,不知道现在写一个系统,大家能不能掌握呢?emmm,我们一步一步的来吧,尽量让大家懂得怎么去做一个系统,我写了很多的注释,大家可以根据注释来理解。(代码有点多哈,这次头文件就不放了)
一、需求分析说明本系统实现了学生成绩管理系统所需的相关功能,其中的功能主要分为五项:
1)实现对两个文件数据进行合并生成新文件
2)抽取出三科成绩中有补考的学生并保存在一个新文件
3)对合并后的文件中的数据按总分降序排序(至少采用两种排序方法实现)
4)输入一个学生姓名后能查找到此学生的信息并输出结果
5)要求使用结构体、链或数组等实现上述要求
二、概要设计说明模块调用图:
三、详细设计说明 1)主函数模块调用各功能模块,实现文件合并、查找学生信息、排序等功能。
本模块的主要功能是初始化图形界面,进入主菜单,调用各模块,实现软件功能。
主菜单
void menu() { system("cls"); textcolor(10); gotoxy(10,5); cprintf(" The Students' Grade Management System n"); gotoxy(10,8); cprintf(" *************************Menu********************************n"); gotoxy(10,9); cprintf(" * 1 input record 2 delete record *n"); gotoxy(10,10); cprintf(" * 3 search record 4 modify record *n"); gotoxy(10,11); cprintf(" * 5 insert record 6 count record *n"); gotoxy(10,12); cprintf(" * 7 sort reord 8 save record *n"); gotoxy(10,13); cprintf(" * 9 display record 0 quit system *n"); gotoxy(10,14); cprintf(" *************************************************************n"); }
主函数
void main() { link l; FILE *fp; int select; char ch; int count=0; Node *p,*r; l=(Node*)malloc(sizeof(Node)); if(!l) { printf("n allocate memory failure "); return ; } l->next=NULL; r=l; fp=fopen("C:\student","ab+"); if(fp==NULL) { printf("n=====>can not open file!n"); exit(0); } while(!feof(fp)) { p=(Node*)malloc(sizeof(Node)); if(!p) { printf(" memory malloc failure!n"); exit(0); } if(fread(p,sizeof(Node),1,fp)==1) { p->next=NULL; r->next=p; r=p; count++; } } fclose(fp); printf("n=====>open file sucess,the total records number is : %d.n",count); menu(); while(1) { system("cls"); menu(); p=r; printf("n Please Enter your choice(0~9):"); scanf("%d",&select); if(select==0) { if(saveflag==1) { getchar(); printf("n=====>Whether save the modified record to file?(y/n):"); scanf("%c",&ch); if(ch=='y'||ch=='Y') Save(l); } printf("=====>thank you for useness!"); getchar(); break; } switch(select) { case 1:Add(l);break; case 2:Del(l);break; case 3:Qur(l);break; case 4:Modify(l);break; case 5:Insert(l);break; case 6:Tongji(l);break; case 7:Sort(l);break; case 8:Save(l);break; case 9:system("cls");Disp(l);break; default: Wrong();getchar();break; } } }2)声明模块
函数的声明,以及一些简单的功能实现,这个不好怎么说,自己看注释理解吧!
void printheader() { printf(HEADER1); printf(HEADER2); printf(HEADER3); } void printdata(Node *pp) { Node* p; p=pp; printf(FORMAT,DATA); } void Wrong() { printf("nnnnn***********Error:input has wrong! press any key to continue**********n"); getchar(); } void Nofind() { printf("n=====>Not find this student!n"); } void Disp(link l) { Node *p; p=l->next; if(!p) { printf("n=====>Not student record!n"); getchar(); return; } printf("nn"); printheader(); while(p) { printdata(p); p=p->next; printf(HEADER3); } getchar(); }3)查询模块
通过学号或者姓名查询信息,这里需要指针的基础比较扎实了,初学者可以慢慢来,看不懂也没关系,可以先跟着注释以及书上的知识比对着来。
Node* Locate(link l,char findmess[],char nameornum[]) { Node *r; if(strcmp(nameornum,"num")==0) { r=l->next; while(r) { if(strcmp(r->data.num,findmess)==0) return r; r=r->next; } } else if(strcmp(nameornum,"name")==0) { r=l->next; while(r) { if(strcmp(r->data.name,findmess)==0) return r; r=r->next; } } return 0; } void Qur(link l) { int select; char searchinput[20]; Node *p; if(!l->next) { system("cls"); printf("n=====>No student record!n"); getchar(); return; } system("cls"); printf("n =====>1 Search by number =====>2 Search by namen"); printf(" please choice[1,2]:"); scanf("%d",&select); if(select==1) { stringinput(searchinput,10,"input the existing student number:"); p=Locate(l,searchinput,"num"); if(p) { printheader(); printdata(p); printf(END); printf("press any key to return"); getchar(); } else Nofind(); getchar(); } else if(select==2) { stringinput(searchinput,15,"input the existing student name:"); p=Locate(l,searchinput,"name"); if(p) { printheader(); printdata(p); printf(END); printf("press any key to return"); getchar(); } else Nofind(); getchar(); } else Wrong(); getchar(); }4)输入模块
输入字符串或者分数。
void stringinput(char *t,int lens,char *notice) { char n[255]; do{ printf(notice); scanf("%s",n); if(strlen(n)>lens)printf("n exceed the required length! n"); }while(strlen(n)>lens); strcpy(t,n); } int numberinput(char *notice) { int t=0; do{ printf(notice); scanf("%d",&t); if(t>100 || t<0) printf("n score must in [0,100]! n"); }while(t>100 || t<0); return t; }5)增加模块
增加学生记录,注释已经很清楚了
void Add(link l) { Node *p,*r,*s; char ch,flag=0,num[10]; r=l; s=l->next; system("cls"); Disp(l); while(r->next!=NULL) r=r->next; while(1) { while(1) { stringinput(num,10,"input number(press '0'return menu):"); flag=0; if(strcmp(num,"0")==0) {return;} s=l->next; while(s) { if(strcmp(s->data.num,num)==0) { flag=1; break; } s=s->next; } if(flag==1) { getchar(); printf("=====>The number %s is not existing,try again?(y/n):",num); scanf("%c",&ch); if(ch=='y'||ch=='Y') continue; else return; } else {break;} } p=(Node *)malloc(sizeof(Node)); if(!p) { printf("n allocate memory failure "); return ; } strcpy(p->data.num,num); stringinput(p->data.name,15,"Name:"); p->data.cgrade=numberinput("C language Score[0-100]:"); p->data.mgrade=numberinput("Math Score[0-100]:"); p->data.egrade=numberinput("English Score[0-100]:"); p->data.total=p->data.egrade+p->data.cgrade+p->data.mgrade; p->data.ave=(float)(p->data.total/3); p->data.mingci=0; p->next=NULL; r->next=p; r=p; saveflag=1; } return ; }6)删除模块
删除学生记录
void Del(link l) { int sel; Node *p,*r; char findmess[20]; if(!l->next) { system("cls"); printf("n=====>No student record!n"); getchar(); return; } system("cls"); Disp(l); printf("n =====>1 Delete by number =====>2 Delete by namen"); printf(" please choice[1,2]:"); scanf("%d",&sel); if(sel==1) { stringinput(findmess,10,"input the existing student number:"); p=Locate(l,findmess,"num"); if(p) { r=l; while(r->next!=p) r=r->next; r->next=p->next; free(p); printf("n=====>delete success!n"); getchar(); saveflag=1; } else Nofind(); getchar(); } else if(sel==2) { stringinput(findmess,15,"input the existing student name"); p=Locate(l,findmess,"name"); if(p) { r=l; while(r->next!=p) r=r->next; r->next=p->next; free(p); printf("n=====>delete success!n"); getchar(); saveflag=1; } else Nofind(); getchar(); } else Wrong(); getchar(); } void Modify(link l) { Node *p; char findmess[20]; if(!l->next) { system("cls"); printf("n=====>No student record!n"); getchar(); return; } system("cls"); printf("modify student recorder"); Disp(l); stringinput(findmess,10,"input the existing student number:"); p=Locate(l,findmess,"num"); if(p) { printf("Number:%s,n",p->data.num); printf("Name:%s,",p->data.name); stringinput(p->data.name,15,"input new name:"); printf("C language score:%d,",p->data.cgrade); p->data.cgrade=numberinput("C language Score[0-100]:"); printf("Math score:%d,",p->data.mgrade); p->data.mgrade=numberinput("Math Score[0-100]:"); printf("English score:%d,",p->data.egrade); p->data.egrade=numberinput("English Score[0-100]:"); p->data.total=p->data.egrade+p->data.cgrade+p->data.mgrade; p->data.ave=(float)(p->data.total/3); p->data.mingci=0; printf("n=====>modify success!n"); Disp(l); saveflag=1; } else Nofind(); getchar(); }7)插入模块
void Insert(link l) { link p,v,newinfo; char ch,num[10],s[10]; int flag=0; v=l->next; system("cls"); Disp(l); while(1) { stringinput(s,10,"please input insert location after the Number:"); flag=0;v=l->next; while(v) { if(strcmp(v->data.num,s)==0) {flag=1;break;} v=v->next; } if(flag==1) break; else { getchar(); printf("n=====>The number %s is not existing,try again?(y/n):",s); scanf("%c",&ch); if(ch=='y'||ch=='Y') {continue;} else {return;} } } stringinput(num,10,"input new student Number:"); v=l->next; while(v) { if(strcmp(v->data.num,num)==0) { printf("=====>Sorry,the new number:'%s' is existing !n",num); printheader(); printdata(v); printf("n"); getchar(); return; } v=v->next; } newinfo=(Node *)malloc(sizeof(Node)); if(!newinfo) { printf("n allocate memory failure "); return ; } strcpy(newinfo->data.num,num); stringinput(newinfo->data.name,15,"Name:"); newinfo->data.cgrade=numberinput("C language Score[0-100]:"); newinfo->data.mgrade=numberinput("Math Score[0-100]:"); newinfo->data.egrade=numberinput("English Score[0-100]:"); newinfo->data.total=newinfo->data.egrade+newinfo->data.cgrade+newinfo->data.mgrade; newinfo->data.ave=(float)(newinfo->data.total/3); newinfo->data.mingci=0; newinfo->next=NULL; saveflag=1; p=l->next; while(1) { if(strcmp(p->data.num,s)==0) { newinfo->next=p->next; p->next=newinfo; break; } p=p->next; } Disp(l); printf("nn"); getchar(); }8)统计模块
void Tongji(link l) { Node *pm,*pe,*pc,*pt; Node *r=l->next; int countc=0,countm=0,counte=0; if(!r) { system("cls"); printf("n=====>Not student record!n"); getchar(); return ; } system("cls"); Disp(l); pm=pe=pc=pt=r; while(r) { if(r->data.cgrade<60) countc++; if(r->data.mgrade<60) countm++; if(r->data.egrade<60) counte++; if(r->data.cgrade>=pc->data.cgrade) pc=r; if(r->data.mgrade>=pm->data.mgrade) pm=r; if(r->data.egrade>=pe->data.egrade) pe=r; if(r->data.total>=pt->data.total) pt=r; r=r->next; } printf("n------------------------------the TongJi result--------------------------------n"); printf("C Language<60:%d (ren)n",countc); printf("Math <60:%d (ren)n",countm); printf("English <60:%d (ren)n",counte); printf("-------------------------------------------------------------------------------n"); printf("The highest student by total scroe name:%s totoal score:%dn",pt->data.name,pt->data.total); printf("The highest student by English score name:%s totoal score:%dn",pe->data.name,pe->data.egrade); printf("The highest student by Math score name:%s totoal score:%dn",pm->data.name,pm->data.mgrade); printf("The highest student by C score name:%s totoal score:%dn",pc->data.name,pc->data.cgrade); printf("nnpress any key to return"); getchar(); } void Sort(link l) { link ll; Node *p,*rr,*s; int i=0; if(l->next==NULL) { system("cls"); printf("n=====>Not student record!n"); getchar(); return ; } ll=(Node*)malloc(sizeof(Node)); if(!ll) { printf("n allocate memory failure "); return ; } ll->next=NULL; system("cls"); Disp(l); p=l->next; while(p) { s=(Node*)malloc(sizeof(Node)); if(!s) { printf("n allocate memory failure "); return ; } s->data=p->data; s->next=NULL; rr=ll; while(rr->next!=NULL && rr->next->data.total>=p->data.total) {rr=rr->next;} if(rr->next==NULL) rr->next=s; else { s->next=rr->next; rr->next=s; } p=p->next; } l->next=ll->next; p=l->next; while(p!=NULL) { i++; p->data.mingci=i; p=p->next; } Disp(l); saveflag=1; printf("n =====>sort complete!n"); } 9)数据保存
void Save(link l) { FILE* fp; Node *p; int count=0; fp=fopen("c:\student","wb"); if(fp==NULL) { printf("n=====>open file error!n"); getchar(); return ; } p=l->next; while(p) { if(fwrite(p,sizeof(Node),1,fp)==1) { p=p->next; count++; } else { break; } } if(count>0) { getchar(); printf("nnnnn=====>save file complete,total saved's record number is:%dn",count); getchar(); saveflag=0; } else {system("cls"); printf("the current link is empty,no student record is saved!n"); getchar(); } fclose(fp); }四、总结
好了,这样一个《学生成绩管理系统》就完成了,代码有点多,我开始写的时候也琢磨了很久,单纯了这么给出代码你们能不能理解,所以为此我加了非常多的注释以方便大家的理解,文中说的那些模块本来想写点东西的,但无奈文笔匮乏,没办法希望大家理解,也希望大家可以耐心的看完,而非简单说拿去运行不行就骂UP主这的那得,我希望的是大家都可以真真实实的学到知识,并从中感受到编程的快乐。好了,总得来说还是得感谢大家,在这里希望可以得到大家小小的关注,非常感谢!
后续UP主还会发布更多的项目源码以及学习资料,希望大家可以持续关注,有什么问题可以回帖留言。想要C/C++学习资料以及其他项目的源码的可以加群【1083227756】了解。想要对程序员的未来发展有兴趣的可以关注微信公众号:【狐狸的编码时光】,希望和大家一起学习进步!!!
视频讲解当然忘不了最重要的事,需要视频讲解的同学,可以点击下方链接,讲得很详细,也希望大家可以耐心的观看,不要吝啬一键三连啦!
http:// https://www.bilibili.com/video/BV1s44y1v7SB?share_source=copy_webhttp:// https://www.bilibili.com/video/BV1s44y1v7SB?share_source=copy_web?share_source=copy_web
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)