学生成绩管理系统,供大家参考,具体内容如下
一、问题描述及功能要求
(1)输入同学的学号,姓名,三门科成绩(应用数学、大学英语、计算机应用基础)
(2)可以计算出每个学生三门课的平均成绩。
(3)可通过输入姓名、学号查询成绩,也可通过姓名修改学生信息,也可通过主界面删除学生信息,以及清楚所有信息
二、代码实现 带有注释
废话不说,直接代码,欢迎指正。
大家CV可能有不兼容的情况,可以跟我滴滴,尽可能解决问题地回复。
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define null NULL
class student
{
private :
friend class studentMessage;
student *next; //节点指针
string name; //学生姓名
int age; //年纪
int id; //学号
double score[3]; //三科成绩
double total; //总分
double average; //平均成绩
public :
student(string _name, int _age, int _id, double *_score)
{
name = _name;
age = _age;
id = _id;
score[0] = _score[0];
score[1] = _score[1];
score[2] = _score[2];
total = score[0]+score[1]+score[2];
average = total/3;
next = NULL;
}
student() //为studentMessage初始化头结点用
{
name = "null" ;
age = 0;
id = 0;
score[0]=score[1]=score[2]=0;
total = 0;
average = 0;
next = NULL;
}
~student(){}
void swap(student*);
};
void student::swap(student *q)
{
string _name;
int _age,_id;
double _score[3],_total,_average;
_name = name;
name = q->name;
q->name = _name;
_age = age;
age = q->age;
q->age = _age;
_id = id;
id = q->id;
q->id = _id;
_score[0] = score[0];
score[0] = q->score[0];
q->score[0] = _score[0];
_score[1] = score[1];
score[1] = q->score[1];
q->score[1] = _score[1];
_score[2] = score[2];
score[2] = q->score[2];
q->score[2] = _score[2];
_total = total;
total = q->total;
q->total = _total;
_average = average;
average = q->average;
q->average = _average;
}
class studentMessage
{
private :
student *first; //头指针
int num; //信息中的学生人数
public :
studentMessage()
{
num = 0; //初始化学生人数为0
first = new student; //初始化头结点
}
~studentMessage(){ delete first;}
/*管理系统常规操作*/
void Insret( void ); //插入
void Display( void ); //显示
void Delete( void ); //删除
void Search( void ); //搜索
void Change( void ); //改动
void sortByLesson1( void ); //按成绩一来排序
void sortByLesson2( void ); //按成绩二来排序
void sortByLesson3( void ); //按成绩三来排序
void sortByTotal( void ); //按总分来排序
void SearchByid( void ); //按照学号查找
void SearchByname( void ); //按照姓名查找
int menu( void ); //初始的菜单
void clear( void ); //清空列表
};
int studentMessage::menu( void )
{
int ch;
cout<< "**********************************************************************" <<endl;
cout<< "======================================================================" <<endl;
cout<< "***************************学生成绩管理系统***************************" <<endl;cout<<endl;
cout<< "1.显示所有学生成绩" <<endl;
cout<< "2.添加学生信息" <<endl;
cout<< "3.查询学生信息" <<endl;
cout<< "4.修改学生信息" <<endl;
cout<< "5.删除最下面一个学生信息" <<endl;
cout<< "6.删除所有信息" <<endl;
cout<< "0.退出系统" <<endl;cout<<endl;
cout<< "********************Copyright@ By Jeaven Wong**************************" <<endl;
cout<< "=======================================================================" <<endl;
cout<< "***********************************************************************" <<endl;
cin >> ch;
cout<< "\n\n\n" <<endl;
return ch;
}
//插入
void studentMessage::Insret( void )
{
string name;
int age;
int id;
double score[3];
cout<< "请输入学生姓名: " ;
cin>>name;
cout<< "请输入学生年龄: " ;
cin>>age;
cout<< "请输入学生学号: " ;
cin>>id;
cout<< "下面请输入学生三门课程成绩: " ;
cout<<endl;
cout<< "请输入第一门课的成绩: " ;cin>>score[0];
cout<< "请输入第二门课的成绩: " ;cin>>score[1];
cout<< "请输入第三门课的成绩: " ;cin>>score[2];
cout<<endl;
student *newstu = new student(name,age,id,score);
student *p = first;
while (p->next != NULL)
{
p = p->next;
}
p->next = newstu;
newstu->next = null;
num++;
}
void studentMessage::Display( void )
{
if (num == 0)
{
cout<< "当前记录中无学生..." <<endl;
}
else
{
student *p = first->next;
while (p != null)
{
cout<< "姓名:" <<p->name<< " " ;
cout<< "年龄:" <<p->age<< " " ;
cout<< "学号:" <<p->id<< " " ;
cout<< "三门课程成绩: " <<p->score[0]<< " " <<p->score[1]<< " " <<p->score[2]<< " " ;
cout<< "总分:" <<p->total<< " " ;
cout<< "平均分:" <<p->average<<endl;
p = p->next;
}
}
}
void studentMessage::Delete( void )
{
student *p = first;
student *pre = first;
while (p->next != NULL)
{
pre = p;
p = p->next;
}
pre->next = NULL;
delete p;
num--;
}
void studentMessage::Search( void )
{
int temp = 0;
cout<< "请输入查找的条件,有如下选项..." <<endl;
cout<< "按照学号查找(请输入【1】) 按照姓名查找(请输入【2】)" <<endl;
cin>>temp;
switch (temp)
{
case 1: SearchByid(); break ;
case 2: SearchByname(); break ;
default : cout<< "输入有误..." <<endl;
}
}
void studentMessage::SearchByid( void )
{
int _id;
int flag = 0;
cout<< "请输入待查找学生的学号:" ;
cin >> _id;
student *p = first->next;
while (p != null)
{
if (p->id == _id)
{
flag = 1;
cout<< "下面是查找匹配结果:" <<endl;
cout<< "姓名:" <<p->name<< " " ;
cout<< "年龄:" <<p->age<< " " ;
cout<< "学号:" <<p->id<< " " ;
cout<< "三门课程成绩: " <<p->score[0]<< " " <<p->score[1]<< " " <<p->score[2]<< " " ;
cout<< "总分:" <<p->total<< " " ;
cout<< "平均分:" <<p->average<<endl;
}
p = p->next;
}
if (flag == 0)
{
cout<< "抱歉,记录中没有查找匹配项..." <<endl;
}
}
void studentMessage::SearchByname( void )
{
string _name;
int flag = 0;
cout<< "请输入待查找的学生姓名: " ;
cin >> _name;
student *p = first->next;
while (p != null)
{
if (p->name == _name)
{
flag = 1;
cout<< "下面是查找匹配结果:" <<endl;
cout<< "姓名:" <<p->name<< " " ;
cout<< "年龄:" <<p->age<< " " ;
cout<< "学号:" <<p->id<< " " ;
cout<< "三门课程成绩: " <<p->score[0]<< " " <<p->score[1]<< " " <<p->score[2]<< " " ;
cout<< "总分:" <<p->total<< " " ;
cout<< "平均分:" <<p->average<<endl;
}
p = p->next;
}
if (flag == 0)
{
cout<< "抱歉,记录中没有查找匹配项..." <<endl;
}
}
void studentMessage::Change( void )
{
string _name;
int flag = 0,temp;
int _id,_age;
int course = 0;
cout<< "请输入需要改动信息的学生的姓名: " ;
cin >> _name;
student *p = first->next;
while (p != null)
{
if (p->name == _name)
{
flag = 1;
cout<< "该学生当前信息如下:" <<endl;
cout<< "姓名:" <<p->name<< " " ;
cout<< "年龄:" <<p->age<< " " ;
cout<< "学号:" <<p->id<< " " ;
cout<< "三门课程成绩: " <<p->score[0]<< " " <<p->score[1]<< " " <<p->score[2]<< " " ;
cout<< "总分:" <<p->total<< " " ;
cout<< "平均分:" <<p->average<<endl;
cout<< "请指明哪一项需要修改..." <<endl;
cout<< "修改学号(输入【1】) 修改年龄(输入【2】)修改成绩(输入【3】)" <<endl;
cin >> temp;
switch (temp)
{
case 1:
{
cout<< "请输入新的学号:" ;cin>>_id;
p->id = _id;
}
break ;
case 2:
{
cout<< "请输入新的年龄:" ;cin>>_age;
p->age = _age;
}
break ;
case 3:
{
cout<< "请按指示修改课程成绩..." <<endl;
cout<< "是否需要修改第一门课程成绩?(需要输入【1】不需要输入【0】)" <<endl;
cin >> course;
if (course == 1)
{
cout<< "请输入修改后的第一门课的成绩:" ; cin >> p->score[0];
}
course = 0;
cout<< "是否需要修改第二门课程成绩?(需要输入【1】不需要输入【0】)" <<endl;
cin >> course;
if (course == 1)
{
cout<< "请输入修改后的第二门课的成绩:" ; cin >> p->score[1];
}
course = 0;
cout<< "是否需要修改第三门课程成绩?(需要输入【1】不需要输入【0】)" <<endl;
cin >> course;
if (course == 1)
{
cout<< "请输入修改后的第三门课的成绩:" ; cin >> p->score[2];
}
course = 0;
p->total = p->score[0]+p->score[1]+p->score[2];
p->average = p->total/3;
cout<< "修改后的信息如下: " <<endl;
cout<< "姓名:" <<p->name<< " " ;
cout<< "年龄:" <<p->age<< " " ;
cout<< "学号:" <<p->id<< " " ;
cout<< "三门课程成绩: " <<p->score[0]<< " " <<p->score[1]<< " " <<p->score[2]<< " " ;
cout<< "总分:" <<p->total<< " " ;
cout<< "平均分:" <<p->average<<endl;
}
break ;
default : cout<< "输入有误..." <<endl;
}
}
p = p->next;
}
if (flag == 0)
cout<< "当前记录中没有次学生..." <<endl;
}
/*排序我均采用冒泡排序法,均是从小到大排序*/
//按照科目一排序
void studentMessage::sortByLesson1( void )
{
student *p = first->next;
while (p->next != null)
{
student *q = p->next;
while (q != null)
{
if (p->score[0] > q->score[0])
{
p->swap(q);
}
q = q->next;
}
p = p->next;
}
}
//按照科目二排序
void studentMessage::sortByLesson2( void )
{
student *p = first->next;
while (p->next != null)
{
student *q = p->next;
while (q != null)
{
if (p->score[1] > q->score[1])
{
p->swap(q);
}
q = q->next;
}
p = p->next;
}
}
//按照科目三排序
void studentMessage::sortByLesson3( void )
{
student *p = first->next;
while (p->next != null)
{
student *q = p->next;
while (q != null)
{
if (p->score[2] > q->score[2])
{
p->swap(q);
}
q = q->next;
}
p = p->next;
}
}
//按照总成绩排序
void studentMessage::sortByTotal( void )
{
student *p = first->next;
while (p->next != null)
{
student *q = p->next;
while (q != null)
{
if (p->total > q->total)
{
p->swap(q);
}
q = q->next;
}
p = p->next;
}
}
void studentMessage::clear( void )
{
student *p = first->next;
while (p != null)
{
first->next = p->next;
p->next = null;
delete p;
p = first->next;
}
}
int main()
{
studentMessage stulist;
int ch;
while (ch = stulist.menu())
{
switch (ch)
{
case 1: stulist.Display(); break ;
case 2: stulist.Insret(); break ;
case 3: stulist.Search(); break ;
case 4: stulist.Change(); break ;
case 5: stulist.Delete(); break ;
case 6: stulist.clear(); break ;
default : cout<< "请按要求输入..." <<endl;
}
}
return 0;
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/m0_46525584/article/details/106967106