c语言学生选课系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h#includestring.h#includestdlib.hstructstu{intnum;charname[20];charkind[20];intlhours;intrhours;intcrdit;intscore;intterm;}s[1000],t;intinput(structstus[]);intopenfile(structstus[]);voidoutput(structstus[],intn);intseqsearch1(structstus[],intn,intsearch_score);intseqsearch2(structstus[],intn,charsearch_name[]);voidseqinsert(structstus[],int*len);voidseqdelete(structstus[],int*len);voidrevise(structstus[],intn);voidsort(structstus[],intn);voidsave(structstus[],intn);voidmain(){intsel,choice;intn,*len=&n,i;intsearch_score;charsearch_name[20];charmessage[]={*********************************************************************************************\n*****************************************************欢迎使用西安理工大学选课系统************\n本系统是一个学生选课系统,您可以在本系统中实现\n课程信息的输入,浏览,查找,存入,删除,修改,\n排序,保存等操作******************************\n};charmenu[]={88888888888888888888888888888888888888888888888888\n88888888888888888888888888888888888888888888888888\n*1.输入课程信息\n*2.浏览课程信息\n*3.查找课程信息\n*4.插入课程信息\n*5.删除课程信息\n*6.修改课程信息\n*7.课程信息排序\n*8.存盘\n*9.退出\n88888888888888888888888888888888888888888888888888\n};printf(%s,message);do{printf(%s,menu);printf(请在1--9中选择\n);scanf(%d,&sel);switch(sel){case1:printf(1---键盘输入\n);printf(2---文件载入\n);printf(请选择1或2\n);scanf(%d,&choice);switch(choice){case1:n=input(s);break;case2:n=openfile(s);break;}break;case2:output(s,n);break;case3:do{printf(1----------按照学分查找------\n);printf(2----------按照课程名查找----\n);printf(0----------返回上一级菜单----\n);printf(请选择\n);scanf(%d,&choice);switch(choice){case1:printf(请输入学分\n);scanf(%d,&search_score);i=seqsearch1(s,n,search_score);if(i==-1)printf(无此学分相应课程);else{printf(8888888888888);printf(i=%d,i);printf(查找课程为:\n);printf(课程编号%d\n,s[i].num);printf(课程名称%20s\n,s[i].name);printf(课程性质%20s\n,s[i].kind);printf(总学时%d\n,s[i].lhours);printf(授课学时%d\n,s[i].rhours);printf(实验或上机学时%d\n,s[i].crdit);printf(学分%d\n,s[i].score);printf(开课学期%d\n,s[i].term);printf(--------\n);}break;case2:printf(请输入课程名\n);scanf(%s,search_name);i=seqsearch2(s,n,search_name);if(i==-1)printf(无此课程\n);else{printf(8888888888\n);printf(查找的课程为);printf(课程编号%d\n,s[i].num);printf(课程名称%20s\n,s[i].name);printf(课程性质%20s\n,s[i].kind);printf(总学时%d\n,s[i].lhours);printf(授课学时%d\n,s[i].rhours);printf(实验或上机学时%d\n,s[i].crdit);printf(学分%d\n,s[i].score);printf(开课学期%d\n,s[i].term);}break;case9:break;}}while(choice!=0);case4:seqinsert(s,len);break;case5:seqdelete(s,len);break;case6:revise(s,n);break;case7:sort(s,n);break;case8:save(s,n);break;case9:exit(1);}}while(sel!=0);}voidsave(structstus[],intn)/*保存模块*/{inti;FILE*fp1;fp1=fopen(d:\\课程系统表.txt,w);if(fp1==NULL)printf(保存不成功\n);else{for(i=0;in;i++)fprintf(fp1,%d%20s%10d%d%d%d%d,s[i].num,s[i].name,s[i].kind,s[i].lhours,s[i].rhours,s[i].crdit,s[i].score,s[i].term);fclose(fp1);printf(成功保存\n);}}/*输出模块*/voidoutput(structstus[],intn){inti;printf(选修课程信息表\n);printf(\n);for(i=0;i=n-1;i++){printf(课程编号%d\n,s[i].num);printf(课程名称%20s\n,s[i].name);printf(课程性质%20s\n,s[i].kind);printf(总学时%d\n,s[i].lhours);printf(授课学时%d\n,s[i].rhours);printf(实验或上机学时%d\n,s[i].crdit);printf(学分%d\n,s[i].score);printf(开课学期%d\n,s[i].term);}}/*学分查询模块*/intseqsearch1(structstus[],intn,intsearch_score){inti=0;for(i=0;i=n-1;i++)if(s[i].score==search_score)returni;}/*课程名查询模块*/intseqsearch2(structstus[],intn,charsearch_name[]){inti=0;for(i=0;i=n-1;i++)if(strcmp(s[i].name,search_name)==0)returni;}/*修改模块*/voidrevise(structstus[],intn){intk,choice;charkname[20];do{printf(1**********按课程名称修改*******\n);printf(0***********返回上级菜单***********\n);printf(请输入选择\n);scanf(%d,&choice);switch(choice){case1:printf(请输入要修改的课程名称\n);scanf(%s,&kname);k=seqsearch2(s,n,kname);if(k==-1)printf(修改无效\n);else{printf(课程编号);scanf(%d,&s[k].num);printf(课程名称);scanf(%20s,&s[k].name);printf(课程性质);scanf(%20s,&s[k].kind);printf(总学时);scanf(%d,&s[k].lhours);printf(授课学时);scanf(%d,&s[k].rhours);printf(实验或上机学时);scanf(%d,&s[k].crdit);printf(学分);scanf(%d,&s[k].score);printf(开课学期);scanf(%d,&s[k].term);printf(修改成功!\n);}break;case0:break;}}while(choice!=0);}/*删除模块*/voidseqdelete(structstus[],int*len){intj,delete_score,k,choice;chardelete_name[20];if(*len==0)printf(数组以空);else{do{printf(1*********按课程名删除*****\n);printf(0*********返回上级菜单*****\n);printf(请输入选择\n);scanf(%d,&choice);switch(choice){case1:printf(请输入删除课程的课程名:);scanf(%s,delete_name);k=seqsearch2(s,*len,delete_name);if(k==-1)printf(无效的删除位置\n);else{for(j=k+1;j=*len-1;j++)s[j-1]=s[j];(*len)--;printf(删除成功);}break;case0:break;}}while(choice!=0);}}/*输入模块*/intinput(structstus[]){inti=0,n=0;printf(输入课程编号(为-1时结束));scanf(%d,&s[i].num);while(s[i].num!=-1){printf(课程编号);scanf(%d,&s[i].num);printf(课程名称);scanf(%20s,&s[i].name);printf(课程性质);scanf(%20s,&s[i].kind);printf(总学时);scanf(%d,&s[i].lhours);printf(授课学时);scanf(%d,&s[i].rhours);printf(实验或上机学时);scanf(%d,&s[i].crdit);printf(学分);scanf(%d,&s[i].score);printf(开课学期);scanf(%d,&s[i].term);i++;n++;printf(输入课程编号(为-1时结束));scanf(%d,&s[i].num);}returnn;}/*排序模块*/voidsort(structstus[],intn){inti,j,k;for(i=0;in-1;i++){k=i;for(j=i+1;jn;j++)if(strcmp(s[k].name,s[j].name)0)k=j;if(i!=k){t=

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功