设为首页 加入收藏

TOP

数据结构程序设计――C语言学生管理(动态链表)(二)
2014-11-23 20:15:58 来源: 作者: 【 】 浏览:6
Tags:数据结构 程序设计 语言 学生管理 动态
; printf("-------------------------------------\n"); scanf("%s%s%s%d%s",stu_num,stu_name,stu_sex,&stu_age,stu_dept); if(strcpy(stu_sex,"男") != 0 && strcpy(stu_sex,"女")) { printf("◎性别不可乱填!!!\n"); return 0; } if(!IsStudent(stu_num)) { newStu = (Student*)malloc(LEN_STUDENT); strcpy(newStu->num,stu_num); strcpy(newStu->name,stu_name); strcpy(newStu->sex,stu_sex); newStu->age = stu_age; strcpy(newStu->dept,stu_dept); newStu->headCourse = (Course*)malloc(LEN_COURSE); newStu->headCourse->next = NULL; newStu->next = NULL; for(p=p->next; p->next!=NULL; p=p->next); p->next = newStu; printf("\n◎学生信息已成功添加◎\n"); } else { printf("\n◎该学号学生已存在请检查学号重新填写◎\n"); } return 0; } /*【1-2】添加成绩*/ int Add_Grade() { Student *p1 = student->next; char stu_num[10]; printf("\n◎请输入您要添加成绩的学号信息:"); scanf("%s",stu_num); while(p1 != NULL) { if(strcmp(p1->num,stu_num) == 0) { Course *pc; int cou_id; char cou_name[20]; int cou_credit; int cou_grade; for(pc = p1->headCourse; pc->next!=NULL; pc=pc->next); printf("\n----◎请输入课程成绩----\n"); printf("课程名称 成绩 \n"); printf("--------------------------\n"); scanf("%s%d",cou_name,&cou_grade); if(cou_grade > 100 || cou_grade < 0) { printf("◎成绩填写错误!!!\n"); return 0; } Course *pc1; Course *newCou; if((pc1 = FindCourseByName(cou_name)) != NULL) { newCou = (Course*)malloc(LEN_COURSE); newCou->id = pc1->id; strcpy(newCou->name,cou_name); newCou->credit = pc1->credit; newCou->grade = cou_grade; newCou->next = NULL; pc->next = newCou; printf("\n◎学生成绩已成功添加◎\n"); } else { printf("\n◎需要添加的课程在课程数据库中不存在,请先添加这一课程◎\n"); } return 0; } p1 = p1->next; } printf("数据库中不存在您要添加学生的信息 ~~~"); printf("\n\n"); return 0; } /*【1-3】添加可选课程*/ int Add_Class() { Course *pc = course; int cou_id; char cou_name[20]; int cou_credit; printf("\n----◎请输入课程信息----\n"); printf("编号 课程名称 学分\n"); printf("------------------------\n"); scanf("%d%s%d",&cou_id,cou_name,&cou_credit); if(FindCourseById==NULL || FindCourseByName==NULL) { for(; pc->next!=NULL; pc=pc->next); Course *newCou = (Course*)malloc(LEN_COURSE); newCou->id = cou_id; strcpy(newCou->name,cou_name); newCou->credit = cou_credit; newCou->next = NULL; pc->next = newCou; printf("\n◎可选课程已成功添加◎\n"); } else { printf("\n◎数据库中该课程已存在\n\n"); } return 0; } /*【2-1】全量查询*/ void Print_Inquire_All() { void menu_print_out(); Student *p1 = student->next; menu_print_out(); while (p1!=NULL) { printf("%s\t%s\t%s\t%d\t%s ",p1->num,p1->name,p1->sex,p1->age,p1->dept); Course *q = p1->headCourse->next; while (q!=NULL) { printf("%s: %d ",q->name,q->grade); q = q->next; if(q == NULL) { printf("\n"); } } p1 = p1->next; } } /*【2-2】按学号查询*/ int Print_Inquire_Num() { void menu_print_out(); Student *p1 = student->next; char stu_num[20]; printf("◎请输入您需要查询的学号:"); scanf("%s",stu_num); while (p1!=NULL) { if(strcmp(p1->num,stu_num) == 0) { menu_print_out(); printf("%s\t%s\t%s\t%d\t%s ",p1->num,p1->name,p1->sex,p1->age,p1->dept); Course *q = p1->headCourse->next; while (q!=NULL) { printf("%s: %d ",q->name,q->grade); q = q->next; if(q == NULL) { printf("\n\n"); } } return 0; } p1 = p1->next; } printf("\n◎数据库中不存在您要查询的数据 ~~~"); printf("\n\n"); return 0; } /*【2-3】按姓名查询*/ int Print_Inquire_Name() { void menu_print_out(); Student *p1 = student->next; char stu_name[20]; printf("◎请输入您需要查询的姓名:"); scanf("%s",stu_name); while (p1!=NULL) { if(strcmp(p1->name,stu_name) == 0) { menu_print_out(); printf("%s\t%s\t%s\t%d\t%s ",p1->num,p1->name,p1->sex,p1->age,p1->dept); Course *q = p1->headCourse->next; while (q!=NULL) { printf("%s: %d ",q->name,q->grade); q = q-
首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C指针原理(54)-Ncurses-文本终端.. 下一篇C指针原理(55)-C语言-pvm并行计算

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: