您好,欢迎访问三七文档
#includestdio.h#includestdlib.hintN1,N2,kk1,kk2,kk3;structcouse*head1;structstudent*head2;structcouse//课程信息结构体{intnum1;charname1[20];intscore;intnelepeo;//课程已选人数intMelepeo;//课程人数上限structcouse*next;};structstudent//学生信息结构体{intnum2;charname2[20];intnelenum[50];//已选课程编号intnelen;//已选课程数量structstudent*next;};voidMs(){for(kk1=0;kk11100;kk1++)for(kk2=0;kk21200;kk2++)for(kk3=0;kk31200;kk3++);}voidkeyboardc()//录入课程子函数(从键盘录入){structcouse*p1,*p2;N1=0;p1=p2=(structcouse*)malloc(sizeof(structcouse));printf(课程编号\t课程名称\t学分\t课程人数上限\n);scanf(%d%s%d%d,&p1-num1,p1-name1,&p1-score,&p1-Melepeo);p1-nelepeo=0;head1=NULL;while(p1-num1!=0){N1=N1+1;if(N1==1)head1=p1;elsep2-next=p1;p2=p1;p1=(structcouse*)malloc(sizeof(structcouse));scanf(%d%s%d%d,&p1-num1,p1-name1,&p1-score,&p1-Melepeo);p1-nelepeo=0;}p2-next=NULL;}voidfilec()//录入键盘子函数(从文件录入){FILE*fp;charfilepath[20];structcouse*p1,*p2;N1=0;printf(输入要读入的文件路径:);getchar();gets(filepath);if((fp=fopen(filepath,r))==NULL){printf(找不到%s文件!\n,filepath);exit(0);}p1=p2=(structcouse*)malloc(sizeof(structcouse));fscanf(fp,%d%s%d%d%d,&p1-num1,p1-name1,&p1-score,&p1-nelepeo,&p1-Melepeo);head1=NULL;while(!feof(fp)){N1=N1+1;if(N1==1)head1=p1;elsep2-next=p1;p2=p1;p1=(structcouse*)malloc(sizeof(structcouse));fscanf(fp,%d%s%d%d%d,&p1-num1,p1-name1,&p1-score,&p1-nelepeo,&p1-Melepeo);}p2-next=NULL;}voidinputc()//录入课程主函数{inti;printf(\t\t\t录入课程信息\n);printf(\n1.从键盘录入\n);printf(2.从文件录入\n);printf(3.返回主菜单\n);printf(请选择(1~3):\n);scanf(%d,&i);switch(i){case(1):keyboardc();break;case(2):filec();break;case(3):break;}}voidinsertc(structcouse*incouse)//课程管理子函数(增加课程){structcouse*p0,*p1,*p2;p1=head1;p0=incouse;if(head1==NULL){head1=p0;p0-next=NULL;}else{while((p0-num1p1-num1)&&(p1-next!=NULL)){p2=p1;p1=p1-next;}if(p0-num1=p1-num1){if(head1==p1)head1=p0;elsep2-next=p0;p0-next=p1;}else{p1-next=p0;p0-next=NULL;}}N1=N1+1;}voiddelc(intnum1)//课程管理子函数(删除课程){structcouse*p1,*p2;if(head1==NULL){printf(\n没有课程,无法删除!\n);gotoend;}p1=head1;while(num1!=p1-num1&&p1-next!=NULL){p2=p1;p1=p1-next;}if(num1==p1-num1){if(p1==head1)head1=p1-next;elsep2-next=p1-next;printf(已删除该编号课程!\n);N1=N1-1;}elseprintf(无该编号的课程!\n);end:;}voidmanagementc()//课程管理主函数{structcouse*incouse;inti,num1;printf(\t\t\t课程管理\n);printf(1.新增课程\n);printf(2.删除课程\n);printf(3.返回主菜单\n);printf(请选择(1~3):\n);scanf(%d,&i);switch(i){case(1):{incouse=(structcouse*)malloc(sizeof(structcouse));printf(课程编号\t课程名称\t学分\t课程人数上限\n);scanf(%d%s%d%d,&incouse-num1,incouse-name1,&incouse-score,&incouse-Melepeo);incouse-nelepeo=0;insertc(incouse);break;}case(2):{printf(请输入要删除课程的编号:\n);scanf(%d,&num1);delc(num1);break;}case(3):break;}}voidkeyboards()//录入学生信息子函数(从键盘录入){inti;structstudent*p1,*p2;N2=0;p1=p2=(structstudent*)malloc(sizeof(structstudent));printf(学生学号\t学生姓名\n);scanf(%d%s,&p1-num2,p1-name2);p1-nelen=0;for(i=0;i20;i++)p1-nelenum[i]=0;head2=NULL;while(p1-num2!=0){N2=N2+1;if(N2==1)head2=p1;elsep2-next=p1;p2=p1;p1=(structstudent*)malloc(sizeof(structstudent));scanf(%d%s,&p1-num2,p1-name2);p1-nelen=0;for(i=0;i20;i++)p1-nelenum[i]=0;}p2-next=NULL;}voidfiles()//录入学生信息子函数(从文件录入){inti=0;FILE*fp;charfilepath[20];structstudent*p1,*p2;N2=0;printf(输入要读入的文件路径:);getchar();gets(filepath);if((fp=fopen(filepath,r))==NULL){printf(找不到%s文件!\n,filepath);exit(0);}p1=p2=(structstudent*)malloc(sizeof(structstudent));fread(p1,sizeof(structstudent),1,fp);head2=NULL;while(!feof(fp)){i=0;N2=N2+1;if(N2==1)head2=p1;elsep2-next=p1;p2=p1;p1=(structstudent*)malloc(sizeof(structstudent));fread(p1,sizeof(structstudent),1,fp);}p2-next=NULL;}voidinputs()//录入学生信息主函数{inti;printf(\t\t\t录入学生信息\n);printf(\n1.从键盘录入\n);printf(2.从文件录入\n);printf(3.返回主菜单\n);printf(请选择(1~3):\n);scanf(%d,&i);switch(i){case(1):keyboards();break;case(2):files();break;case(3):break;}}voidinserts(structstudent*incouse)//学生信息管理子函数(填加学生信息){structstudent*p0,*p1,*p2;p1=head2;p0=incouse;if(head2==NULL){head2=p0;p0-next=NULL;}else{while((p0-num2p1-num2)&&(p1-next!=NULL)){p2=p1;p1=p1-next;}if(p0-num2=p1-num2){if(head2==p1)head2=p0;elsep2-next=p0;p0-next=p1;}else{p1-next=p0;p0-next=NULL;}}N2=N2+1;}voiddels(intnum2)//学生信息管理子函数(删除学生信息){structstudent*p1,*p2;if(head2==NULL){printf(\n没有该学生信息,无法删除!\n);gotoend;}p1=head2;while(num2!=p1-num2&&p1-next!=NULL){p2=p1;p1=p1-next;}if(num2==p1-num2){if(p1==head2)head2=p1-next;elsep2-next=p1-next;printf(已删除该学生信息!\n);N2=N2-1;}elseprintf(无该学号的学生!\n);end:;}voidmanagements()//学生信息管理主函数{structstudent*incouse;inti,num2;printf(\t\t\t学生信息管理\n);printf(1.新增学生信息\n);printf(2.删除学生信息\n);printf(3.返回主菜单\n);printf(请选择(1~3):\n);scanf(%d,&i);switch(i){case(1):{incouse=(structstudent*)malloc(sizeof(structstudent));incouse-nelen=0;incouse-nelenum[0]=0;printf(学生学号\t学生姓名\n);scanf(%d%s,&incouse-num2,incouse-name2);inserts(incouse);break;}case(2):{printf(请输入要删除学生的学号:\n);scanf(%d,&num2);dels(num2);break;}case(3):break;}}voidelect(structstudent*s)//选课{structcouse*p;intnum1,i;printf(请输入要选课的编号:\n);scanf(%d,&num1);for(i=0;s-nelenum[i]!=0;i++);s-nelenum[i]=num1;(s-nel
本文标题:学生选课系统源代码
链接地址:https://www.777doc.com/doc-4922740 .html