服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - C++实现寝室卫生管理系统

C++实现寝室卫生管理系统

2022-10-21 13:58编程小白2.0 C/C++

这篇文章主要为大家详细介绍了C++实现寝室卫生管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C++实现寝室卫生管理系统的具体代码,供大家参考,具体内容如下

介绍:

当初写程序的时候很多知识都不足,我算是一个半路出家的。当时在另一课本上看到goto语句,感觉挺有趣的,就用上了,但goto语句,不适合很长的代码,由易造成逻辑混乱,也可以换成do-while语句。

我设计了输出表格框架,再循环输出数据,为使数据对齐,使用setw(),setw(int n)是c+ +中在输出操作中使用的字段宽度设置,设置输出的域宽,n表示字段宽度。此函数只对紧接着的输出有效,紧接着的输出结束后又变回默认的域宽。当后面紧跟着的输出字段长度小于n的时候,在该字段前面用空格补齐;当输出字段长度大于n时,全部整体输出。头文件为:iomanip;

输入密码时,如非回车键,皆输出“*”,通过getch()函数实现,此函数是一个不回显函数,当用户按下某个字符时,函数自动读取,无需按回车键,所在头文件:conio.h,int __cdecl getch();声明,等,还用了一些算法,在此先不做详细介绍。

一、基本功能

1.(管理员,需要密码)实现成绩录入(地面卫生、床铺、物品摆放及其他)成绩求和和保存、修改及删除

2.(学生查询)实现显示所有寝室成员(按寝室号排序和按成绩排序)、显示自己寝室成绩-输入号(按寝室号排序和按成绩排序)、本周文明寝室、本周差评寝室

二、扩展功能

1.管理员也可对学生寝室信息包括寝室号,寝室成员进行基本管理,包括增,删,查,改等功能

2.对系统使用成员实现所有寝室成绩的查询,显示功能(可按寝室号排序或成绩排序),学生也可查看其他寝室相关信息

三、功能结构

 本系统的总体功能结构是:首先学生可以查看寝室卫生检查结果信息,管理员具有唯一的帐号以及密码,登录后可以对基本数据进行增删改查等操作。

总体分为五大模块:寝室基本信息录入模块,寝室基本信息修改模块,寝室基本信息查询模块,寝室基本信息显示模块,寝室基本信息保存模块。总体功能结构图如图所示:

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
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
#include<iostream>
#include<conio.h>
#include<fstream>
#include<iomanip>
#include<string>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#define M 50//表长
typedef int shu;
//寝室信息结构
typedef struct {
    shu ground;//地面卫生
    shu bed;//床铺
    shu article;//物品摆放
    shu other;//其他
    shu grade;//总成绩
    char member[50];//寝室成员
    char number[10];//寝室号
    int Total;
}Student, St;
 
Student S[M];
 
