题目描述
某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,用一维数组作函数参数编程实现如下学生成绩管理:(1)录入每个学生的学号和考试成绩;(2)计算课程的总分和平均分;(3)按成绩由高到低排出名次表;(4)按学号由小到大排出成绩表;(5)按学号查询学生排名及其考试成绩;(6)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;(7)输出每个学生的学号、考试成绩。
程序运行结果示例
Input student number(nID), &(p->score));
27 p->next = (*S)->next;//p成了末尾节点
28 (*S)->next = p;//把这个新节点接到前节点之后
29 }
30 }
31
32 void Print_stu(STU_List S)
33 {
34 STU_List p = S->next;
35 while (p)
36 {
37 printf("%ld\t%.0f\n", p->ID, p->score);
38 p = p->next;
39 }
40 }
41
42 void Total_average_score(STU_List* S, int n)
43 {
44 float total = 0;
45 STU_List p = (*S)->next;
46 while (p)
47 {
48 total = p->score + total;
49 p = p->next;
50 }
51 printf("sum=%.0f,aver=%.2f\n", total, total / n);
52 }
53
54 void Sort_score(STU_List* S, short int n)
55 {
56 STU_List p, q, temp;
57 short int times;
58 for (int i = 0; i < n - 1; i++)
59 {
60 p = (*S)->next;
61 q = (*S)->next->next;
62 temp = (*S);
63 times = n - 1 - i;
64 while (times)
65 {
66 if (p->score < q->score)
67 {
68 p->next = q->next;
69 q->next = p;
70 temp->next = q;
71 }
72 temp = temp->next;
73 p = temp->next;
74 q = temp->next->next;
75 times--;
76 }
77 }
78 printf("Sort in descending order by score:\n");
79 Print_stu(*S);
80 }
81
82 void Sort_number(STU_List* S, short int n)
83 {
84 STU_List p, q, temp;
85 short int times;
86 for (int i = 0; i < n - 1; i++)
87 {
88 p = (*S)->next;
89 q = (*S)->next->next;
90 temp = (*S);
91 times = n - 1 - i;
92 while (times)
93 {
94 if (p->ID > q->ID)
95 {
96 p->next = q->next;
97 q->next = p;
98 temp->next = q;
99 }
100 temp = temp->next;
101 p = temp->next;
102 q = temp->next->next;
103 times--;
104 }
105 }
106 printf("Sort in ascending order by number:\n");
107 Print_stu(*S);
108 }
109
110 void Search_score(STU_List S)
111 {
112 STU_List p = S->next;
113 long ID;
114 printf("Input the number you want to search:\n");
115 scanf_s("%ld", &ID);
116 while (p)
117 {
118 if (p->ID == ID)
119 {
120 printf("%ld\t%.0f\n", ID, p->score);
121 break;
122 }
123 else
124 {
125 p = p->next;
126 }
127 }
128 if (!p)
129 {
130 printf("Not found!\n");
131 }
132 }
133
134 void Analysis_score(STU_List S, short int n)
135 {
136 STU_List p = S->next;
137 float temp_score10 = 0, temp_score9 = 0, temp_score8 = 0, temp_score7 = 0, temp_score6 = 0, temp_score5 = 0;
138 float num = n;
139 while (p)
140 {
141 if (p->score == 100)
142 temp_score10++;
143 else if (90 score && p->score score score score score < 60)
152 temp_score5++;
153 p = p->next;
154 }
155 printf(" |