《C语言学生选课系统(代码).pdf》由会员分享,可在线阅读,更多相关《C语言学生选课系统(代码).pdf(21页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、.#include#include#includeint N1,N2;struct studentint num2;char name220;int nelenum50;/所选课程编号int nelen;/所选课程学分和struct student*next;struct course;struct course*head1;struct student*head2;void zhang/从键盘录入课程信息struct course*p1,*p2;N1=0;p1=p2=mallocsizeof;1/21int num1;/课程编号char name120;char major20;char t
2、ype20;int credit;int period;char teacher20;int people;/选此门课程的人数struct course*next;/结构体指针.printf;scanfnum1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher;p1-people=0;head1=NULL;whilenum1!=0N1=N1+1;ifhead1=p1;else p2-next=p1;p2=p1;p1=mallocsizeof;scanfnum1,p1-name1,p1-major,p1-type,&p1-cre
3、dit,&p1-period,p1-teacher;p1-people=0;void zhang1/从文件录入课程信息FILE*fp;char filepath20;struct course*p1,*p2;N1=0;printf;getchar;gets;iffp=fopen=NULL2/21p2-next=NULL;.printf;exit;p1=p2=mallocsizeof;fscanfnum1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher,&p1-people;while!feofN1=N1+1;head1=p1
4、;p2-next=p1;ifelsep2=p1;p1=mallocsizeof;fscanfnum1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher,&p1-people;void load/录入课程信息函数int i;printf;printf;printf;printf;printf;3/21p2-next=NULL;.scanf;switchcase 1:zhang;break;case 2:zhang1;break;case 3:break;void insert/增加课程信息struct course*p0,*p1
5、,*p2;p1=head1;p0=incourse;ifwhilenum1p1-num1&next!=NULLifhead1=p0;p2-next=p0;4/21head1=p0;p0-next=NULL;elsep2=p1;p1=p1-next;ifnum1num1else.p0-next=p1;void delc/删除课程信息struct course*p1,*p2;printf;ifp1-next=p0;elsep0-next=NULL;N1=N1+1;goto end;p1=head1;whilenum1&p1-next!=NULLifhead1=p1-next;p2-next=p1-
6、next;p2=p1;p1=p1-next;ifnum1elseprintf;5/21.N1=N1-1;void managementc/课程信息管理函数struct course*p1;int i,num1;printf;printf;printf;printf;printf;scanf;switchcase 1:p1=mallocsizeof;printf课程编号t 课程名称t 主修t 课程性质t 学分t 课时t 教printf;elseend:;师n;scanfnum1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher;
7、p1-people=0;insert;break;scanf;delc;break;case 2:printf;case 3:break;6/21.void putin/从键盘录入学生信息int i=0;FILE*fp;7/21int i;struct student*p1,*p2;N2=0;p1=p2=mallocsizeof;printf;scanfnum2,p1-name2;p1-nelen=0;fori=0;i p1-nelenumi=0;head2=NULL;whilenum2!=0p2-next=NULL;N2=N2+1;ifhead2=p1;p2-next=p1;elsep2=p
8、1;p1=mallocsizeof;scanfnum2,p1-name2;p1-nelen=0;fori=0;i p1-nelenumi=0;void putin2/从文件录入学生信息.char filepath20;struct student*p1,*p2;N2=0;printf;getchar;gets;iffp=fopen=NULLp1=p2=mallocsizeof;freadp1,sizeof,1,fp;head2=NULL;while!feofp2-next=NULL;i=0;N2=N2+1;ifhead2=p1;p2-next=p1;elsep2=p1;p1=mallocsiz
9、eof;freadp1,sizeof,1,fp;printf;exit;void input/录入学生信息函数int i;8/21.printf;printf;printf;printf;printf;scanf;switchcase 1:putin;break;case 2:putin2;break;case 3:break;void inserts/增加学生信息struct student*p0,*p1,*p2;p1=head2;p0=incouse;ifelsewhilenum2p1-num2&next!=NULLifnum2 num29/21head2=p0;p0-next=NULL;
10、p2=p1;p1=p1-next;.elsep1-next=p0;p0-next=NULL;if head2=p0;else p2-next=p0;p0-next=p1;N2=N2+1;void dels/删除学生信息struct student*p1,*p2;ifp1=head2;whilenum2&p1-next!=NULLifnum2ifhead2=p1-next;else10/21printf;goto end;p2=p1;p1=p1-next;.p2-next=p1-next;printf;N2=N2-1;elseprintf;end:;void managements/学生信息管理
11、函数struct student*p1;int i,num2;printf;printf;printf;printf;printf;scanf;switchcase 1:p1=mallocsizeof;p1-nelen=0;p1-nelenum0=0;printf;scanfnum2,p1-name2;inserts;break;scanf;dels;break;case 2:printf;case 3:break;11/21.void elect/学生选课struct student*s;struct course*p;int a,i,b;printf;scanf;s=head2;while
12、num2!=a&s-next!=NULL s=s-next;ifnum2!=aifnelen10printf;scanf;fori=0;nelenumi=0;i+;s-nelenumi=b;p=head1;whilenum1!=bp=p-next;fori=0;nelenumi!=0;i+;s-nelenumi=b;people+;12/21printf;goto end;printf;goto end;.nelen=nelen+credit;people+;end:;void back/学生退课void elective/学生选课信息管理13/21struct student*p;struc
13、t course*p1;int b,i,j,a;printf;scanf;p=head2;whilenum2!=a&p!=NULL p=p-next;ifprintf;scanf;p1=head1;whilenum1!=b p1=p1-next;fornelenumi!=b;i+;fornelenumj!=0;j+p-nelenumj=p-nelenumj+1;p-nelenum-j=0;nelen=nelen-credit;people-;printf;printf;else.void listc/浏览课程信息void lists/浏览学生信息14/21int i;printf;printf
14、;printf;printf;printf;scanf;switchcase 1:elect;break;case 2:back;break;case 3:break;struct course*p;p=head1;printf课程编号课程名称主修课程性质学分课时whileprintfnum1,p-name1,p=p-next;教师选课人数n;p-major,p-type,p-credit,p-period,p-teacher,p-people;.struct student*p;int a;p=head2;printf学生编号学生姓名所选课程编号所选课程学分whileprintfnum2,p
15、-name2;printfnelen;fornelenuma!=0&aprintfnelenuma;printf;p=p-next;n;void intoc/存储课程信息FILE*fp;struct course*p;char filepath30;printf;getchar;gets;iffp=fopen=NULLp=head1;while15/21printf;exit;.void intos/存储学生信息void into/信息存储函数16/21fprintfnum1,p-name1,p-major,p-fclose;printf;p=p-next;type,p-credit,p-pe
16、riod,p-teacher,p-people;FILE*fp;struct student*p;char filepath30;printf;getchar;gets;iffp=fopen=NULLp=head2;whilefclose;printf;fwritep,sizeof,1,fp;p=p-next;printf;exit;.int i;printf;printf;printf;printf;printf;scanf;switchcase:intoc;break;case:intos;break;case:break;void storeint i;printf;printf;pri
17、ntf;printf;printf;printf;scanf;switchcase:listc;break;case:lists;break;case:into;break;case:break;17/21/信息存储浏览函数.void search1/按学生编号查找学生信息void search2/按学生姓名查找学生信息int b;char name20;struct student*p;printf;scanf;p=head2;printf;18/21int a,b;struct student*p;printf;scanf;p=head2;printf;whileifnum2=ap=p-n
18、ext;printfnum2,p-name2;fornelenumb!=0&bprintfnelenumb;printfnelen;.whileifstrcmpname2=0p=p-next;printfnum2,p-name2;fornelenumb!=0&bprintfnelenumb;printfnelen;void search/学生信息查找主函数char m;int i;int i;printf;printf;printf;printf;printf;scanf;switchcase 1:search1;break;case 2:search2;break;case 3:break;
19、void main/主函数start:19/21.printf;printf;printf;printf;printf;printf;printf;printf;printf;printf;printf;printf;printf;printf;scanf;ifscanfifi8ifscanfswitchcase 1:system;load;goto start;break;20/21printf;goto start;printf;goto start;.case 2:system;managementc;goto start;break;case 3:system;input;goto start;break;case 4:system;managements;goto start;break;case 5:system;elective;goto start;break;case 6:system;store;goto start;break;case 7:system;search;goto start;break;case 8:system;printf;21/21