第8章实验1:学生成绩管理系统V1.0

题目描述

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,用一维数组作函数参数编程实现如下学生成绩管理:
(1)录入每个学生的学号和考试成绩;
(2)计算课程的总分和平均分;
(3)按成绩由高到低排出名次表;
(4)按学号由小到大排出成绩表;
(5)按学号查询学生排名及其考试成绩;
(6)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
(7)输出每个学生的学号、考试成绩。

程序运行结果示例

Input student number(n<30):
6↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
1↙
Input student’s ID, name and score:
11003001 87↙
11003005 98↙
11003003 75↙
11003002 48↙
11003004 65↙
11003006 100↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
2↙
sum=473,aver=78.83
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
3↙
Sort in descending order by score:
11003006 100
11003005 98
11003001 87
11003003 75
11003004 65
11003002 48
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
4↙
Sort in ascending order by number:
11003001 87
11003002 48
11003003 75
11003004 65
11003005 98
11003006 100
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
5↙
Input the number you want to search:
11003004
11003004 65
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
6↙
<60 1 16.67%
60-69 1 16.67%
70-79 1 16.67%
80-89 1 16.67%
90-99 1 16.67%
100 1 16.67%
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
7↙
11003001 87
11003002 48
11003003 75
11003004 65
11003005 98
11003006 100
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
8↙
Input error!
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
0↙
End of program!

输入格式:

( 1 )录入学生的人数:
**输入数据格式:"%d"
**提示信息:“Input student number(n<30):\n”
( 2 )录入每个学生的学号和考试成绩:
**输入数据格式:"%ld%f"
**提示信息:“Input student’s ID, name and score:\n”
输出格式:
菜单项的输出显示:
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
计算课程的总分和平均分:
**输出总分与平均分格式:“sum=%.0f,aver=%.2f\n”
按成绩由高到低排出名次表:
**输出格式:"%ld\t%.0f\n"
**提示信息:“Sort in descending order by score:\n”
按学号由小到大排出成绩表:
**输出格式:"%ld\t%.0f\n"
**提示信息:“Sort in ascending order by number:\n”
按学号查询学生排名及其考试成绩:
**如果未查到此学号的学生,提示信息:“Not found!\n”
**如果查询到该学生,输出格式:"%ld\t%.0f\n"
按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比:
**成绩<60输出格式:"<60\t%d\t%.2f%%\n"
**成绩=100输出格式:"%d\t%d\t%.2f%%\n"
**其他输出百分比格式:"%d-%d\t%d\t%.2f%%\n"
输出学生成绩格式:"%ld\t%.0f\n"

代码

  1 #include <stdlib.h>
  2 #include<stdio.h>
  3 
  4 typedef struct Student_Node
  5 {
  6     long ID;
  7     float score;
  8     struct Student_Node* next;
  9 } Student_Node, * STU_List;
 10 
 11 void Initialize(STU_List* S)
 12 {
 13     *S = (STU_List)malloc(sizeof(Student_Node));
 14     (*S)->ID = 0;
 15     (*S)->score = 0;
 16     (*S)->next = NULL;
 17 }
 18 
 19 void Input_record(STU_List* S, int n)
 20 {
 21     STU_List p;
 22     printf("Input student's ID, name and score:\n");
 23     for (int i = 0; i < n; i++)
 24     {
 25         p = (STU_List)malloc(sizeof(Student_Node));
 26         scanf_s("%ld%f", &(p->ID), &(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 <= p->score && p->score <= 99)
144             temp_score9++;
145         else if (80 <= p->score && p->score <= 89)
146             temp_score8++;
147         else if (70 <= p->score && p->score <= 79)
148             temp_score7++;
149         else if (60 <= p->score && p->score <= 69)
150             temp_score6++;
151         else if (p->score < 60)
152             temp_score5++;
153         p = p->next;
154     }
155     printf("<60\t%d\t%.2f%%\n", (int)temp_score5, (temp_score5 / num) * 100.0);
156     printf("%d-%d\t%d\t%.2f%%\n", 60, 69, (int)temp_score6, (temp_score6 / num) * 100.0);
157     printf("%d-%d\t%d\t%.2f%%\n", 70, 79, (int)temp_score7, (temp_score7 / num) * 100.0);
158     printf("%d-%d\t%d\t%.2f%%\n", 80, 89, (int)temp_score8, (temp_score8 / num) * 100.0);
159     printf("%d-%d\t%d\t%.2f%%\n", 90, 99, (int)temp_score9, (temp_score9 / num) * 100.0);
160     printf("%d\t%d\t%.2f%%\n", 100, (int)temp_score10, (temp_score10 / num) * 100.0);
161 }
162 
163 void print_menu()
164 {
165     printf("Management for Students' scores\n");
166     printf("1.Input record\n");
167     printf("2.Caculate total and average score of course\n");
168     printf("3.Sort in descending order by score\n");
169     printf("4.Sort in ascending order by number\n");
170     printf("5.Search by number\n");
171     printf("6.Statistic analysis\n");
172     printf("7.List record\n");
173     printf("0.Exit\n");
174 }
175 
176 void choose(short int choice, STU_List* S, short int n)
177 {
178     switch (choice)
179     {
180     case 1:
181         Input_record(S, n);
182         break;
183     case 2:
184         Total_average_score(S, n);
185         break;
186     case 3:
187         Sort_score(S, n);
188         break;
189     case 4:
190         Sort_number(S, n);
191         break;
192     case 5:
193         Search_score(*S);
194         break;
195     case 6:
196         Analysis_score(*S, n);
197         break;
198     case 7:
199         Print_stu(*S);
200         break;
201     default:
202         printf("Input error!\n");
203         break;
204     }
205 
206 }
207 
208 int main()
209 {
210     short int n, choice;
211     STU_List S;
212     Initialize(&S);
213     printf("Input student number(n<30):\n");
214     scanf_s("%hd", &n);
215 
216     while (1)
217     {
218         print_menu();
219         printf("Please Input your choice:\n");
220         scanf_s("%hd", &choice);
221         if (choice == 0)
222         {
223             printf("End of program!\n");
224             break;
225         }
226         else
227         {
228             choose(choice, &S, n);
229         }
230     }
231     return 0;
232 }

学生样例

学号分数
11003001 87
11003005 98
11003003 75
11003002 48
11003004 65
11003006 100



posted @ 2021-10-07 12:47  UserHAO  阅读(225)  评论(0编辑  收藏  举报