精选文库PAGE\*MERGEFORMAT##include#include#includeintN1,N2;structstudentintnum2;charname2[20];intnelenum[50];//所选课程编号intnelen;//所选课程学分和structstudent*next;};structcourseintnum1;//课程编号structcourse*next;//结构体指针charname1[20];charmajor[20];chartype[20];intcredit;intperiod;charteacher[20];intpeople;//选此门课程的人数};structcourse*head1;structstudent*head2;voidzhang()//从键盘录入课程信息structcourse*p1,*p2;N1=0;p1=p2=(structcourse*)malloc(sizeof(structcourse));printf("课程编号\t课程名称\t主修\t课程性质\t学分\t课时\t教师\n");seanf("%d%s%s%s%d%d%s",&p1->num1,p1->namel,p1->major,p1->type,&p1->credit,&p1->period,p1->teacher);p1->people=0;head仁NULL;while(p1->num1!=0){N1=N1+1;if(N1==1)head1=p1;elsep2->next=p1;p2=p1;p1=(structcourse*)malloc(sizeof(structcourse));seanf("%d%s%s%s%d%d%s",&p1->num1,p1->namel,p1->major,p1->type,&p1->credit,&p1->period,p1->teacher);p1->people=0;//从文件录入课程信息p2->next=NULL;voidzhang1()FILE*fp;charfilepath[20];structcourse*p1,*p2;N1=0;printf("请输入您要读取的路径:");getchar();gets(filepath);if((fp=fopen(filepath,"r"))==NULL)printf("找不到%s文件!\n",filepath);exit(O);p1=p2=(structcourse*)malloc(sizeof(structcourse));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(fp))N1=N1+1;if(N1==1)head仁p1;elsep2->next=p1;p2=p1;p1=(structcourse*)malloc(sizeof(structcourse));fscanf(fp,"%d%s%s%s%d%d%s%d",&p1->num1,p1->namel,p1->major,p1->type,&p1->credit,&p1->period,p1->teacher,&p1->people);p2->next=NULL;voidload()〃录入课程信息函数inti;printf("\t\t\t录入课程信息\n");printf("\n1.从键盘录入");printf("\n2.从文件录入");printf("\n3.返回主菜单\n");printf("请选择1-3:");scanf("%d",&i);switch(i)case1:zhang();break;case2:zhang1();break;//增加课程信息case3:break;voidinsert(structcourse*incourse)structcourse*p0,*p1,*p2;p1=head1;p0=incourse;if(head1==NULL)head仁p0;p0->next=NULL;elsewhile((p0->num1>p1->num1)&&(p1->next!=NULL))p2=p1;p仁p1->next;if(p0->num1v=p1->num1)if(head1==p1)head仁p0;elsep2->next=p0;p0->next=p1;elsep1->next=pO;pO->next=NULL;N1=N1+1;voiddelc(intnum1)//删除课程信息structcourse*p1,*p2;if(head1==NULL)printf("\n无法删除!\n");gotoend;p1=head1;while(num1!=p1->num1&&p1->next!=NULL)p2=p1;p仁p1->next;if(num仁=p1->num1)if(p1==head1)head仁p1->next;elsep2->next=p1->next;printf("已删除\n");N1=N1-1;}elseprintf("没有此课程\n");end:;voidmanagementc()〃课程信息管理函数structcourse*p1;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)case1:{p1=(structcourse*)malloc(sizeof(structcourse));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;break;insert(p1);}case2:printf("请输入您要删除的课程编号:\n");scanf("%d",&num1);delc(num1);break;case3:break;voidputin(void)//从键盘录入学生信息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;i<20;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;i<20;i++)p1->nelenum[i]=0;p2->next=NULL;}voidputin2()//从文件录入学生信息inti=0;FILE*fp;charfilepath[20];structstudent*p1,*p2;N2=0;printf("请输入您要读取的路径:");getcharO;gets(filepath);if((fp=fopen(filepath,"rt"))==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;voidinput()//录入学生信息函数inti;printf("\t\t\t录入学生信息\n");printf("\n1.从键盘录入\n");printf("2.从文件录入\n");printf("3.返回主菜单\n");printf("请输入1-3:\n");seanf("%d",&i);switch(i)ease1:putin();break;ease2:putin2();break;ease3:break;voidinserts(struetstudent*ineouse)II增加学生信息struetstudent*p0,*p1,*p2;p1=head2;p0=ineouse;if(head2==NULL)head2=p0;p0->next=NULL;elsewhile((p0->num2>p1->num2)&&(p1->next!=NULL))p2=p1;p仁p1->next;if(p0->num2<=p1->num2)if(head2==p1)head2=p0;elsep2->next=pO;pO->next=p1;elsep1->next=pO;pO->next=NULL;}II删除学生信息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;p仁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*p1;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)case1:{p1=(structstudent*)malloc(sizeof(structstudent));p1->nelen=0;p1->nelenum[0]=0;printf("num\tname\n");scanf("%d%s",&p1->num2,p1->name2);inserts(p1);}break;case2:{printf("请输入您要删除的学生编号:\n");scanf("%d",&num2);dels(num2);}break;case3:break;voidelect()//学生选课structstudent*s;structcourse*p;inta,i,b;printf("请输入您的学号:\n");scanf("%d",&a);s=head2;while((s->num2)!=a&&s->next!=NULL)s=s->next;if(s->num2!=a)printf("您的信息不存在,请重新输入:\n");gotoend;if((s->nelen)>10)printf("您的学分已满");gotoend;}printf("请输入您要选修的课程编号\n");scanf("%d",&b);for(i=0;(s->nelenum[i])==0;i++);s->nelenum[i]=b;p=head1;while((p->num1)!=b)p=p->next;for(i=0;(s->nelenum[i])!=0;i++);s->nelenum[i]=b;(p->people)++;(s->nelen)=(s->nelen)+(p->credit);(p->people)++;end:;voidback()〃学生退课structstudent*p;structcourse*p1;intb,i,j,a;printf("请输入您的学号:\n");scanf("%d",&a);p=head2;while(p->num2!=a&&p匸NULL)p=p->next;if(p==NULL)printf("您的信息不存在:\n");elseprintf("请输入您要退选的课程:\n");scanf("%d",&b);p1=head1;while(p1->num1!=b)p仁p1->next;for(i=0;p->nelenum[i]!=b;i++);for(j=i;p->nelenum[j]!=0;j++)p->nelenum[j]=p->nelenum[j+1];p->nelenum[T]=0;(p->nelen)=(p->nelen)-(p1->credit);(p1->people)--;printf("succeed!\n");voidelective()〃学生选课信息管理inti;printf("\t\t\t学生选课信息管理\n");printf("1.选课\n");printf("2.退课\n");printf("3.返回主菜单\n");printf("请输入1-3:\n");seanf("%d",&i);switch(i)case1:elect();break;case2:back();break;//浏览课程信息case3:break;voidlistc()structcourse*p;p=head1;printf("课程编号教师选课人数\n");课程名称主修课程性质学分课时while(p!=NULL)printf("%6d%13s%13s%10s%7d%7d%12s%5d\n",p->num1,p->name1,p->major.p->type,p->credit,p->period,p->teacher,p->people);//浏览学生信息p=p->next;voidlists()structstudent*p;inta;p=head2;printf("学生编号学生姓名所选课程编号所选课程学分\n");while(p!=NULL)printf("%6d%13s",p->num2,p->name2);printf("%6d",p->nelen);for(a=0;p->nelenum[a]!=O&&a<14;a++)printf("%d",p->nelenum[a]);printf("\n");〃存储课程信息p=p->next;voidintoc()FILE*fp;structcourse*p;charfilepath[30];printf("输入路径:");getcharO;gets(filepath);if((fp=fopen(filepath,"w"))==NULL)无法储存!");exit(O);p=head1;while(p!=NULL)fprintf(fp,"%d%s%s%s%d%d%s%d\n",p->num1,p->namel,p->major,p->type,p->credit,p->period,p->teacher,p->people);p=p->next;fclose(fp);〃存储学生信息printf("已储存入%s文件!\n",filepath);voidintos(){FILE*fp;structstudent*p;charfilepath[30];printf("请输入路径:");getcharO;gets(filepath);if((fp=fopen(filepath,"wt"))==NULL){printf("\n无法储存!");exit(0);p=head2;while(p!=NULL)fwrite(p,sizeof(structstudent),1,fp);p=p->next;fclose(fp);//信息存储函数printf("已储存入%s文件!\n",filepath);voidinto()inti;printf("\t\t\t信息存储\n");printf("1.课程信息存储\n");printf("2.学生信息存储t\n");printf("3.返回主菜单\n");printf("请输入1-3\n");seanf("%d",&i);switch(i){case(1):intoc();break;case(2):intos();break;case(3):break;voidstore()//信息存储浏览函数inti;printf("\t\t信息存储和浏览\n");printf("1.课程信息浏览\n");printf("2.学生信息浏览\n");printf("3.信息存储\n");printf("4.返回主菜单\n");printf("请输入1-4:\n");scanf("%d",&i);switch(i)case(1):listc();break;case(2):lists();break;case(3):into();break;case(4):break;voidsearch1()//按学生编号查找学生信息inta,b;structstudent*p;printf("请输入学生编号");scanf("%d",&a);p=head2;printf("学号学生姓名所选课程编号所选课程学分\n");while(p!=NULL)if(p->num2==a)printf("%6d%13s”,p->num2,p->name2);for(b=0;p->nelenum[b]!=0&&b<14;b++)printf("%d",p->nelenum[b]);printf("%10d\n",p->nelen);p=p->next;voidsearch2()//按学生姓名查找学生信息intb;charname[20];structstudent*p;printf("请输入要查找的学生姓名:");scanf("%s",name);p=head2;printf("学号学生姓名所选课程编号所选课程学分\n");while(p!=NULL)〃学生信息查找主函数//主函数if(strcmp(name,p->name2)==0){printf("%6d%13s",p->num2,p->name2);for(b=0;p->nelenum[b]!=O&&b<14;b++)printf("%d",p->nelenum[b]);printf("%10d\n",p->nelen);p=p->next;voidsearchOinti;printf("\t\t\t学生信息查找");printf("\n1.按学号查找");printf("\n2.按姓名查找");printf("\n3.返回主菜单");printf("\n请输入1-3:");scanf("%d",&i);switch(i)case1:search1();break;case2:search2();break;case3:break;}}voidmain()charm;inti;start:printf("\t\t\t*****************************\n");printf("\n\t\t\t\t欢迎使用此系统!\n");printf("\t\t\t*****************************\n");printf("\n");printf("\t\t菜单:\n");printf("\t\t\t1.录入课程信息\n");printf("\t\t\t2.课程信息管理\n");printf("\t\t\t3.录入学生信息\n");printf("\t\t\t4.学生信息管理\n");printf("\t\t\t5.学生选课\n");printf("\t\t\t6.信息存储与浏览\n");printf("\t\t\t7.查找学生信息\n");printf("\t\t\t8.退出系统");printf("\t\t\t\n请输入1-8:\n");seanf("%d",&i);if(scanf("%d",&i))if(i<1IIi>8){printf("请重新输入:\n");gotostart;if(scanf("%c",&m)){printf("输入错误,请重新输入:\n");gotostart;switch(i)case1:system("cls");load();gotostart;break;case2:system("cls");managementc();gotostart;break;case3:system("cls");input();gotostart;break;case4:system("cls");managements();gotostart;break;case5:system("cls");elective();gotostart;break;case6:system("cls");store();gotostart;break;case7:system("cls");search();gotostart;break;case8:{system("cls");printf("Thankyou!\n\nBye-Bye!\n");
本文档为【C语言学生选课系统(代码)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。