正文

学生成绩查询系统2008-01-07 10:56:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bigpig/31885.html

分享到:

/*课程链表结构定义*/ typedef struct course {   char cour[30];   int  score;   char  teacher[10];   struct course *next; }C_COURSE; /*学生链表结构定义*/ typedef struct student {   int num;   char name[10];   char dep[20];   float ave;   C_COURSE *link;   struct student *next;   }S_STUDENT;/*从键盘上输入信息并创建课程结构结点实例*//*分数为-1时,输入结束*//*返回所创建的接点地址,若输入结束返回NULL*/C_COURSE *creatcoursenode(){   C_COURSE *p=(C_COURSE*)malloc(sizeof(C_COURSE));   printf("course=");   scanf("%s",p->cour);   printf("teacher=");   scanf("%s",p->teacher);   printf("score=");   scanf("%d",&p->score);   if(p->score==-1){      free(p);   return NULL;   }   else return p;}/*在课程链表中插入一个学生所学的所有课程*//*插入课程的成绩进行比较,并按照从高到低的顺序进行排列*//*h:课程链表的头接点的地址;course:要插入的接点*/void insercoursenode(C_COURSE **h,C_COURSE *course){  C_COURSE *p,*q;  if(*h==NULL||course->score>=(*h)->score) {    course->next=*h; *h=course;  }  else {   q=*h;   p=q->next;   while(q!=NULL&&course->score<p->score) {     q=p;  p=p->next;   }    course->next=p; q->next=course;  } } /*计算课程链表中课程的平均直*/ /*link:课程链表的头指针*/ /*返回链表中各门课的平均成绩*/ float aver(C_COURSE *link) {    int n=0,total=0; while(link!=NULL) {    total+=link->score;    n++;    link=link->next;  }    if(n) {     return (float)(total/n);    }     else {      return 0;   }}/*从键盘输入创建学生接点*//*返回所创建的接点*/S_STUDENT * createstudentnode(){  C_COURSE *q;  S_STUDENT *p=(S_STUDENT*)malloc(sizeof(S_STUDENT));  printf("number=");  scanf("%d",&p->num);  printf("name=");  scanf("%s",p->name);  printf("dep=");  scanf("%s",p->dep);  p->link=NULL;  while((q=creatcoursenode())!=NULL){      insercoursenode(&(p->link),q);   }   p->ave=aver(p->link);   return p;}/*学生链表中插入学生信息*/void insertstudentnode(S_STUDENT **h,S_STUDENT *stu){   S_STUDENT *p,*q;   if(*h==NULL||stu->ave>=(*h)->ave){      stu->next=*h;   *h=stu; } else{ q=*h; p=q->next; while(p!=NULL&&stu->ave<p->ave){  q=p;  p=p->next; } stu->next=p; q->next=stu; }}

阅读(6234) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册