本文实例为大家分享了C语言学生成绩管理系统的具体代码,供大家参考,具体内容如下
Ps:后加了个链表排序,用冒泡写的。
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
/* Title : Student's score management system Author: nyist_xiaod Date : 2012.5.8 */ #include <stdio.h> #include <conio.h> #include <string.h> #include <stdlib.h> #define Print_Head_Num puts("班级 姓名 语文 数学 英语 总成绩") #define Print_Head_Cla puts("学号 姓名 语文 数学 英语 总成绩") #define Print_Head_All puts("班级 学号 姓名 语文 数学 英语 总成绩") typedef struct Node Node; struct Score { int chinese,math,english,sum; }; struct Node { char name[20],classs[20],number[20]; struct Score score; struct Node* next; }*head,*u,*p,*q; int n,C,M,E,Cj,Cy,Mj,My,Ej,Ey; char num[20]; void Welcome() { printf ( "\t\t %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n" ,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4); printf ( "\t\t %c 欢迎您使用学生成绩管理系统 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 1.读取文件 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 2.保存文件 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 3.添加学生成绩 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 4.修改学生成绩 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 5.删除学生成绩 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 6.查询本人成绩 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 7.查询本班成绩 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 8.查询全校成绩 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c 9.退出管理系统 %c\n" ,4,4); printf ( "\t\t %c %c\n" ,4,4); printf ( "\t\t %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n\n" ,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4); printf ( "\t\t 请输入指令:(1-9) " ); } Node* new_node(Node* uu) { uu = (Node*) malloc ( sizeof (Node)); uu->next = NULL; return uu; } void Add() { u = new_node(u); printf ( "\n请输入您要加入的学生的信息:\n" ); printf ( "\n姓名: " ); scanf ( "%s" ,u->name); printf ( "\n班级: " ); scanf ( "%s" ,u->classs); printf ( "\n学号: " ); scanf ( "%s" ,u->number); printf ( "\n语文、数学、英语成绩: " ); scanf ( "%d%d%d" ,&u->score.chinese,&u->score.math,&u->score.english); u->score.sum = u->score.chinese + u->score.math + u->score.english; u->next = head->next; head->next = u; printf ( "\n--->添加成功!\n" ); } void Mod() { n = 0; printf ( "\n请输入您要修改的学号: " ); scanf ( "%s" ,num); for (u = head; u != NULL;u = u->next) { if ( strcmp (u->number,num) == 0) { n = 1; printf ( "\n请输入新的语文、数学、英语成绩: " ); scanf ( "%d%d%d" ,&u->score.chinese,&u->score.math,&u->score.english); u->score.sum = u->score.chinese + u->score.math + u->score.english; printf ( "\n--->修改成功!\n" ); break ; } } if (!n) printf ( "\n--->没有这个学生的信息!\n" ); } void Del() { n = 0; printf ( "\n请输入您要删除的学生的学号: " ); scanf ( "%s" ,num); for (u = head; u != NULL;u = u->next) { if ( strcmp (u->number,num) == 0) { n = 1; p->next = u->next; free (u); printf ( "\n--->删除成功!\n" ); break ; } p = u; } if (!n) printf ( "\n--->没有这个学生的信息!\n" ); } void Sort() { int i,j; n = 0; for (u = head->next; u != NULL;u = u->next) n++; for (i=1;i<=n;i++) { u = head; for (j=0;j<n-i;j++) { p = u->next; q = p->next; if ( strcmp (p->classs,q->classs) > 0 || strcmp (p->classs,q->classs) == 0 && p->score.sum < q->score.sum) { u->next = q; p->next = q->next; q->next = p; } u = u->next; } } } void Que_One() { n = 0; printf ( "\n请输入您要查询的学生的学号: " ); scanf ( "%s" ,num); for (u = head->next; u != NULL;u = u->next) { if ( strcmp (u->number,num) == 0) { n = 1; printf ( "\n" ); Print_Head_Num; printf ( "%-11s%-15s" ,u->classs,u->name); printf ( "%-6d%-6d%-6d%-6d\n" ,u->score.chinese,u->score.math,u->score.english,u->score.sum); break ; } } if (!n) printf ( "\n--->没有这个学生的信息!\n" ); } void Analyze_Sco(Node *uu) { C += uu->score.chinese; M += uu->score.math; E += uu->score.english; if (uu->score.chinese >= 60) Cj++; if (uu->score.chinese >= 90) Cy++; if (uu->score.math >= 60) Mj++; if (uu->score.math >= 90) My++; if (uu->score.english >= 60) Ej++; if (uu->score.english >= 90) Ey++; } void Print_Sco() { printf ( "语文平均成绩: %-6.2f, 及格率: %%%-6.2f , 优秀率: %%%-6.2f.\n\n" ,( float )C/n,( float )100*Cj/n,( float )100*Cy/n); printf ( "数学平均成绩: %-6.2f, 及格率: %%%-6.2f , 优秀率: %%%-6.2f.\n\n" ,( float )M/n,( float )100*Mj/n,( float )100*My/n); printf ( "英语平均成绩: %-6.2f, 及格率: %%%-6.2f , 优秀率: %%%-6.2f.\n\n" ,( float )E/n,( float )100*Ej/n,( float )100*Ey/n); } void Que_Cla() { Sort(); n = C = M = E = Cj = Cy = Mj = My = Ej = Ey = 0; printf ( "\n请输入您要查询的班级: " ); scanf ( "%s" ,num); printf ( "\n" ); for (u = head->next; u != NULL;u = u->next) { if ( strcmp (u->classs,num)) continue ; if (!n) Print_Head_Cla; n++; printf ( "%-11s%-15s" ,u->number,u->name); printf ( "%-6d%-6d%-6d%-d\n" ,u->score.chinese,u->score.math,u->score.english,u->score.sum); Analyze_Sco(u); } if (!n) { printf ( "没有这个班级的学生信息!\n" ); return ; } printf ( "\n该班共有学生 %d 人.\n\n" ,n); Print_Sco(); } void Que_All() { Sort(); n = C = M = E = Cj = Cy = Mj = My = Ej = Ey = 0; printf ( "\n" ); if (head->next == NULL) { printf ( "--->没有学生信息!\n" ); return ; } Print_Head_All; for (u = head->next; u != NULL;u = u->next) { n++; printf ( "%-12s%-12s%-15s" ,u->classs,u->number,u->name); printf ( "%-6d%-6d%-6d%-d\n" ,u->score.chinese,u->score.math,u->score.english,u->score.sum); Analyze_Sco(u); } printf ( "\n全校共有学生 %d 人.\n\n" ,n); Print_Sco(); } void Save() { char c; printf ( "\n确认保存?(Y/N): " ); scanf ( "%*c%c" ,&c); if (c == 'N' ) return ; FILE *fp; if ((fp= fopen ( "C:\\data.txt" , "w" ))==NULL) { printf ( "\n--->无法打开文件\n" ); return ; } fputs ( "班级 学号 姓名 语文 数学 英语 总成绩" ,fp); if (head->next != NULL) fputs ( "\n" ,fp); for (u = head->next; u != NULL;u = u->next) { fprintf (fp, "%-11s%-11s%-15s" ,u->classs,u->number,u->name); fprintf (fp, "%-6d%-6d%-6d%-d" ,u->score.chinese,u->score.math,u->score.english,u->score.sum); if (u->next != NULL) fprintf (fp, "\n" ); } fclose (fp); printf ( "\n--->成绩成功存入C:\\\\data.txt中\n" ); } void Open() { printf ( "\n请把数据放到目录C:\\\\data.txt中,按任意键确认.\n" ); getch(); FILE *fp; if ((fp= fopen ( "C:\\data.txt" , "r" ))==NULL) { printf ( "\n--->没有找到文件!\n" ); return ; } char tmp[100]; fgets (tmp,66,fp); while (! feof (fp)) { u = new_node(u); fscanf (fp, "%s%s%s" ,u->classs,u->number,u->name); fscanf (fp, "%d%d%d%d" ,&u->score.chinese,&u->score.math,&u->score.english,&u->score.sum); u->next = head->next; head->next = u; } printf ( "\n--->成绩读入成功!\n" ); fclose (fp); } void Exi() { char c; printf ( "\n确定退出?(Y/N): " ); scanf ( "%*c%c" ,&c); if (c == 'N' ) return ; system ( "cls" ); printf ( "\n\n" ); printf ( "\t\t\t %c %c %c %c %c %c %c %c %c\n" ,4,4,4,4,4,4,4,4,4); printf ( "\t\t\t %c Made by Xiaod %c\n" ,4,4); printf ( "\t\t\t %c %c %c %c %c %c %c %c %c\n" ,4,4,4,4,4,4,4,4,4); printf ( "\t\t\t Thank you!\n\n\n" ); exit (0); } int main() { int orz; system ( "color 0B" ); head = new_node(head); while (1) { Welcome(); scanf ( "%d" ,&orz); system ( "cls" ); switch (orz) { case 1:Open(); break ; case 2:Save(); break ; case 3:Add(); break ; case 4:Mod(); break ; case 5:Del(); break ; case 6:Que_One(); break ; case 7:Que_Cla(); break ; case 8:Que_All(); break ; case 9:Exi(); break ; default : printf ( "\n--->无效的指令!\n" ); } printf ( "\n" ); system ( "pause" ); system ( "cls" ); } return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/dgq8211/article/details/7581403