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

时间:2021-05-02

关键代码如下所示:

? 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; ca

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章