//1、定义清屏函数
void Clear()
{
    system("pause");
    system("cls");
}
//2、定义显示函数表头
void showhead()
{
    cout << "\n********************欢迎使用宿舍卫生管理系统********************\n " << endl;
    cout << "\n    显示方式:\n " << endl;
    cout << "\t①按成绩显示\n" << endl;
    cout << "\t②按寝室显示\n" << endl;
    cout << "\t③返回上级\n\n" << endl;
    cout << "\t    请选择:";
}
//3、登录函数
void load()
{
    int n1; int i;
loop:cout << "\n********************欢迎使用宿舍卫生管理系统********************\n\n" << endl;
    cout << "\t\t帐号:";
    cin >> n1;
    cout << "\t\t密码:";
    char a[40], b[14] = { "20190228" };
    for (i = 0;; i++)
    {
        int __cdecl getch();
        a[i] = getch();
        if (a[i] != '\r')
            cout << "*";
        else {
            a[i] = '\0';
            if (strcmp(a, b) == 0 && n1 == 20190228)
            {
                cout << "\n登录成功。。。。\n" << endl;
                Clear();
            }
            else {
                cout << "\n用户名或密码错误。。。\n" << endl;
                Clear();
                goto loop;
            }
            break;
        }
    }
}
//4、定义查询函数表头
void searchheader()
{
    cout << "\n********************欢迎使用宿舍卫生管理系统********************\n\n " << endl;
    cout << "\t①按成绩查询\n" << endl;
    cout << "\t②按寝室查询\n" << endl;
    cout << "\t③返回上级\n\n" << endl;
    cout << "    请选择:";
}
//5、定义录入函数
void Add(Student* S)
{
    char ch[10];
    char ch1[2] = { "0" };
    do
    {
        cout << "\n********************欢迎使用宿舍卫生管理系统********************\n\n" << endl;
        cout << "\t****************学生信息录入****************\n";
        cout << "请输入第" << S[0].Total + 1 << "个寝室的信息\n";
        cout << "寝 室 号:";
        cin >> S[S[0].Total + 1].number;
        cout << " 成  员 :";
        cin >> S[S[0].Total + 1].member;
        cout << "地面卫生:";
        cin >> S[S[0].Total + 1].ground;
        cout << " 床  铺 :";
        cin >> S[S[0].Total + 1].bed;
        cout << "物品摆放:";
        cin >> S[S[0].Total + 1].article;
        cout << " 其  他 :";
        cin >> S[S[0].Total + 1].other;
        cout << "总 成 绩:";
        S[S[0].Total + 1].grade = S[S[0].Total + 1].ground + S[S[0].Total + 1].bed + S[S[0].Total + 1].article + S[S[0].Total + 1].other;
        cout<< S[S[0].Total + 1].grade<<endl;
        S[0].Total++;
        cout << "按数字“0”退出,任意键继续录入: " ;
        cin >> ch;
        system("cls");//清屏函数
    } while (strcmp(ch, ch1) != 0);
}
//6、定义显示函数 
void Display_All(Student* S)
{
 
    cout << "\n" << endl;
    int i;
    cout << "                                                                                                   " << endl;
    cout << "  ———————————————————————————————————————————————— " << endl;
    cout << " |                                     学 生 宿 舍 信 息                                          |" << endl;
    cout << " |————————————————————————————————————————————————|" << endl;
    cout << " | 寝室号 | 总成绩 |              寝  室  成  员              |地面卫生| 床  铺 |物品摆放| 其  他 |" << endl;
    if (S[0].Total > 0)
    {
        for (i = 1; i <= S[0].Total; i++)
        {
            cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
            cout << " |" << setw(8) << S[i].number << "|" << setw(8) << S[i].grade << "|";
            cout << setw(42) << S[i].member << "|" << setw(8) << S[i].ground << "|";
            cout << setw(8) << S[i].bed << "|" << setw(8) << S[i].article << "|";
            cout << setw(8) << S[i].other << "|" <<endl ;
        }
    }
    else
    {
        cout << " |————————————————————————————————————————————————|" << endl;
        cout << "                                没 有 任 何 学 生 信 息                                            " << endl;
    }
    cout << "  ———————————————————————————————————————————————— " << endl;
}
//7、排序函数按照成绩从小到大排序(快排)
int Partition(Student* S, int low, int high)
{//对顺序表中的子表进行一趟排序,返回枢轴位置
    shu  pivotkey;
    Student i;
    i = S[low];//用i作枢轴记录
    pivotkey = S[low].grade;//枢轴成绩保存在pivokey中
    while (low < high)//从表的两端交替的向中间扫描 
    {
        while (low < high && S[high].grade >= pivotkey) --high;
        S[low] = S[high];//将比枢轴记录小的记录移到低端
        while (low < high && S[low].grade <= pivotkey) ++low;
        S[high] = S[low];//比枢轴记录大的记录移到高端
    }
    S[low] = i;//枢轴记录到位 
    return low; //返回枢轴位置 
}
void QSort(Student* S, int low, int high)
{
    //对顺序表中的子表进行快速排序
    int pivotloc;
    if (low < high) //长度大于1
    {
        pivotloc = Partition(S, low, high);//将子表一分为二,pivotloc是枢轴位置
        QSort(S, low, pivotloc - 1);//对左子表递归排序
        QSort(S, pivotloc + 1, high);//对右子表递归排序
    }
}
void Sort_grade(Student* S)
{//对顺序表L进行快速排序
    QSort(S, 1, S[0].Total);
}
//8、排序函数按照寝室号从小到大排序(堆排序) 
void HeapAdjust(Student* S, int s, int m)
{
    Student rc; int j;
    rc = S[s];
    for (j = 2 * s; j <= m; j *= 2)//沿number较大的孩子结点向下筛选
    {
        if (j < m&& strcmp(S[j].number, S[j + 1].number)<0) ++j;//j为number较大的记录下标
        if (strcmp(rc.number , S[j].number)>=0) break;//rc应插入在位置s上
        S[s] = S[j]; s = j;
    }
    S[s] = rc;
}
void CreatHeap(Student* S)
{//把无序序列S[1...n]建成大根堆
    int n, i;
    n = S[0].Total;
    for (i = n / 2; i > 0; --i)//反复调用HeapAdjust
        HeapAdjust(S, i, n);
}
void Sort_number(Student* S)
{//对顺序表S进行堆排序
    int i;
    Student x;
    CreatHeap(S);
    for (i = S[0].Total; i > 1; --i)
    {
        x = S[1];//将堆顶记录和当前未经排序子序列S[1...i]中最后一个记录互换
        S[1] = S[i];
        S[i] = x;
        HeapAdjust(S, 1, i - 1);//将S[1..i-1]重新调整为大根堆
    }
}
//9、查询函数以成绩为关键字进行查询(折半查找)
void searh_grade(Student* S)
{
    int high, low, mid;
    int j=0;
    shu grade;
    low = 1;
    high = S[0].Total;
    cout << "请输入你要查找学生的成绩:";
    cin >> grade;
    Sort_grade(S);//声明排序函数按照成绩从小到大排序(快排)
    cout << "\n\n" << endl;
    cout << "  ———————————————————————————————————————————————— " << endl;
    cout << " |                                     所 查 找 寝 室 信 息                                       |" << endl;
    cout << " |————————————————————————————————————————————————|" << endl;
    cout << " | 寝室号 | 总成绩 |               寝  室  成  员             |地面卫生| 床  铺 |物品摆放| 其  他 |" << endl;
    if (grade== S[1].grade)
    {
        cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
        cout << " |" << setw(8) << S[1].number << "|" << setw(8) << S[1].grade << "|";
        cout << setw(42) << S[1].member << "|" << setw(8) << S[1].ground << "|";
        cout << setw(8) << S[1].bed << "|" << setw(8) << S[1].article << "|";
        cout << setw(8) << S[1].other <<  "|"<<endl;
        j = 1;
    }
    else
        if (grade == S[(S[0].Total)].grade)
        {
            cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
            cout << " |" << setw(8) << S[S[0].Total].number << "|" << setw(8) << S[S[0].Total].grade << "|";
            cout << setw(42) << S[S[0].Total].member << "|" << setw(8) << S[S[0].Total].ground << "|";
            cout << setw(8) << S[S[0].Total].bed << "|" << setw(8) << S[S[0].Total].article << "|";
            cout << setw(8) << S[S[0].Total].other << "|" << endl;
            j = 1;
        }
        else
        {
            while (low <= high)
            {
                mid = (low + high) / 2;
                if (grade == S[mid].grade)
                {
                    int i = mid;
                    cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
                    cout << " |" << setw(8) << S[i].number << "|" << setw(8) << S[i].grade << "|";
                    cout << setw(42) << S[i].member << "|" << setw(8) << S[i].ground << "|";
                    cout << setw(8) << S[i].bed << "|" << setw(8) << S[i].article << "|";
                    cout << setw(8) << S[i].other << "|" << endl;
                    j = 1;
                    break;
                }
                else
                    if (grade > S[mid].grade)
                        low = mid + 1;
                    else
                        high = mid - 1;
            }
        }
    if (j != 1)
    {
        cout << " |————————————————————————————————————————————————|" << endl;
        cout << " |                                     查 无 此 寝 室 信 息                                       |" << endl;
    }
    cout << "  ———————————————————————————————————————————————— " << endl;
}
//10、查询函数以寝室号为关键字进行查询(折半查找)
void searh_number(Student* S)
{
    int high, low, mid;
    char number[20];
    int j=0;
    low = 1;
    high = S[0].Total;
    cout << "请输入你要查找学生的寝室号:";
    cin >> number;
    Sort_number(S);//声明排序函数按照寝室号从小到大排序(堆排序)
    cout << "'\n\n" << endl;
    cout << "  ———————————————————————————————————————————————— " << endl;
    cout << " |                                     所 查 找 的 寝 室 信 息                                    |" << endl;
    cout << " |————————————————————————————————————————————————|" << endl;
    cout << " | 寝室号 | 总成绩 |               寝  室  成  员             |地面卫生| 床  铺 |物品摆放| 其  他 |" << endl;
    while (low <= high)
    {
        mid = (low + high) / 2;
        if (strcmp(number, S[mid].number) == 0)
        {
            int i = mid; j = 1;
            cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
            cout << " |" << setw(8) << S[i].number << "|" << setw(8) << S[i].grade << "|";
            cout << setw(42) << S[i].member << "|" << setw(8) << S[i].ground << "|";
            cout << setw(8) << S[i].bed << "|" << setw(8) << S[i].article << "|";
            cout << setw(8) << S[i].other << "|" << endl;
 
            for (i = mid + 1; i <= high; i++)
            {
                if (strcmp(number, S[i].number) == 0)
                {
                    cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
                    cout << " |" << setw(8) << S[i].number << "|" << setw(8) << S[i].grade << "|";
                    cout << setw(42) << S[i].member << "|" << setw(8) << S[i].ground << "|";
                    cout << setw(8) << S[i].bed << "|" << setw(8) << S[i].article << "|";
                    cout << setw(8) << S[i].other << "|" << endl;
                }
            }
            for (i = mid - 1; i >= low; i--)
            {
                if (strcmp(number, S[i].number) == 0)
                {
                    cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
                    cout << " |" << setw(8) << S[i].number << "|" << setw(8) << S[i].grade << "|";
                    cout << setw(42) << S[i].member << "|" << setw(8) << S[i].ground << "|";
                    cout << setw(8) << S[i].bed << "|" << setw(8) << S[i].article << "|";
                    cout << setw(8) << S[i].other << "|" << endl;
                }
            }
            break;
        }
        else
            if (strcmp(number, S[mid].number) > 0)
                low = mid + 1;
            else
                high = mid - 1;
    }
    if (j != 1)
    {
        cout << " |————————————————————————————————————————————————|" << endl;
        cout << " |                                     查 无 此 寝 室 信 息                                       |" << endl;
    }
    cout << "  ———————————————————————————————————————————————— " << endl;
}
//11、判断是否是文明寝室
void y_n_number(Student* S)
{
    int high, low, mid;
    char number[20];
    int j=0;
    low = 1;
    high = S[0].Total;
    cout << "请输入你要查找学生的寝室号:";
    cin >> number;
    Sort_number(S);//声明排序函数按照寝室号号从小到大排序(堆排序)
    while (low <= high)
    {
        mid = (low + high) / 2;
        if (strcmp(number, S[mid].number) == 0)
        {
            int i = mid; j = 1;
            if (S[i].grade >= 80)
                cout << "\n\n本周文明寝室\n\n";
            else cout << "\n\n本周差评寝室\n\n";
 
            for (i = mid + 1; i <= high; i++)
            {
                if (strcmp(number, S[i].number) == 0)
                {
                    if (S[i].grade >= 80)
                        cout << "\n\n本周文明寝室\n\n";
                    else cout << "\n\n本周差评寝室\n\n";
                }
            }
            for (i = mid - 1; i >= low; i--)
            {
                if (strcmp(number, S[i].number) == 0)
                {
                    if (S[i].grade >= 80)
                        cout << "\n\n本周文明寝室\n\n";
                    else cout << "\n\n本周差评寝室\n\n";
                }
            }
            break;
        }
        else
            if (strcmp(number, S[mid].number) > 0)
                low = mid + 1;
            else
                high = mid - 1;
    }
    if (j != 1)
    {
        cout << "  ———————————————————————————————————————————————— " << endl;
        cout << " |                                            查 无 此 寝 室 信 息                                |" << endl;
        cout << "  ———————————————————————————————————————————————— " << endl;
    }
}
//12、定义修改学生信息表头函数
void Exchangehead()
{
    cout << "\n********************欢迎使用宿舍卫生管理系统********************\n\n " << endl;
    cout << "    ********************修改菜单********************\n " << endl;
    cout << "\t①单个删除信息\n" << endl;
    cout << "\t②删除全部信息\n" << endl;
    cout << "\t③修改寝室信息\n" << endl;
    cout << "\t④返回上级菜单\n\n" << endl;
    cout << "    请选择:";
}
//13、写文件函数
void Keep(Student* S)
{
    ofstream output("学生宿舍信息.txt");//初始化输出流对象
    if (output.is_open())
    {
        int i, j;
        j= S[0].Total;
        output << j<<endl;
        for (i = 1; i <= S[0].Total; i++)
        {
            output << S[i].number<<endl;
            output << S[i].grade<<endl;
            output << S[i].member << endl;
            output << S[i].ground << endl;
            output << S[i].bed << endl;
            output << S[i].article << endl;
            output << S[i].other << endl;
        }
    }
    output.close();
}
//14、读文件函数
void Input(Student* S)
{
    ifstream input("学生宿舍信息.txt",ios::in);//初始化输出流对象
    if (input.is_open())
    {
        int i,j;
        input >> j;
        S[0].Total = j;
        for (i = 1; i <= S[0].Total; i++)
        {
            input >> S[i].number;
            input >> S[i].grade;
            input >> S[i].member;
            input >> S[i].ground;
            input >> S[i].bed;
            input >> S[i].article;
            input>> S[i].other;
        }
    }
    input.close();
}
//主函数开始
void main()
{
    Student S[M];
    S[0].Total = 0;
    Input(S);
loop1:cout << "\n********************欢迎使用宿舍卫生管理系统********************\n" << endl;
    cout << "\n    请选择以何身份登录系统:\n\n\n";
    cout << "\t1、管理员\n\n";
    cout << "\t2、学生\n\n";
    cout << "\t3、退出系统\n\n";
    cout << "\t请选择:";
    int x;
    cin >> x;
    
    switch (x)
    {
    case 1: {
        system("cls");//清屏函数;
        load();//调用登录函数
        int choicem;
        do {
            cout << "\n********************欢迎使用宿舍卫生管理系统********************\n" << endl;
            cout << "\t ********************主菜单********************\n " << endl;
            cout << "\t①录入学生信息\n" << endl;
            cout << "\t②显示学生信息.\n" << endl;
            cout << "\t③查询学生信息\n" << endl;
            cout << "\t④修改学生信息\n" << endl;
            cout << "\t⑤存储学生信息\n" << endl;
            cout << "\t⑥返回上级\n" << endl;
            cout << "\t⑦退出系统\n\n" << endl;
            cout << "\t请选择:";
            cin >> choicem;
            
            switch (choicem)
            {
            case 1: // 录入信息.
            {
                system("cls");//清屏函数
                Add(S); // 调用录入信息函数
                system("cls");//清屏函数
                Keep(S);
                break;
            }
            case 2: // 显示学生信息
            {
                system("cls");//清屏函数
                int choice2;
            loop2:showhead();
                cin >> choice2;
                if (choice2 == 1)
                {
                    Sort_grade(S);//调用排序函数按照成绩从小到大排序(快排) 
                    system("cls");//清屏函数
                    cout << "按成绩大小显示信息." << endl;
                    Display_All(S); // 调用显示学生信息函数
                    Keep(S);
                    Clear();
                    goto loop2;
                    system("cls");//清屏函数
                }
                else if (choice2 == 2)
                {
                    Sort_number(S);//排序函数按照寝室号从小到大排序(堆排序)
                    system("cls");//清屏函数
                    cout << "按寝室号大小显示信息." << endl;
                    Display_All(S); // 调用显示学生信息函数
                    Keep(S);
                    Clear();
                    goto loop2;
                    system("cls");//清屏函数
                }
                else if (choice2 == 3)
                {
                    system("cls");//清屏函数
                    break;
                }
                else {
                    cout << "\n\t输入错误,请重新输入。。。。 " << endl;
                    Clear();
                    goto loop2;
                }
            }
            case 3: // 查询学生信息、
            {
                system("cls");//清屏函数
                int choice3;
            loop3:searchheader();//调用查询表头函数
                cin >> choice3;
                if (choice3 == 1)//按成绩查询
                {
                    system("cls");//清屏函数
                    searh_grade(S);//查询函数以成绩为关键字进行查询(折半查找)
                    Clear();
                    goto loop3;
                }
                else if (choice3 == 2)//按寝室号查询
                {
                    system("cls");//清屏函数
                    searh_number(S);//调用查询函数以寝室号为关键字进行查询(折半查找)
                    Clear();
                    goto loop3;
                }
                else if (choice3 == 3)//返回上级菜单
                    system("cls");//清屏函数
                else // 输入错误
                {
                    cout << "\n\n\t选择错误,请重新输入。。。 \n" << endl;
                    Clear();
                    goto loop3;
                }
                break;
            }
            case 4: // 修改学生信息
            {
                system("cls");//清屏函数
            loop4: Exchangehead();//调用修改学生信息表头函数
                int choice1;
                cin >> choice1;
 
                if (choice1 == 1)//单个删除
                {
                    int i, j;
                    int flag = 0; // 用来判断表中是否存在所要册除的学生的信息.
                    char number[20];
 
                    system("cls");//清屏函数
                    cout << "请输入你要删除寝室的寝室号:";
                    cin >> number;
                    for (i = 1; i <= S[0].Total; i++)
                        if (strcmp(S[i].number, number) == 0)
                            flag = i;
                    if (!flag) {
                        cout << "\n \n\t你所要删除的信息在表中不存在! \n" << endl;
                        Clear();
                        goto loop4;
                    }
                    else {
                        for (i = flag; i <= S->Total; i++)
                        {
                            j = i + 1;
                            S[i] = S[j];
                        }
                        S[0].Total--;
                        cout << "\n\t删除成功!\n" << endl;
                        Clear();
                        Keep(S);
                        goto loop4;
                    }
                }
                else if (choice1 == 2) // 全部删除
                {
                    system("cls");//清屏函数
                    S[0].Total = 0;
                    cout << "\n\n\n          册除成功。。。。。\n\n" << endl;
                    Clear();
                    Keep(S);
                    goto loop4;
                }
                else if (choice1 == 3)//修改信息
                {
                    int i;
                    int flag = 0; // 用来判断表中是否存在所要修改的学生的信息.
                    char number[20];
                    system("cls");//清屏函数
                    cout << "请输入你要修改的寝室的寝室号:";
                    cin >> number;
                    for (i = 1; i <= S[0].Total; i++)
                        if (strcmp(S[i].number, number) == 0)
                            flag = i;
                    if (!flag)
                    {
                        cout << "\n\t你所要修改的学生在表中不存在! \n" << endl;
                        Clear();
                        goto loop4;
                    }
                    else
                    {
                        cout << "\n\n" << endl;
                        cout << "  ———————————————————————————————————————————————— " << endl;
                        cout << " |                                     修 改 前 的 寝 室 信 息                                    |" << endl;
                        cout << " |————————————————————————————————————————————————|" << endl;
                        cout << " | 寝室号 | 总成绩 |              寝  室  成  员              |地面卫生| 床  铺 |物品摆放| 其  他 |" << endl;
                        cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
                        cout << " |" << setw(8) << S[flag].number << "|" << setw(8) << S[flag].grade << "|";
                        cout << setw(42) << S[flag].member << "|" << setw(8) << S[flag].ground << "|";
                        cout << setw(8) << S[flag].bed << "|" << setw(8) << S[flag].article << "|";
                        cout << setw(8) << S[flag].other << "|" << endl;
                        cout << "  ———————————————————————————————————————————————— " << endl;
                        cout << "********************学生信息修改********************\n";
                        cout << " 寝室号 :";
                        cin >> S[flag].number;
                        cout << " 成  员 :";
                        cin >> S[flag].member;
                        cout << "地面卫生:";
                        cin >> S[flag].ground;
                        cout << " 床  铺 :";
                        cin >> S[flag].bed;
                        cout << "物品摆放:";
                        cin >> S[flag].article;
                        cout << " 其  他 :";
                        cin >> S[flag].other;
                        cout << " 总成绩 :";
                        S[flag].grade = S[flag].ground + S[flag].bed + S[flag].article + S[flag].other;
                        cout << S[flag].grade;
                        cout << "\n";
                        cout << "  ———————————————————————————————————————————————— " << endl;
                        cout << " |                                     修 改 后 的 寝 室 信 息                                    |" << endl;
                        cout << " |————————————————————————————————————————————————|" << endl;
                        cout << " | 寝室号 | 总成绩 |              寝  室  成  员              |地面卫生| 床  铺 |物品摆放| 其  他 |" << endl;
                        cout << " |————|————|—————————————————————|————|————|————|————|" << endl;
                        cout << " |" << setw(8) << S[flag].number << "|" << setw(8) << S[flag].grade << "|";
                        cout << setw(42) << S[flag].member << "|" << setw(8) << S[flag].ground << "|";
                        cout << setw(8) << S[flag].bed << "|" << setw(8) << S[flag].article << "|";
                        cout << setw(8) << S[flag].other << "|" << endl;
                        cout << "  ———————————————————————————————————————————————— " << endl;
                        Clear();
                        Keep(S);
                        goto loop4;
                    }
                }
                else
                    if (choice1 == 4)//返回上级菜单
                    {
                        system("cls");//清屏函数
                        break;
                    }
                    else//输入错误
                    {
                        cout << "\n\t选择错误,请重新选择。。。\n" << endl;
                        Clear();
                        goto loop4;
                    }
            }
            case 5: // 存储学生信息、
            {
                system("cls");//清屏函数
                Keep(S);
                cout << "\n********************欢迎使用宿舍卫生管理系统********************\n " << endl;
                cout << "\n\t存储成功。。。。。\n" << endl;
                Clear();
                break;
            }
            case 6: //返回上级
            {
                system("cls");//返回上级
                goto loop1;
            }
            case 7:break; // 退出管理系统
            default: {
                cout << "\n\n\t输入错误,请重新选择。。。\n\n" << endl;
                Clear();
                break;
            }
            }
        } while (choicem != 7);
        break;
    }
    case 2: {
        system("cls");//清屏函数;
        int choice;
        do {
            cout << "\n********************欢迎使用宿舍卫生管理系统********************\n " << endl;
            cout << "\n    显示方式:\n " << endl;
            cout << "\t①按寝室查询\n" << endl;
            cout << "\t②按寝室显示\n" << endl;
            cout << "\t③按成绩显示\n" << endl;
            cout << "\t④本周寝室评价\n" << endl;
            cout << "\t⑤返回上级\n" << endl;
            cout << "\t⑥退出系统\n\n" << endl;
            cout << "    请选择:";
            cin >> choice;
            if (choice == 1)//按成绩查询
            {
                system("cls");//清屏函数
                searh_number(S);// 查询函数以寝室号为关键字进行查询(折半查找)
                Clear();
 
            }
            else if (choice == 2)//按寝室号显示
            {
                system("cls");//清屏函数
                Sort_number(S);//排序函数按照寝室号从小到大排序(堆排序)
                Display_All(S);//显示函数
                Clear();
            }
            else if (choice == 3)//按成绩显示
            {
                Sort_grade(S);//调用排序函数按照成绩从小到大排序(快排) 
                system("cls");//清屏函数
                Display_All(S); // 调用显示学生信息函数
                Clear();
            }
            else if (choice == 4)
            {
                system("cls");//清屏函数
                y_n_number(S);//是否是文明寝室ok
                Clear();
            }
            else if (choice == 5)//返回上级
            {
                system("cls");//清屏函数
                goto loop1;
            }
            else if(choice == 6)
            {
                break;
            }
            else {
                cout << "\n\t输入错误,请重新输入。。。。 \n\n" << endl;
                Clear();
            }
        } while (choice != 5);
        break;
    }
    case 3:break;
    default: {
        cout << "\n\n\t输入错误,请重新输入。。。\n\n"<<endl;
        Clear();
        goto loop1;
    }
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq_51926288/article/details/115083266

延伸 · 阅读

精彩推荐