学生信息管理

实验题目(共10题, 第4题)


标题: 学生信息管理
时 限: 1000 ms
内存限制: 20000 K
总时限: 3000 ms
描述: 用链式存储结构实现对一个班级学生信息管理。设计程序求出每个人的平均成绩并按平均成绩由高到底排序后输出学生记录。
输入: 人数n
人员记录1 (格式为: 学号 姓名 成绩1  成绩2  成绩3)
人员记录2
输出: 人员记录x                                                        1
人员记录y                                                        2
  …
人员记录z                                                        n
输入样例: 3
1 孙俪莉  76  78  89  
2 章子怡  72  56  67  
3 刘德华  56  84  90
输出样例: 1 孙俪莉  76 78  89  81.00  1
3 刘德华 56  84  90  76.67  2
2 章子怡 72  56  67  65.00  3
提示:  
来源:
 
View Code
  1 #include<stdio.h>
2 #include<stdlib.h>
3
4 #define ElemType int
5 typedef struct Student
6 {
7 int num;
8 char name[10];
9 float score1;
10 float score2;
11 float score3;
12 float average;
13 struct Student *next;
14 } student,*stu;
15
16 void CreatList(stu L,ElemType n)
17 {
18 stu p1;
19 while(n>0)
20 {
21 p1=(stu)malloc(sizeof(student));
22 scanf("%d",&p1->num);
23 scanf("%s",p1->name);
24 scanf("%f",&p1->score1);
25 scanf("%f",&p1->score2);
26 scanf("%f",&p1->score3);
27 L->next=p1;
28 L=p1;
29 n--;
30 }
31 L->next=NULL;
32 }
33
34 void AverageScore(stu L)
35 {
36 stu p;
37 p=L->next;
38 while(p)
39 {
40 p->average=((p->score1)+(p->score2)+(p->score3))/3;
41 p=p->next;
42 }
43
44 }
45
46 void List_Sort(stu L)
47 {
48 stu p,q,r,s,l;
49 l=L;
50 p=L->next;
51 while(p)
52 {
53 r=p;
54 q=p->next;
55 while(q)
56 {
57 if(r->average<q->average)
58 r=q;
59 q=q->next;
60 }
61 s=p;
62 if(s->average==r->average && s->num==r->num)
63 {
64 p=p->next;
65 l->next=r;
66 l=r;
67 }
68 else
69 {
70 while(s->next->num!=r->num)
71 s=s->next;
72 s->next=r->next;
73 l->next=r;
74 l=r;
75 }
76 }
77 l->next=NULL;
78 }
79
80 void TraverseList(stu L,ElemType n)
81 {
82 ElemType i=0;
83 stu p;
84 p=L->next;
85 while(p)
86 {
87 i++;
88 if(i==n && n>10)
89 printf("%d %s %.2f %.2f %.2f %.2f %d\n",p->num,p->name,p->score1,p->score2,p->score3,p->average,i);
90 else printf("%d %s %.2f %.2f %.2f %.2f %d\n",p->num,p->name,p->score1,p->score2,p->score3,p->average,i);
91 p=p->next;
92 }
93 }
94 int main()
95 {
96 ElemType n;
97 stu L;
98 L=(stu)malloc(sizeof(student));
99 L->next=NULL;
100 scanf("%d",&n);
101 CreatList(L,n);
102 AverageScore(L);
103 List_Sort(L);
104 TraverseList(L,n);
105 return 0;
106 }
posted @ 2011-05-24 17:52  itbird  Views(893)  Comments(1Edit  收藏  举报