本文实例为大家分享了C++运动会管理系统的实现代码,供大家参考,具体内容如下
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
|
#include<iostream.h> #define MAX 10 #include<iomanip.h> #include "fstream.h" int n,m,w; class gamescore { public : int academynum; //院系编号 int score[MAX][MAX]; //记录成绩的2维数组 int totalscore[MAX]; //院总分存储数组 int mentotalscore[MAX]; //男团总分存储数组 int womentotalscore[MAX]; //女团总分存储数组 int projectnum; //项目编号 gamescore() { academynum=0; projectnum=0; } void search( int academynum, int projectnum); void remove ( int academynum, int projectnum); void repair( int academynum, int projectnum); void save(); //保存成绩 void input(); void sort1(); //按院总分排序 void sort2(); //按男团总分排序 void sort3(); //按女团总分排序 void hold(); //存储总分数 int academytotalscore( int academynum); //院总分 int academywomentotalscore( int academynum); //院女团总分 int academymentotalscore( int academynum); //院男团总分 void output1( int academy); //输出院系的成绩列表 void output2( int academynum); //输出院系的团体成绩列表 }; void gamescore::input() { int i,j; for (i=0;i<n;i++) { cout<< "输入编号为" <<i+1<< "院系的成绩(若参赛人数超过6人,取前5名:第1名得分 7,第2名得分 5,第3名得分3,第4名得分2,第5名得分 1,否则参赛院系不超过6个,每项目取前三名,分别为5,3,2分,其余记成绩为0)" <<endl; for (j=0;j<m+w;j++) { cout<< "输入编号为" <<i+1<< "院系的的运动项目编号为" <<j+1<< "的成绩:" ; cin>>score[i][j]; if (score[i][j]!=0&&score[i][j]!=2&&score[i][j]!=5&&score[i][j]!=10) { cout<< "成绩输入错误,请检查后再输入" <<endl; cin>>score[i][j]; } } } if (i=n-1) cout<< "!!输入完毕" <<endl; } void gamescore::save() { ofstream ofs( "运动会成绩.txt" ); ofs<< "将最终学院参加的对应项目成绩列表列出(行表示学院编号,列表示项目编号)" <<endl; for ( int i=0;i<n;i++) { for ( int j=0;j<m+w;j++) { ofs<<score[i][j]<<setw(5); } ofs<<endl; } for (i=1;i<=n;i++) { ofs<< "编号为" <<i<< "的学院总分的成绩为:" <<academytotalscore(i)<<endl; ofs<< "编号为" <<i<< "的学院男团的成绩为:" <<academymentotalscore(i)<<endl; ofs<< "编号为" <<i<< "的学院女团的成绩为:" <<academywomentotalscore(i)<<endl; } ofs.close(); } int gamescore::academytotalscore( int academynum) //院总分 { int sum=score[academynum-1][0]; for ( int i=1;i<m+w;i++) { sum=sum+score[academynum-1][i]; } return sum; } int gamescore::academywomentotalscore( int academynum) //院女团总分 { int sum=score[academynum-1][m]; for ( int i=m+1;i<m+w;i++) { sum=sum+score[academynum-1][i]; } return sum; } int gamescore::academymentotalscore( int academynum) //院男团总分 { int sum=score[academynum-1][0]; for ( int i=1;i<m;i++) { sum=sum+score[academynum-1][i]; } return sum; } void gamescore::hold() //存储总分 { for ( int i=1;i<=n;i++) { totalscore[i-1]=academytotalscore(i); mentotalscore[i-1]=academymentotalscore(i); womentotalscore[i-1]=academywomentotalscore(i); } } void gamescore::sort1() //按院系总分排序 { int p,q; int a[MAX]; for ( int i=0;i<n;i++) { a[i]=i+1; } for ( int j=0;j<n-1;j++) { for (i=0;i<=n-1-j;i++) { if (totalscore[i]<totalscore[i+1]) { p=totalscore[i]; totalscore[i]=totalscore[i+1]; totalscore[i+1]=p; q=a[i]; a[i]=a[i+1]; a[i+1]=q; } } } cout<< "按院系总分从大到小排序,以及对应的院系编号为:" <<endl; for (j=0;j<n;j++) { cout<<a[j]<<setw(5); } cout<<endl; for (j=0;j<n;j++) { cout<<totalscore[j]<<setw(5); } cout<<endl; } void gamescore::sort2() //按男团总分排序 { int p,q; int a[MAX]; for ( int i=0;i<n;i++) { a[i]=i+1; } for ( int j=0;j<n-1;j++) { for (i=0;i<=n-1-j;i++) { if (mentotalscore[i]<mentotalscore[i+1]) { p=mentotalscore[i]; mentotalscore[i]=mentotalscore[i+1]; mentotalscore[i+1]=p; q=a[i]; a[i]=a[i+1]; a[i+1]=q; } } } cout<< "按男团总分从大到小排序,以及对应的院系编号为:" <<endl; for (j=0;j<n;j++) { cout<<a[j]<<setw(5); } cout<<endl; for (j=0;j<n;j++) { cout<<mentotalscore[j]<<setw(5); } cout<<endl; } void gamescore::sort3() //按女团总分排序 { int p,q; int a[MAX]; for ( int i=0;i<n;i++) { a[i]=i+1; } for ( int j=0;j<n-1;j++) { for (i=0;i<=n-1-j;i++) { if (womentotalscore[i]<womentotalscore[i+1]) { p=womentotalscore[i]; womentotalscore[i]=womentotalscore[i+1]; womentotalscore[i+1]=p; q=a[i]; a[i]=a[i+1]; a[i+1]=q; } } } cout<< "按女团总分从大到小排序,以及对应的院系编号为:" <<endl; for (j=0;j<n;j++) { cout<<a[j]<<setw(5); } cout<<endl; for (j=0;j<n;j++) { cout<<womentotalscore[j]<<setw(5); } cout<<endl; } void gamescore::search( int academynum, int projectnum) { int j; int k; do { cout<< "1 查询该院该单项成绩的总分, 2 查询该院总分,,3 查询该院男团总分,4 查询该院女团总分,5 按项目编号查询,0 退出查询" <<endl; cout<< "请选择:" ; cin>>k; if (k<0||k>5) //判断输入的操作编号是否在目录中,如果超出范围重新输入 { cout<< "输入有误,请重新输入要操作的项目编号" ; cin>>k; } switch (k) { case 1: cout<< "编号为" <<academynum<< "的学院的第" <<projectnum<< "个项目的成绩为:" ; cout<<score[academynum-1][projectnum-1]<<endl; break ; case 2: cout<< "该院总分为:" <<academytotalscore(academynum)<<endl; break ; case 3: cout<< "该院男团总分为:" <<academymentotalscore(academynum)<<endl; break ; case 4: cout<< "该院女团总分:" <<academywomentotalscore(academynum)<<endl; break ; case 5: cout<< "不同院系对应的第" <<projectnum<< "个项目的成绩为:" <<endl; for (j=0;j<n;j++) { cout<<1+j<<setw(5); } cout<<endl; for (j=0;j<n;j++) { cout<<score[j][projectnum-1]<<setw(5); } cout<<endl; break ; default : return ; } } while (1); } void gamescore::repair( int academynum, int projectnum) { cout<< "请重新输入该项成绩:" ; cin>>score[academynum-1][projectnum-1]; cout<< "修改成功" <<endl; } void gamescore:: remove ( int academynum, int projectnum) { score[academynum-1][projectnum-1]=0; cout<< "!!删除成功" <<endl; } void gamescore::output1( int academynum) { //cout<<"该学院运动项目编号及对应的成绩如下:"<<endl; for ( int i=0;i<m+w;i++) { cout<<1+i<<setw(5); } cout<<endl; for (i=0;i<m+w;i++) { cout<<score[academynum-1][i]<<setw(5); } } void gamescore::output2( int academynum) { cout<< "该院男团成绩为" <<academymentotalscore(academynum)<<endl; cout<< "该院女团成绩为" <<academywomentotalscore(academynum)<<endl; } ///////////////////////////////////////////////////// void main() { int projectnum; int academynum; gamescore a; int num; ////////////////////////////////////////////菜单 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<< " ** 7 对成绩按院系进行排序 **" <<endl; cout<< " ** 8 对成绩按男团进行排序 **" <<endl; cout<< " ** 9 对成绩按女团进行排序 **" <<endl; cout<< " ** 10 保存成绩信息 **" <<endl; cout<< " ** 0 退出该程序 **" <<endl; cout<< " **********************************************" <<endl<<endl; cout<< " 输入参加院系数 n=" ; cin>>n; cout<< " 输入男子项目数 m=" ; cin>>m; cout<< " 输入女子项目数 w=" ; cin>>w; do { cout<< "请选择要操作的菜单标号:" ; cin>>num; if (num>10||num<0) { cout<< "输入有误,请重新输入要操作的项目编号:" ; cin>>num; } switch (num) { case 1: a.input(); break ; case 2: cout<< "输入要查找的院系:" ; cin>>academynum; cout<< "输入要查询的运动项目编号:" ; cin>>projectnum; a.search(academynum,projectnum); break ; case 3: cout<< "输入要修改的院系编号" ; cin>>academynum; cout<< "输入要修改的运动项目的编号:" ; cin>>projectnum; a.repair(academynum,projectnum); break ; case 4: cout<< "输入要删除成绩所在的院系的编号:" ; cin>>academynum; cout<< "输入要删除运动项目编号:" ; cin>>projectnum; a. remove (academynum,projectnum); break ; case 5: cout<< "输入要查询成绩的院系编号:" ; cin>>academynum; a.output1(academynum); break ; case 6: cout<< "输入要查询团体成绩的院系的编号:" ; cin>>academynum; a.output2(academynum); break ; case 7: cout<< "该学院运动项目编号及对应学院总分的成绩如下:" ; a.hold(); a.sort1(); break ; case 8: cout<< "该学院运动项目编号及对应男团的成绩如下:" ; a.hold(); a.sort2(); break ; case 9: cout<< "该学院运动项目编号及对应女团的成绩如下:" ; a.hold(); a.sort3(); break ; case 10: a.save(); cout<< "!!保存成功" <<endl; break ; default : return ; } } while (1); } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/u014094726/article/details/33117665?utm_source=blogxgwz8