设计一个学生成绩管理系统,实现对学生成绩的动态管理,实现对学生成绩的输入,显示,删除,查找,插入,最佳,保存,计算,排序等主要功能。
功能要求
1、每一条记录包括一个学生的学号、姓名、3门课成绩、平均成绩。
2、输入功能:可以一次完成若干条记录的输入。
3、显示功能:完成全部学生记录的显示。
4、查找功能:完成按姓名查找学生记录,并显示。
5、排序功能:按学生平均成绩进行排序。
6、插入功能:按平均成绩高低插入一条学生记录
7、删除功能:如果输入错误,可以删除学生记录;
8、退出。
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
#include<stdio.h> #include<stdlib.h> #include<string.h> #define SIZE_NAME 10 #define SIZE_ID 20 int Record = 0; typedef struct { char name[SIZE_NAME]; char id[SIZE_ID]; int a, b, c; int ava; }pInfo; typedef struct node { pInfo people; struct node *next; }linkList; int menu(); int create(linkList *head); int display(linkList *head); int search(linkList *head, char *info); int modify(linkList *head, char *pid); int add2(linkList *head, char *pid); int delt(linkList *head, char *info); int compare( int ava1, int ava2); int sort(linkList *head, int boolean); //1升序 0降序 int main() { linkList head, *p; char info[SIZE_ID]; int temp, chus, i; head.next = NULL; while (1) { switch (menu()) { case 1: create(&head); break ; case 2: display(&head); break ; case 3: printf ( "请输入需要查询的学号或姓名: " ); scanf ( "%s" , info); p = &head; p = p->next; for (i = 0; i < search(&head, info); i++) { p = p->next; } printf ( "搜索到:\n" ); printf ( "\t\t\t\t学生信息\n" ); printf ( "--------------------------------------------------------------------------------\n" ); printf ( "\t\t学号\t\t姓名\t\t\t平均成绩\n" ); printf ( "--------------------------------------------------------------------------------\n" ); printf ( "%20s\t" , p->people.id); printf ( "%10s\t" , p->people.name); printf ( "%20d\n" , p->people.ava); break ; case 4: printf ( "请输入需要修改的学号: " ); scanf ( "%s" , info); modify(&head, info); break ; case 5: printf ( "请输入需要添加的学号: " ); scanf ( "%s" , info); add2(&head, info); break ; case 6: printf ( "请输入需要删除的学号或姓名: " ); scanf ( "%s" , info); delt(&head, info); break ; case 7: printf ( "请输入1或0:\n\t1:升序\n\t0:降序\n" ); scanf ( "%d" , &temp); sort(&head, temp); break ; case 8: exit (0); break ; default : printf ( "输错了,再来一次\n" ); } system ( "pause" ); system ( "cls" ); } system ( "pause" ); return 0; } int menu() { int chus; printf ( "\t学生信息\n\n" ); printf ( "请输入(1 -- 8):\n" ); printf ( "\t1.创建学生信息\n" ); printf ( "\t2.显示学生信息\n" ); printf ( "\t3.查询学生信息\n" ); printf ( "\t4.修改学生信息\n" ); printf ( "\t5.添加学生信息\n" ); printf ( "\t6.删除学生信息\n" ); printf ( "\t7.排序学生成绩\n" ); printf ( "\t8.退出\n" ); scanf ( "%d" , &chus); return chus; } int create(linkList *head) { linkList *s, *p; p = head; printf ( "请输入学号 姓名 三科成绩,输入end结束\n" ); while (1) { s = (linkList*) malloc ( sizeof (linkList)); scanf ( "%s" , s->people.id); if (! strcmp (s->people.id, "end" )) { return 0; } scanf ( "%s" , s->people.name); scanf ( "%d" , &s->people.a); scanf ( "%d" , &s->people.b); scanf ( "%d" , &s->people.c); s->people.ava = (s->people.a + s->people.b + s->people.c) / 3; s->next = p->next; p->next = s; p = s; Record++; } return 0; } int display(linkList *head) { int i; linkList *p; p = head; p = p->next; printf ( "\t\t\t\t学生信息\n" ); printf ( "--------------------------------------------------------------------------------\n" ); printf ( "\t\t学号\t\t姓名\t\t\t平均成绩\n" ); printf ( "--------------------------------------------------------------------------------\n" ); for (i = 0; i < Record; i++, p = p->next) { printf ( "%20s\t" , p->people.id); printf ( "%10s\t" , p->people.name); printf ( "%20d\n" , p->people.ava); } return 0; } int search(linkList *head, char *info) { int i; linkList *p; p = head; p = p->next; for (i = 0; i < Record; i++, p = p->next) { if ((! strcmp (p->people.id, info)) || (! strcmp (info, p->people.name))) { return i; } } return -1; } int modify(linkList *head, char *pid) { int i; linkList *p; p = head; p = p->next; for (i = 0; i < search(head, pid); i++) { p = p->next; } printf ( "请输入新信息:\n" ); scanf ( "%s" , p->people.id); scanf ( "%s" , p->people.name); scanf ( "%d" , &p->people.a); scanf ( "%d" , &p->people.b); scanf ( "%d" , &p->people.c); p->people.ava = (p->people.a + p->people.b + p->people.c) / 3; return 0; } int add2(linkList *head, char *pid) { int i; linkList *p, *s; p = head; p = p->next; s = (linkList*) malloc ( sizeof (linkList)); while (p->next != NULL) { p = p->next; } printf ( "请输入需要添加的姓名和成绩:\n" ); strcpy (s->people.id, pid); scanf ( "%s" , s->people.name); scanf ( "%d" , &s->people.a); scanf ( "%d" , &s->people.b); scanf ( "%d" , &s->people.c); s->people.ava = (s->people.a + s->people.b + s->people.c) / 3; if (search(head, s->people.id) == -1) { s->next = p->next; p->next = s; Record++; } else { printf ( "学号重复了\n" ); } sort(head, 0); return 0; } int delt(linkList *head, char *info) { int i, n; linkList *p, *s; p = head; n = search(head, info); if (-1 == n) { printf ( "没有找到\n" ); return 0; } for (i = 0; i < n; i++) { p = p->next; } p->next = p->next->next; Record--; return 0; } int compare( int ava1, int ava2) { if (ava1 < ava2) { return 1; } return 0; } int sort(linkList *head, int boolean) { linkList *p, *pre; pInfo temp; if (boolean) { for (p = head->next; p != NULL; p = p->next) { for (pre = p->next; pre != NULL; pre = pre->next) { if (0 == compare(p->people.ava, pre->people.ava)) { temp = p->people; p->people = pre->people; pre->people = temp; } } } } else { for (p = head->next; p != NULL; p = p->next) { for (pre = p->next; pre != NULL; pre = pre->next) { if (1 == compare(p->people.ava, pre->people.ava)) { temp = p->people; p->people = pre->people; pre->people = temp; } } } } return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/Lu_1u/article/details/73929613