C语言实现学生选课系统
本文实例为大家分享了C语言实现学生选课系统的具体代码,供大家参考,具体内容如下
#include#include #include #include typedefstructcurr { charname[20];//课程姓名 intnumber;//课程序号 charteacher[20];//课程教师姓名 inttime;//课程课时 intclassroom;//课程教室 structcurr*next;//链表next }curr,*pcurr; typedefstructstu { intnumber;//学生序号 charname[20];//学生姓名 charsex[20];//学生性别 structcurr*choices;//学生选课 structstu*next;//链表next }stu,*pstu; pcurrcreat_curr(pcurrcurr_head);//创建链表,课程信息 pcurrfind_curr(pcurrcurr_head,intnumber);//查找链表,课程信息 pcurradd_curr(pcurrcurr_head,pcurrnew_curr);//课程信息加入链表 voidout_curr(pcurrcurr_head);//输出课程信息 pcurrdel_curr(pcurrcurr_head,pcurrdel_point);//删除课程信息 pstucreat_stu(pstustu_head);//创建链表,学生信息 pstufind_stu(pstustu_head,intnumber);//查找链表,学生信息 pstuadd_stu(pstustu_head,pstunew_stu);//学生信息,加入链表 voidout_stu(pstustu_head);//输出学生信息 pstudel_stu(pstustu_head,pstudel_point);//删除学生信息 pstuchoice_curr(pstustu_head,intnumber1,pcurrcurr_head);//学生选课信息 voidout_choice(pstustu_head);//输出学生选课信息 voidtitle() { printf("\t---------欢迎使用成都信息工程大学--学生选课系统------------\n"); printf("\t---------------------\n"); printf("\t---------1.输入课程信息------------\n"); printf("\t---------2.浏览课程信息------------\n"); printf("\t---------3.删除课程信息------------\n"); printf("\t---------4.输入学生信息------------\n"); printf("\t---------5.浏览学生信息------------\n"); printf("\t---------6.删除学生信息------------\n"); printf("\t---------7.学生选课------------\n"); printf("\t---------8.所有学生选课信息------------\n"); printf("\t---------9.退出程序------------\n"); printf("\t---------------------\n"); printf("\t---------特别鸣谢:网络工程专业刘尚文同学------------\n"); } intmain() { inta,n=0,i; intnumber=0; intnumber1=0; pcurrcurr_head=NULL; pstustu_head=NULL; pcurrnew_curr=NULL; pstunew_stu=NULL; pcurrdel_point=NULL; charchoice[20]; do { system("cls"); title(); printf("请在1-9中选择:"); scanf("%d",&a); switch(a){ case1: system("cls"); new_curr=creat_curr(curr_head); curr_head=add_curr(curr_head,new_curr); break; case2: system("cls"); printf("\t\t---------全部课程信息------------\n"); printf("\t课程姓名\t课程序号\t课程教师姓名\t课程课时\t课程教室\n"); out_curr(curr_head); system("pause"); break; case3: system("cls"); printf("\t课程姓名\t课程序号\t课程教师姓名\t课程课时\t课程教室\n"); out_curr(curr_head); printf("请输入打算删除的课程的序号:\n"); scanf("%d",&number); curr_head=del_curr(curr_head,find_curr(curr_head,number)); printf("删除成功!\n"); system("pause"); break; case4: system("cls"); new_stu=creat_stu(stu_head); stu_head=add_stu(stu_head,new_stu); break; case5: system("cls"); printf("\t\t---------全部学生信息------------\n"); printf("\t学生姓名\t学生学号\t学生性别\n"); out_stu(stu_head); system("pause"); break; case6: system("cls"); printf("请输入打算删除的学生的学号:\n"); scanf("%d",&number); stu_head=del_stu(stu_head,find_stu(stu_head,number)); printf("删除成功!\n"); system("pause"); break; case7: system("cls"); printf("\t学生姓名\t学生学号\t学生性别\n"); out_stu(stu_head); printf("请输入选课同学学号:"); scanf("%d",&number1); choice_curr(stu_head,number1,curr_head); system("pause"); break; ; case8: system("cls"); printf("\t\t\t\t---------全部选课信息------------\n"); printf("\n"); printf("\t学生姓名\t学生学号\t学生性别\t课程姓名\t课程序号\t课程教师姓名\t课程课时\t课程教室\n"); out_choice(stu_head); system("pause"); break; case9: return0; break; } }while(a!=0); return0; } //创建链表,课程信息 pcurrcreat_curr(pcurrcurr_head) { pcurrnew_curr=(pcurr)malloc(sizeof(curr)); printf("\n"); printf("\t\t---------输入课程信息------------\n"); printf("\n"); printf("请输入课程姓名:"); scanf("%s",new_curr->name); printf("请输入课程序号:"); scanf("%d",&new_curr->number); printf("请输入课程教师姓名:"); scanf("%s",new_curr->teacher); printf("请输入课程课时:"); scanf("%d",&new_curr->time); printf("请输入课程教室:"); scanf("%d",&new_curr->classroom); while(find_curr(curr_head,new_curr->number)!=NULL) { printf("此序号已经有数据,请重新输入."); scanf("%d",&new_curr->number); } new_curr->next=NULL; returnnew_curr; } //查找链表 pcurrfind_curr(pcurrcurr_head,intnumber) { if(curr_head==NULL) returnNULL; if(curr_head->number==number) returncurr_head; returnfind_curr(curr_head->next,number); } //课程信息加入链表 pcurradd_curr(pcurrcurr_head,pcurrnew_curr) { if(curr_head==NULL) returnnew_curr; new_curr->next=curr_head; returnnew_curr; } //输出课程信息 voidout_curr(pcurrcurr_head) { while(curr_head) { printf("\t%s\t\t%d\t\t%s\t\t%d\t\t%d\n",curr_head->name,curr_head->number,curr_head->teacher,curr_head->time,curr_head->classroom); curr_head=curr_head->next; } } //删除课程信息 pcurrdel_curr(pcurrcurr_head,pcurrdel_point) { pcurrpoint; if(del_point==NULL) { printf("没有此序号信息,请重新输入!\n"); returncurr_head; } point=NULL; if(del_point==curr_head) { point=curr_head->next; free(curr_head); returnpoint; } point=curr_head; while(point) { if(point->next==del_point) { point->next=del_point->next; free(del_point); returncurr_head; } point=point->next; } } //创建链表,学生信息 pstucreat_stu(pstustu_head) { pstunew_stu=(pstu)malloc(sizeof(stu)); printf("\n"); printf("\t\t---------输入学生信息------------\n"); printf("\n"); printf("请输入学生姓名:"); scanf("%s",new_stu->name); printf("请输入学生学号:"); scanf("%d",&new_stu->number); printf("请输入学生性别:"); scanf("%s",new_stu->sex); while(find_stu(stu_head,new_stu->number)!=NULL) { printf("此学号已经有数据,请重新输入."); scanf("%d",&new_stu->number); } new_stu->choices=NULL; new_stu->next=NULL; returnnew_stu; } //查找链表 pstufind_stu(pstustu_head,intnumber) { if(stu_head==NULL) returnNULL; if(stu_head->number==number) returnstu_head; returnfind_stu(stu_head->next,number); } //学生信息加入链表 pstuadd_stu(pstustu_head,pstunew_stu) { if(stu_head==NULL) returnnew_stu; new_stu->next=stu_head; returnnew_stu; } //输出学生信息 voidout_stu(pstustu_head) { while(stu_head) { printf("\t%s\t\t%d\t\t%s\n",stu_head->name,stu_head->number,stu_head->sex); stu_head=stu_head->next; } } //删除学生信息 pstudel_stu(pstustu_head,pstudel_point) { pstupoint; if(del_point==NULL) { printf("没有此学号信息,请重新输入!\n"); returnstu_head; } point=NULL; if(del_point==stu_head) { point=stu_head->next; free(stu_head); returnpoint; } point=stu_head; while(point) { if(point->next==del_point) { point->next=del_point->next; free(del_point); returnstu_head; } point=point->next; } } //学生选课 pstuchoice_curr(pstustu_head,intnumber1,pcurrcurr_head) { intnumber; pcurrpoint=NULL,point1=NULL; pcurrchoice_point=NULL; pstustu_point=find_stu(stu_head,number1); if(stu_point!=NULL) { printf("\t课程姓名\t课程序号\t课程教师姓名\t课程课时\t课程教室\n"); out_curr(curr_head); printf("请输入所选课程学号:"); scanf("%d",&number); point=find_curr(curr_head,number); if(point!=NULL) { choice_point=(pcurr)malloc(sizeof(curr)); memcpy(choice_point,point,sizeof(curr)); choice_point->next=NULL; if(stu_point->choices==NULL) { stu_point->choices=choice_point; } else { choice_point->next=stu_point->choices; stu_point->choices=choice_point; } printf("恭喜你!选课成功!\n"); returnstu_head; } else { printf("没有所选课程序号!"); returnstu_head; } } else { printf("没有所选学生学号!"); returnstu_head; } } //输出学生选课信息 voidout_choice(pstustu_head) { pcurrpoint=NULL; while(stu_head) { point=stu_head->choices; printf("\t%s\t\t%d\t\t%s\n",stu_head->name,stu_head->number,stu_head->sex); while(point) { printf("\t\t\t\t\t\t\t%s\t\t%d\t\t%s\t\t%d\t\t%d\n",point->name,point->number,point->teacher,point->time,point->classroom); point=point->next; } stu_head=stu_head->next; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。