基于C++语言实现机动车违章处罚管理系统

时间:2022-06-19 14:04:38

关键代码如下所示:

?
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <list>
using namespace std;
class Violation{
public:
Violation(){points=fine=0;
number=carNumber=tel=location=isSpot
=police=camera=type=isTreated=treatmentDate=notes="";}
Violation(string snumber,string sdate="",string scarNumber="",string stel="",
string slocation="",int ipoints=-1,string sisSpot="",
string spolice="",string scamera="",string itype="",int ifine=0,
string sisTreated="",string streatmentDate="",string snotes="")
:number(snumber),date(sdate),carNumber(scarNumber),tel(stel),
location(slocation),points(ipoints),isSpot(sisSpot),police(spolice),
camera(scamera),type(itype),fine(ifine),isTreated(sisTreated),
treatmentDate(streatmentDate),notes(snotes){}
bool operator==(const Violation& vltn); //查找用
friend bool compNumber(Violation& vltn1,Violation& vltn2); //编号比较规则
friend bool compDate(Violation& vltn1,Violation& vltn2); //日期比较规则
friend bool compCarNumber(Violation& vltn1,Violation& vltn2); //车牌号比较规则
friend bool compLocation(Violation& vltn1,Violation& vltn); //地点比较规则
friend bool compPoints(Violation& vltn1,Violation& vltn); //扣分比较规则
friend istream& operator>>(istream& input,Violation& vltn);
friend ostream& operator<<(ostream& output,Violation& vltn);
friend class List;
friend int saveFile();
private:
string number; //编号
string date; //日期
string carNumber; //车牌号
string tel; //联系电话-
string location; //地点
int points; //扣分
string isSpot; //现场
string police; //现场执勤交警
string camera; //非现场摄像头编号
string type; //违章类别
int fine; //罚款
string isTreated; //是否处理
string treatmentDate; //处理日期
string notes; //备注
};
bool Violation::operator==(const Violation& vltn){
if(location==""||vltn.location=="")
if(tel==""||vltn.tel=="")
if(carNumber==""||vltn.carNumber=="")
if(date==""||vltn.date=="")
return number==vltn.number;
else return date==vltn.date;
else return carNumber==vltn.carNumber;
else return tel==vltn.tel;
else return location==vltn.location;
}
bool compNumber(Violation& vltn1,Violation& vltn2){
return vltn1.number>vltn2.number;
}
bool compDate(Violation& vltn1,Violation& vltn2){
return vltn1.date>vltn2.date;
}
bool compCarNumber(Violation& vltn1,Violation& vltn2){
return vltn1.carNumber<vltn2.carNumber;
}
bool compLocation(Violation& vltn1,Violation& vltn2){
return vltn1.location>vltn2.location;
}
bool compPoints(Violation& vltn1,Violation& vltn2){
return vltn1.points>vltn2.points;
}
istream& operator>>(istream& input,Violation& vltn){
input>>vltn.number>>vltn.date>>vltn.carNumber>>vltn.tel>>vltn.location
>>vltn.points>>vltn.isSpot>>vltn.police>>vltn.camera>>vltn.type
>>vltn.fine>>vltn.isTreated>>vltn.treatmentDate>>vltn.notes;
return input;
}
ostream& operator<<(ostream& output,Violation& vltn){
output<<setw(6)<<vltn.number
<<setw(9)<<vltn.date
<<setw(9)<<vltn.carNumber
<<setw(12)<<vltn.tel
<<setw(11)<<vltn.location
<<setw(5)<<vltn.points
<<setw(9)<<vltn.isSpot
<<setw(13)<<vltn.police
<<setw(17)<<vltn.camera
<<setw(11)<<vltn.type
<<setw(5)<<vltn.fine
<<setw(9)<<vltn.isTreated
<<setw(9)<<vltn.treatmentDate
<<setw(33)<<vltn.notes<<endl;
return output;
}
class List{
public:
friend class User;
int loadFile(); //读取文件
int saveFile(); //保存到文件
int insert(); //添加记录
int change(); //修改记录
int del(); //删除记录
int browse(); //浏览记录
int searchMenu(); //查询信息
int searchCarNumber(); //按车牌号
int searchDate(); //按日期查找
int searchTel(); //按电话查找
int searchLocation(); //按地点查询
int countMenu(); //统计信息
int countDate(); //按日期统计违章
int countCarNumber(); //按车牌统计违章
int countLocation(); //按地点统计违章
int countPoints(); //按扣分统计违章
static List* getList();
private:
list <Violation> vltnlist;
static List* m_list;
List(){};
List(const List&){}
List& operator=(const List&){}
};
const char* filepath="violation.dat"; //指定数据文件路径
bool checkNumber(string s,int size){
if(s.size()!=size) return false;
for(int i=0;i<size;i++)
if(s[i]<'0'||s[i]>'9') return false;
return true;
}
List* List::m_list=NULL;
List* List::getList(){
if(NULL==m_list) m_list=new List;
return m_list;
}
int List::loadFile(){
ifstream infile(filepath,ios::in);
if(infile)
for(;!infile.eof();){
Violation vltn;infile>>vltn;
vltnlist.push_back(vltn);
}
infile.close();
return 0;
}
int List::saveFile(){
ofstream outfile(filepath,ios::out);
list<Violation>::iterator it;
for(it=vltnlist.begin();it!=vltnlist.end();it++)
outfile<<endl<<it->number<<' '<<it->date<<' '<<it->carNumber<<' '
<<it->tel<<' '<<it->location<<' '<<it->points<<' '<<it->isSpot<<' '
<<it->police<<' '<<it->camera<<' '<<it->type<<' '<<it->fine<<' '
<<it->isTreated<<' '<<it->treatmentDate<<' '<<it->notes;
outfile.close();
return 0;
}
int List::insert(){
list<Violation>::iterator it;
string number,date,carNumber,tel,location,isSpot,police,camera,type,
isTreated,treatmentDate,notes;
int points,fine;
cout<<"请输入违章编号【放弃添加 0】【5位数字,如16384】:";
for(;;){
cin>>number;cin.sync();
if(number=="0") return 0;
if(!checkNumber(number,5)) {
cout<<"请输入有效编号:";
continue;
}
Violation l(number);
it=find(vltnlist.begin(),vltnlist.end(),l);
if(it!=vltnlist.end())
cout<<"编号已存在,请重新输入:";
else break;
}
cout<<"请输入违章日期【8位数字,如20160630】:";
while(1){
cin>>date;cin.sync();
if(!checkNumber(date,8)){
cout<<"请输入有效日期:";
continue;
}
else break;
}
cout<<"请输入违章车辆车牌号:";cin>>carNumber;cin.sync();
cout<<"请输入登记联系电话【11位数字,如13751516464】:";
while(1){
cin>>tel;cin.sync();
if(!checkNumber(tel,11)){
cout<<"请输入有效电话:";
continue;
}
else break;
}
cout<<"请输入违章地点:";cin>>location;cin.sync();
cout<<"请输入处罚扣分【0~12分】:";
while(1){
if(cin>>points){
cin.sync();
if(points<0||points>12){
cout<<"请输入有效扣分:";
continue;
}
else break;
}
else{
cin.clear();cin.sync();
cout<<"请输入有效扣分:";
continue;
}
}
cout<<"请输入是否现场【是 1】:";cin>>isSpot;cin.sync();
if(isSpot=="1"){
cout<<"请输入现场执勤交警:";cin>>police;cin.sync();
isSpot="是";camera="现场";
}
else{
cout<<"请输入非现场摄像头编号【6位数字,如646464】:";
while(1){
cin>>camera;cin.sync();
if(!checkNumber(camera,6)){
cout<<"请输入有效编号:";
continue;
}
else break;
}
isSpot="否";police="非现场";
}
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<<"* | | *"<<endl;
cout<<"* └------------------------------------------------┘*"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"请选择违章类别:";
int Mark=1;
while(Mark){
char n;cin>>n;cin.sync();
switch(n){
case '1': type="超速";Mark=0;break;
case '2': type="酒驾";Mark=0;break;
case '3': type="闯红灯";Mark=0;break;
case '4': type="违规变道";Mark=0;break;
case '5': type="未系安全带";Mark=0;break;
case '6': type="超载";Mark=0;break;
default : cout<<"输入有误,请重新输入:";
}
}
cout<<"请输入罚款金额【0~5000元】:";
while(1){
if(cin>>fine){
cin.sync();
if(fine<0||fine>50000){
cout<<"请输入有效金额:";
continue;
}
else break;
}
else{
cin.clear();cin.sync();
cout<<"请输入有效金额:";
continue;
}
}
cout<<"请输入是否处理【是 1】:";cin>>isTreated;cin.sync();
if(isTreated=="1"){
cout<<"请输入处理日期【8位数字,如20160630】:";//cin>>treatmentDate;cin.sync();
while(1){
cin>>treatmentDate;cin.sync();
if(!checkNumber(treatmentDate,8)){
cout<<"请输入有效日期:";
continue;
}
else break;
}
isTreated="是";
}
else{
isTreated="否";treatmentDate="未处理";
}
cout<<"请输入备注【无 0】:";cin>>notes;cin.sync();
if(notes=="0") notes="无";
Violation vltn(number,date,carNumber,tel,location,points,isSpot,police,camera,
type,fine,isTreated,treatmentDate,notes);
vltnlist.push_back(vltn);
saveFile();
cout<<"车辆违章信息添加成功!";getchar();
return 0;
}
int List::change(){
list<Violation>::iterator it;
if(!vltnlist.size()){
cout<<"还没有记录,不能修改!"<<endl;getchar();
return 0;
}
string number,date,carNumber,tel,location,isSpot,police,camera,type,
isTreated,treatmentDate,notes;
int points,fine;
browse();
cout<<"请输入想要修改的记录编号【放弃0】:";
cin>>number;cin.sync();
if(number=="0") return 0;
Violation vltn(number);
it=find(vltnlist.begin(),vltnlist.end(),vltn);
if(it==vltnlist.end()){
cout<<"此编号不存在!";getchar();
return 0;
}
while(1){
system("cls");
cout<<" 当前信息 请输入"<<endl;
cout<<" 违章编号:"<<setw(17)<<(*it).number<<" 1"<<endl
<<" 违章日期:"<<setw(17)<<(*it).date<<" 2"<<endl
<<" 车辆车牌号:"<<setw(17)<<(*it).carNumber<<" 3"<<endl
<<" 登记联系电话:"<<setw(17)<<(*it).tel<<" 4"<<endl
<<" 违章地点:"<<setw(17)<<(*it).location<<" 5"<<endl
<<" 处罚扣分:"<<setw(17)<<(*it).points<<" 6"<<endl
<<" 是否现场:"<<setw(17)<<(*it).isSpot<<endl
<<" 现场执勤交警:"<<setw(17)<<(*it).police<<" 7"<<endl
<<" 非现场摄像头编号:"<<setw(17)<<(*it).camera<<" 8"<<endl
<<" 违章类别:"<<setw(17)<<(*it).type<<" 9"<<endl
<<" 罚款金额:"<<setw(17)<<(*it).fine<<" a"<<endl
<<" 是否处理:"<<setw(17)<<(*it).isTreated<<" b"<<endl
<<" 处理日期:"<<setw(17)<<(*it).treatmentDate<<" c"<<endl
<<" 备注:"<<endl<<setw(34)<<(*it).notes<<" d"<<endl;
cout<<"请选择要修改的条目【放弃修改 0】:";
int Mark=1;
while(Mark){
char n;cin>>n;cin.sync();
switch(n){
case '0': return 0;
case '1': cout<<"请输入违章编号【5位数字,如16384】:";//cin>>(*it).number;cin.sync();
for(;;){
cin>>number;cin.sync();
if(!checkNumber(number,5)) {
cout<<"请输入有效编号:";
continue;
}
Violation l(number);
list<Violation>::iterator nit;
nit=find(vltnlist.begin(),vltnlist.end(),l);
if(nit!=vltnlist.end())
cout<<"编号已存在,请重新输入:";
else {
(*it).number=number;break;
}
}
Mark=0;break;
case '2': cout<<"请输入违章日期【8位数字,如20160630】:";//cin>>(*it).date;cin.sync();
while(1){
cin>>date;cin.sync();
if(!checkNumber(date,8)){
cout<<"请输入有效日期:";
continue;
}
else {
(*it).date=date;break;
}
}
Mark=0;break;
case '3': cout<<"请输入车辆车牌号:";cin>>(*it).carNumber;cin.sync();
Mark=0;break;
case '4': cout<<"请输入登记联系电话:";//cin>>(*it).tel;cin.sync();
while(1){
cin>>tel;cin.sync();
if(!checkNumber(tel,11)){
cout<<"请输入有效电话【11位数字,如13751516464】:";
continue;
}
else {
(*it).tel=tel;break;
}
}
Mark=0;break;
case '5': cout<<"请输入违章地点:";cin>>(*it).location;cin.sync();
Mark=0;break;
case '6': cout<<"请输入处罚扣分【0~12分】:";//cin>>(*it).points;cin.sync();
while(1){
if(cin>>points){
cin.sync();
if(points<0||points>12){
cout<<"请输入有效扣分:";
continue;
}
else{
(*it).points=points;break;
}
}
else{
cin.clear();cin.sync();
cout<<"请输入有效扣分:";
continue;
}
}
Mark=0;break;
case '7': cout<<"请输入现场执勤交警:";cin>>(*it).police;cin.sync();
(*it).isSpot="是";(*it).camera="现场";
Mark=0;break;
case '8': cout<<"请输入非现场摄像头编号【6位数字,如646464】:";//cin>>(*it).camera;cin.sync();
while(1){
cin>>camera;cin.sync();
if(!checkNumber(camera,6)){
cout<<"请输入有效编号:";
continue;
}
else{
(*it).camera=camera;break;
}
}
(*it).isSpot="否";(*it).police="非现场";
Mark=0;break;
case '9': {
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<<"* | | *"<<endl;
cout<<"* └------------------------------------------------┘*"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"请选择违章类别:";
int Mark1=1;
while(Mark1){
char n1;cin>>n1;cin.sync();
switch(n1){
case '1': (*it).type="超速";Mark1=0;break;
case '2': (*it).type="酒驾";Mark1=0;break;
case '3': (*it).type="闯红灯";Mark1=0;break;
case '4': (*it).type="违规变道";Mark1=0;break;
case '5': (*it).type="未系安全带";Mark1=0;break;
case '6': (*it).type="超载";Mark1=0;break;
default : cout<<"输入有误,请重新输入:";
}
}
Mark=0;break;
}
case 'a': cout<<"请输入罚款金额【0~5000元】:";//cin>>(*it).fine;cin.sync();
while(1){
if(cin>>fine){
cin.sync();
if(fine<0||fine>50000){
cout<<"请输入有效金额:";
continue;
}
else{
(*it).fine=fine;break;
}
}
else{
cin.clear();cin.sync();
cout<<"请输入有效金额:";
continue;
}
}
Mark=0;break;
case 'b': cout<<"请输入是否处理【是 1】:";cin>>(*it).isTreated;cin.sync();
if((*it).isTreated=="1"){
cout<<"输入处理日期:";//cin>>(*it).treatmentDate;cin.sync();
while(1){
cin>>treatmentDate;cin.sync();
if(!checkNumber(treatmentDate,8)){
cout<<"请输入有效日期:";
continue;
}
else {
(*it).treatmentDate=treatmentDate;break;
}
}
(*it).isTreated="是";
}
else{
(*it).isTreated="否";(*it).treatmentDate="未处理";
}
Mark=0;break;
case 'c': cout<<"请输入处理日期【8位数字,如20160630】:";//cin>>(*it).treatmentDate;cin.sync();
while(1){
cin>>treatmentDate;cin.sync();
if(!checkNumber(treatmentDate,8)){
cout<<"请输入有效日期:";
continue;
}
else{
(*it).treatmentDate=treatmentDate;break;
}
}
Mark=0;break;
case 'd': cout<<"请输入备注:";cin>>(*it).notes;cin.sync();
Mark=0;break;
default : cout<<"输入有误,请重新输入:";
}
}
saveFile();
cout<<"修改成功!"<<endl
<<"继续修改请输入任意键,修改完毕请输入0:";
char ch;cin>>ch;cin.sync();
if(ch=='0') return 0;
}
}
int List::del(){
list<Violation>::iterator it;
if(!vltnlist.size()){
cout<<"还没有记录,不能删除!"<<endl;getchar();
return 0;
}
string number;
browse();
cout<<"请输入想要删除的编号【放弃0】:";
cin>>number;cin.sync();
if(number=="0") return 0;
Violation vltn(number);
it=find(vltnlist.begin(),vltnlist.end(),vltn);
if(it==vltnlist.end()){
cout<<"此编号不存在!";getchar();
return 0;
}
vltnlist.erase(it);
if(!vltnlist.size()) remove(filepath);
else saveFile();
cout<<"删除记录成功!";getchar();
return 0;
}
int List::browse(){
list<Violation>::iterator it;
if(!vltnlist.size()){
cout<<"还没有记录!"<<endl;getchar();
return 0;
}
vltnlist.sort(compNumber); //按编号降序排列
cout<<"当前共有 "<<vltnlist.size()<<"条记录,已按编号降序排列:"<<endl
<<" 编号 日期 车牌号 联系电话 地点 扣分 是否现场 现场执勤交警 非现场摄像头编号 违章类别 罚款 是否处理 处理日期 备注"<<endl;
for(it=vltnlist.begin();it!=vltnlist.end();it++)
cout<<*it;
getchar();
return 0;
}
int List::searchMenu(){
if(!vltnlist.size()){
cout<<"还没有记录,不能查询!"<<endl;getchar();
return 0;
}
while(1)
{
system("cls");
cout<<"*******************************************************"<<endl;
cout<<"* ★机动车违章处罚管理系统 ★ *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"* ┌-------------------查询菜单---------------------┐*"<<endl;
cout<<"* | | *"<<endl;
cout<<"* | 查询方式 请输入 | *"<<endl;
cout<<"* | ◆ 按日期查询 1 | *"<<endl;
cout<<"* | ◆ 按车牌号查询 2 | *"<<endl;
cout<<"* | ◆ 按电话查询 3 | *"<<endl;
cout<<"* | ◆ 按地点查询 4 | *"<<endl;
cout<<"* | | *"<<endl;
cout<<"* └------------------------------------------------┘*"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"* ● 返回主菜单 0 *"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"请选择查询方式:";
int Mark=1;
while(Mark){
char n;cin>>n;cin.sync();
switch(n)
{
case '1': searchDate();Mark=0;break;
case '2': searchCarNumber();Mark=0;break;
case '3': searchTel();Mark=0;break;
case '4': searchLocation();Mark=0;break;
case '0': return 0;
default : cout<<"输入有误,请重新输入:";
}
}
}
vltnlist.sort(compNumber);
return 0;
getchar();return 0;
}
int List::searchDate(){
list<Violation>::iterator it;
string date;
cout<<"请输入日期:";cin>>date;cin.sync();
Violation vltn("",date);
it=find(vltnlist.begin(),vltnlist.end(),vltn);
if(it!=vltnlist.end()){
cout<<"已找到日期为 "<<date<<" 的违章记录:"<<endl
<<" 编号 日期 车牌号 联系电话 地点 扣分 是否现场 现场执勤交警 非现场摄像头编号 违章类别 罚款 是否处理 处理日期 备注"<<endl
<<*it;
for(it++;it!=vltnlist.end();it++)
if(*it==vltn) cout<<*it;
}
else cout<<"没有该日期的违章记录!";
getchar();return 0;
}
int List::searchCarNumber(){
list<Violation>::iterator it;
string carNumber;
cout<<"请输入车牌号:";cin>>carNumber;cin.sync();
Violation vltn("","",carNumber);
it=find(vltnlist.begin(),vltnlist.end(),vltn);
if(it!=vltnlist.end()){
cout<<"已找到车牌号为 "<<carNumber<<" 的违章记录:"<<endl
<<" 编号 日期 车牌号 联系电话 地点 扣分 是否现场 现场执勤交警 非现场摄像头编号 违章类别 罚款 是否处理 处理日期 备注"<<endl
<<*it;
for(it++;it!=vltnlist.end();it++)
if(*it==vltn) cout<<*it;
}
else cout<<"没有该车牌号的违章记录!";
getchar();return 0;
}
int List::searchTel(){
list<Violation>::iterator it;
string tel;
cout<<"请输入联系电话:";cin>>tel;cin.sync();
Violation vltn("","","",tel);
it=find(vltnlist.begin(),vltnlist.end(),vltn);
if(it!=vltnlist.end()){
cout<<"已找到联系电话为 "<<tel<<" 的违章记录:"<<endl
<<" 编号 日期 车牌号 联系电话 地点 扣分 是否现场 现场执勤交警 非现场摄像头编号 违章类别 罚款 是否处理 处理日期 备注"<<endl
<<*it;
for(it++;it!=vltnlist.end();it++)
if(*it==vltn) cout<<*it;
}
else cout<<"没有该联系电话的违章记录!";
getchar();return 0;
}
int List::searchLocation(){
list<Violation>::iterator it;
string location;
cout<<"请输入地点:";cin>>location;cin.sync();
Violation vltn("","","","",location);
it=find(vltnlist.begin(),vltnlist.end(),vltn);
if(it!=vltnlist.end()){
cout<<"已找到地点为 "<<location<<" 的违章记录:"<<endl
<<" 编号 日期 车牌号 联系电话 地点 扣分 是否现场 现场执勤交警 非现场摄像头编号 违章类别 罚款 是否处理 处理日期 备注"<<endl
<<*it;
for(it++;it!=vltnlist.end();it++)
if(*it==vltn) cout<<*it;
}
else cout<<"没有该地点的违章记录!";
getchar();return 0;
}
int List::countMenu(){
list<Violation>::iterator it;
if(!vltnlist.size()){
cout<<"还没有记录,不能统计!"<<endl;getchar();
return 0;
}
while(1)
{
system("cls");
cout<<"*******************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* ★机动车违章处罚管理系统 ★ *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"* ┌--------------------统计菜单--------------------┐*"<<endl;
cout<<"* | | *"<<endl;
cout<<"* | 统计方式 请输入 | *"<<endl;
cout<<"* | ◆ 按日期统计违章数量 1 | *"<<endl;
cout<<"* | ◆ 按车牌号统计违章次数 2 | *"<<endl;
cout<<"* | ◆ 按地点统计违章数量 3 | *"<<endl;
cout<<"* | ◆ 显示处罚>=12分的记录 4 | *"<<endl;
cout<<"* | | *"<<endl;
cout<<"* └------------------------------------------------┘*"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"* ● 返回主菜单 0 *"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"请选择统计方式:";
int Mark=1;
while(Mark){
char n;cin>>n;cin.sync();
switch(n)
{
case '1': countDate();Mark=0;break;
case '2': countCarNumber();Mark=0;break;
case '3': countLocation();Mark=0;break;
case '4': countPoints();Mark=0;break;
case '0': return 0;
default : cout<<"输入有误,请重新输入:";
}
}
}
return 0;
getchar();return 0;
}
int List::countDate(){
list<Violation>::iterator it;
vltnlist.sort(compDate);
int sumVltn=0;string y,m1,m2,date1,date2;
cout<<"输入日期范围:"<<endl ;
cout<<"输入年份:";cin>>y;cin.sync();
cout<<"输入起始月份:";cin>>m1;cin.sync();
cout<<"输入结束月份:";cin>>m2;cin.sync();
date1=y+m1;date2=y+m2;
for(it=vltnlist.begin();it!=vltnlist.end();it++){
if((*it).date>=date1&&(*it).date<=date2) sumVltn++;
}
cout<<"该段时间内违章数量为:"<<sumVltn;//getchar();
//vltnlist.push_back(Violation("cutme"));
//it=vltnlist.begin();
/*
cout<<"已按月份统计违章数量:"<<endl
<<" 违章日期 违章数量"<<endl;
int sumVltn=0;string mouth=((*it).date).substr(4,2),date=(*it).date.substr(0,4);
for(it=vltnlist.begin();it!=vltnlist.end();it++)
if((*it).date!=""){
if(mouth!=((*it).date).substr(4,2)){
cout<<(*it).date.substr(0,4)<<"年"<<mouth<<"月"<<setw(9)<<sumVltn<<endl;
sumVltn=1;mouth=(*it).date.substr(4,2);date=(*it).date.substr(0,4);
}
else {
sumVltn++;
}
}
else{
cout<<date<<"年"<<mouth<<"月"<<setw(9)<<sumVltn<<endl;
}*/
//vltnlist.pop_back();
getchar();return 0;
}
int List::countCarNumber(){
list<Violation>::iterator it;
vltnlist.sort(compCarNumber);
vltnlist.push_back(Violation("cutme"));
it=vltnlist.begin();
cout<<"已按车牌号统计违章次数:"<<endl
<<" 车牌号 违章次数"<<endl;
string carNumber=(*it).carNumber;int sumVltn=0;
for(it=vltnlist.begin();it!=vltnlist.end();it++)
if(carNumber!=(*it).carNumber){
cout<<setw(9)<<carNumber<<setw(9)<<sumVltn<<endl;
carNumber=(*it).carNumber;sumVltn=1;
}
else sumVltn++;
vltnlist.pop_back();
getchar();return 0;
}
int List::countLocation(){
list<Violation>::iterator it;
vltnlist.sort(compLocation);
vltnlist.push_back(Violation("cutme"));
it=vltnlist.begin();
string location=(*it).location;int sumVltn=0;
cout<<"已按地点统计违章数量:"<<endl
<<" 地点 违章数量"<<endl;
for(it=vltnlist.begin();it!=vltnlist.end();it++)
if(location !=(*it).location){
cout<<setw(11)<<location<<setw(9)<<sumVltn<<endl;
location=(*it).location;sumVltn=1;
}
else sumVltn++;
vltnlist.pop_back();
getchar();return 0;
}
int List::countPoints(){
list<Violation>::iterator it;
vltnlist.sort(compCarNumber);
vltnlist.push_back(Violation("cutme"));
it=vltnlist.begin();
string carNumber=(*it).carNumber,tel=(*it).tel;
int sumPoints=0;
cout<<"已显示处罚>=12分的违章记录:"<<endl
<<" 车牌号 联系电话"<<endl;
for(it=vltnlist.begin();it!=vltnlist.end();it++)
if(carNumber!=(*it).carNumber){
if(sumPoints>11)
cout<<setw(9)<<carNumber<<setw(12)<<tel<<endl;
carNumber=(*it).carNumber;sumPoints=(*it).points;tel=(*it).tel;
}
else sumPoints+=(*it).points;
vltnlist.pop_back();
getchar();return 0;
}
int menu();
int main(){
List* myList=List::getList();
myList->loadFile();
menu();
myList->saveFile();
return 0;
}
int menu(){
while(1)
{
system("cls");
cout<<"*******************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* ★机动车违章处罚管理系统 ★ *"<<endl;
cout<<"* *"<<endl;
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<<"* | | *"<<endl;
cout<<"* └------------------------------------------------┘*"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"* ● 退出管理系统 0 *"<<endl;
cout<<"*******************************************************"<<endl;
cout<<"请选择功能:";
int Mark=1;
while(Mark){
char n;cin>>n;cin.sync();
List* myList=List::getList();
switch(n)
{
case '1': myList->insert();Mark=0;break;
case '2': myList->change();Mark=0;break;
case '3': myList->del();Mark=0;break;
case '4': myList->browse();Mark=0;break;
case '5': myList->searchMenu();Mark=0;break;
case '6': myList->countMenu();Mark=0;break;
case '0': exit(0);
default : cout<<"输入有误,请重新输入:";
}
}
}
return 0;
}

以上代码是基于C++语言实现机动车违章处罚管理系统的关键代码,代码附有注释,有不明白的地方欢迎给我留言,小编会及时回复大家的,大家可以更加需求适当的添加修改删除。