《C语言学生选课系统代码》由会员分享,可在线阅读,更多相关《C语言学生选课系统代码(21页珍藏版)》请在金锄头文库上搜索。
1、-#include#include#includeint N1,N2;struct studentint num2; char name220; int nelenum50; /所选课程编号 int nelen; /所选课程学分和 struct student * ne*t;struct courseint num1; /课程编号char name120; char major20;char type20;int credit;int period;char teacher20;int people; /选此门课程的人数struct course *ne*t; /构造体指针;struct co
2、urse * head1;struct student * head2;void zhang() /从键盘录入课程信息struct course *p1,*p2; N1=0; p1=p2=(struct course *)malloc(sizeof(struct course); printf(课程编号t课程名称t主修t课程性质t学分t课时t教师n); scanf(%d%s%s%s%d%d%s,&p1-num1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher); p1-people=0; head1=NULL; while(
3、p1-num1!=0)N1=N1+1; if(N1=1)head1=p1; else p2-ne*t=p1; p2=p1; p1=(struct course * )malloc(sizeof(struct course); scanf(%d%s%s%s%d%d%s,&p1-num1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher); p1-people=0; p2-ne*t=NULL;void zhang1() /从文件录入课程信息FILE * fp; char filepath20; struct course *p1,
4、*p2; N1=0; printf(请输入您要读取的路径:); getchar(); gets(filepath); if(fp=fopen(filepath,r)=NULL)printf(找不到 %s 文件!n,filepath); e*it(0); p1=p2=(struct course*)malloc(sizeof(struct course); fscanf(fp,%d%s%s%s%d%d%s%d,&p1-num1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher,&p1-people); while(!feof(f
5、p)N1=N1+1; if(N1=1)head1=p1; else p2-ne*t=p1; p2=p1; p1=(struct course * )malloc(sizeof(struct course); fscanf(fp,%d%s%s%s%d%d%s%d,&p1-num1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher,&p1-people); p2-ne*t=NULL;void load() /录入课程信息函数int i;printf(ttt录入课程信息n);printf(n1.从键盘录入);printf(n2.从文
6、件录入);printf(n3.返回主菜单n);printf(请选择1-3:);scanf(%d,&i);switch(i)case 1: zhang(); break; case 2:zhang1();break; case 3:break; void insert(struct course *incourse) /增加课程信息struct course *p0,*p1,*p2; p1=head1; p0=incourse; if(head1=NULL)head1=p0; p0-ne*t=NULL; elsewhile(p0-num1p1-num1) & (p1-ne*t!=NULL)p2=
7、p1; p1=p1-ne*t; if(p0-num1num1)if(head1=p1)head1=p0; elsep2-ne*t=p0; p0-ne*t=p1; elsep1-ne*t=p0; p0-ne*t=NULL; N1=N1+1;void delc(int num1) /删除课程信息struct course *p1,*p2; if(head1=NULL)printf(n无法删除!n); goto end; p1=head1; while(num1!=p1-num1 & p1-ne*t!=NULL) p2=p1; p1=p1-ne*t; if(num1=p1-num1)if(p1=he
8、ad1) head1=p1-ne*t; else p2-ne*t=p1-ne*t; printf(已删除n); N1=N1-1; else printf(没有此课程n); end:;void managementc() /课程信息管理函数struct course * p1; int i,num1; printf(ttt课程信息管理n); printf(1.添加课程n); printf(2.删除课程n); printf(3.返回n); printf(请输入1-3:n); scanf(%d,&i); switch(i) case 1:p1=(struct course *)malloc(size
9、of(struct course);printf(课程编号t课程名称t主修t课程性质t学分t课时t教师n); scanf(%d%s%s%s%d%d%s,&p1-num1,p1-name1,p1-major,p1-type,&p1-credit,&p1-period,p1-teacher);p1-people=0;insert(p1); break;case 2:printf(请输入您要删除的课程编号:n);scanf(%d,&num1);delc(num1); break;case 3:break;void putin(void) /从键盘录入学生信息 int i;struct student
10、 *p1,*p2;N2=0;p1=p2=(struct student *)malloc(sizeof(struct student);printf(*tn);scanf(%d%s,&p1-num2,p1-name2);p1-nelen=0;for(i=0;inelenumi=0;head2=NULL;while(p1-num2!=0)N2=N2+1;if(N2=1)head2=p1;else p2-ne*t=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student);scanf(%d%s,&p1-num2,p1-name2);p1
11、-nelen=0;for(i=0;inelenumi=0;p2-ne*t=NULL;void putin2() /从文件录入学生信息int i=0;FILE * fp;char filepath20;struct student *p1,*p2;N2=0;printf(请输入您要读取的路径:);getchar();gets(filepath);if(fp=fopen(filepath,rt)=NULL)printf(找不到 %s 文件!n,filepath);e*it(0);p1=p2=(struct student*)malloc(sizeof(struct student);fread(p1,sizeof(struct student),1,fp);head2=NULL;while(!feof(fp)i=0;N2=N2+1;if(N2=1)head2=p1;else p2-ne*t=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student);fread(p1,sizeof(struct s