|

楼主 |
发表于 2015-12-21 13:32:20
|
显示全部楼层
本帖最后由 DarkSE 于 2015-12-21 14:01 编辑
整个代码是这样的
243和244行的输出错误
- #include <stdio.h>
- #include <stdlib.h>
- struct link *course_enroll();//课程录入//完成
- struct link *student_enroll();//学生录入//未完成
- void course_skim();//课程信息浏览//完成
- int check();//学分查询
- void event();//课程选修情况//完成
- void check_number();//学号查询
- void deletememory();
- struct student
- {
- int stu_number;
- char stu_name[10];
- int select_number;
- struct student *stu_next;
- }stu;
- struct link
- {
- int number;//课程编号
- char name[10];
- char nature[10];//课程性质
- int time;//总学时
- int time_class;//授课时间
- int score;
- int time_start;//开课时间
- struct student *stu;
- struct link *next;//节点
- };
- main()
- {
- int n,i,a=0;
- struct link *head=NULL;
- struct student *stu_head=NULL;
- do
- {
- system("cls");
- printf("请选择一下功能:\n");
- printf("0->课程信息录入系统\n1->学生选课信息录入系统\n");
- printf("2->课程信息浏览\n3->学分查询\n");
- printf("4->课程选修情况\n5->学号查询功能\n");
- do
- {
- scanf("%d",&n);
- if(n<0 || n>6)
- {
- printf("输入错误,请重新输入:");
- }
- }while(n<0 || n>6);
- switch(n)
- {
- case 0:
- {
- printf("欢迎进入课程信息录入系统:\n");
- printf("请输入录入的课程的门数:\n");
- scanf("%d",&i);
- head=(course_enroll(head,i));
- break;
- }
- case 1:
- {
- printf("欢迎进入学生选课信息录入功能:\n");
- stu_head=student_enroll(head,stu_head);
- break;
- }
- case 2:
- {
- printf("课程信息浏览:\n");
- course_skim(head);
- break;
- }
- case 3:
- {
- printf("学分查询功能:\n");
- check();
- break;
- }
- case 4:
- {
- printf("课程选修情况:\n");
- event(head,stu_head);
- break;
- }
- case 5:
- {
- printf("学号查询功能:\n");
- check_number(head,stu_head);
- break;
- }
- }
- printf("是否退出选课系统?是输入1,否输入0\n");
- scanf("%d",&a);
- if(1==a)
- {
- deletememory(head,stu_head);
- exit(0);
- }
- }while(0==a);
- }
- struct link *course_enroll(struct link *head,int i)//课程录入
- {
- int j=1;
- struct link *p=NULL;
- struct link *pr=head;//指针指向head
- system("cls");//清屏
- printf("请按照以下格式输入课程信息:\n");
- printf("----编号---名称---性质---学时---授课时间---学分---开课学期----\n");
- for(j;j<=i;j++)//输入的课程的数目
- {
- p=(struct link *)malloc(sizeof(struct link));//为struct link申请内存
- if(p==NULL)//检查申请内存是否为空
- {
- printf("系统错误!!");
- exit(0);
- }
- if(head==NULL)//检查head是否为空
- {
- head=p;//head为空,把第一个当做第一个链表
- }
- else//head 不为空
- {
- while (pr->next != NULL)//指向下一个,直到链尾为止
- {
- pr=pr->next;
- }
- pr->next=p;//把申请的内存接在链尾后面
- }
- pr=p;//把空链表指向head
- scanf("%d",&pr->number);
- scanf("%s",&pr->name);
- scanf("%s",&pr->nature);
- scanf("%d",&pr->time);
- scanf("%d",&pr->time_class);
- scanf("%d",&pr->score);
- scanf("%d",&pr->time_start);
- pr->next=NULL;//最后一个的指针域定义为NULL
- }
- return head;
- }
- struct link *student_enroll(struct link *head,struct student *stu_head)//学生录入//学生选择课程的编号进而录入
- {
- int number;
- struct student *pstu=NULL;
- struct student *pstur=stu_head;
- struct link *p=head;
- if(p==NULL)//head是否为空
- {
- printf("NO ANY DATA !!\n");//没有数据可供选课
- }
- else
- {
- printf("请输入选择的课程编号:");
- scanf("%d",&number);
- while(p!=NULL)//
- {
- if( number == p->number )//寻找存在的课程编号
- {
- printf("请输入学生学号及姓名:");
- pstu=(struct student *)malloc(sizeof(struct student));
- if(pstu==NULL)//申请内存为空
- {
- printf("系统错误!!");
- exit(0);
- }
- if(stu_head==NULL)//stu_head为空
- {
- stu_head=pstu;
- }
- else
- {
- while(pstur->stu_next != NULL)//stu_head不为空,寻找到链尾为止
- {
- pstur=pstur->stu_next ;
- }
- pstur->stu_next =pstu;//申请的内存加入链尾
- }
- pstur=pstu;
- scanf("%d",&pstu->stu_number);
- scanf("%s",&pstu->stu_name);
- pstu->stu_next=NULL;//新节点指针域定义为NULL
- break;
- }
- p=p->next ;//当寻找不到符合的课程编号,则指向下一个继续寻找,直到链尾
- }
- }
- return stu_head;
- }
- void course_skim(struct link *head)//课程信息浏览
- {
- struct link *p=head;
- system("cls");
- if(p==NULL)
- {
- printf("NO ANY DATA !!\n");
- }
- else
- {
- printf("----编号---名称---性质---学时---授课时间---学分---开课学期----\n");
- while(p != NULL)
- {
- printf("%d ",p->number);
- printf("%s ",p->name);
- printf("%s ",p->nature);
- printf("%d ",p->time);
- printf("%d ",p->time_class);
- printf("%d ",p->score);
- printf("%d \n",p->time_start);
- p = p->next;
- }
- }
- }
- int check()//学分查询
- {
- printf("stupid 3\n");
- }
- void event(struct link *head,struct student *stu_head)//课程选修情况
- {
- struct link *p=head;
- struct student *pr=stu_head;
- system("cls");
- if(p==NULL)
- {
- printf("NO ANY DATA !!\n");
- }
- else if(pr == NULL)
- {
- printf("学生未进行选课\n");
- }
- else
- {
- //输出课程信息
- printf("----编号---名称---性质---学时---授课时间---学分---开课学期---学生学号---学生姓名----\n");
- while(p != NULL )
- {
- printf("%d ",p->number);
- printf("%s ",p->name);
- printf("%s ",p->nature);
- printf("%d ",p->time);
- printf("%d ",p->time_class);
- printf("%d ",p->score);
- printf("%d ",p->time_start);
- //输出课程里面的学生信息
- printf("%d ",p->stu->stu_number);//通过head来输出学生信息
- printf("%s \n",p->stu->stu_name);
- p = p->next;
- }
- }
- }
- void check_number(struct link *head,struct student *stu_head)//5
- {
- int number;
- struct link *p=head;
- struct student *pr=stu_head;
- system("cls");
- if(p==NULL)
- {
- printf("NO ANY DATA !!\n");
- }
- else if(pr->stu_number == NULL)
- {
- printf("未有选课记录!!\n");
- }
- else
- {
- printf("请输入查询的学生学号:");
- scanf("%d",&number);
- do
- {
- if(number == (pr->stu_number))
- {
- printf("%d ",p->number);
- printf("%s \n",p->name);
- }
- pr=pr->stu_next ;
- }while( pr->stu_next != NULL);
- }
- // printf("foolish 5\n");
- }
- //清除分配的内存
- void deletememory(struct link *head,struct student *stu_head)
- {
- struct link *p=head;
- struct student *pstu=stu_head;
- struct link *pr=NULL;
- while(p != NULL)
- {
- pr=p;
- p=p->next ;
- free(pr);
- }
- while(pstu!=NULL)
- {
- pr=pstu;
- pstu=pstu->stu_next ;
- free(pr);
- }
- }
复制代码 |
|