C++大型实验——机动车违章处罚管理系统

2018-06-17 23:56:41来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

  1 #include <iostream>
  2 #include <iomanip>
  3 #include <fstream>
  4 #include <string>
  5 #include <list>
  6 using namespace std;
  7 
  8 class Violation{
  9     public:
 10         Violation(){points=fine=0;
 11                     number=carNumber=tel=location=isSpot
 12                     =police=camera=type=isTreated=treatmentDate=notes="";}
 13         Violation(string snumber,string sdate="",string scarNumber="",string stel="",
 14                   string slocation="",int ipoints=-1,string sisSpot="",
 15                   string spolice="",string scamera="",string itype="",int ifine=0,
 16                   string sisTreated="",string streatmentDate="",string snotes="")
 17                   :number(snumber),date(sdate),carNumber(scarNumber),tel(stel),
 18                   location(slocation),points(ipoints),isSpot(sisSpot),police(spolice),
 19                   camera(scamera),type(itype),fine(ifine),isTreated(sisTreated),
 20                   treatmentDate(streatmentDate),notes(snotes){}
 21                   
 22         bool operator==(const Violation& vltn);                          //查找用 
 23         friend bool compNumber(Violation& vltn1,Violation& vltn2);       //编号比较规则 
 24         friend bool compDate(Violation& vltn1,Violation& vltn2);         //日期比较规则 
 25         friend bool compCarNumber(Violation& vltn1,Violation& vltn2);    //车牌号比较规则 
 26         friend bool compLocation(Violation& vltn1,Violation& vltn);      //地点比较规则 
 27         friend bool compPoints(Violation& vltn1,Violation& vltn);        //扣分比较规则     
 28         friend istream& operator>>(istream& input,Violation& vltn);
 29         friend ostream& operator<<(ostream& output,Violation& vltn); 
 30         friend class List;
 31         friend int saveFile();
 32     private:
 33         string number;           //编号
 34         string date;             //日期
 35         string carNumber;        //车牌号 
 36         string tel;              //联系电话-
 37         
 38         string location;         //地点 
 39         int points;              //扣分 
 40         string isSpot;           //现场 
 41         string police;           //现场执勤交警 
 42         
 43         string camera;           //非现场摄像头编号 
 44         string type;             //违章类别 
 45         int fine;                //罚款
 46         string isTreated;        //是否处理 
 47         
 48         string treatmentDate;    //处理日期 
 49         string notes;            //备注 
 50 };
 51 
 52 bool Violation::operator==(const Violation& vltn){
 53     if(location==""||vltn.location=="")
 54         if(tel==""||vltn.tel=="")
 55             if(carNumber==""||vltn.carNumber=="")
 56                 if(date==""||vltn.date=="")
 57                     return number==vltn.number;
 58                 else return date==vltn.date;
 59             else return carNumber==vltn.carNumber;
 60         else return tel==vltn.tel;
 61     else return location==vltn.location;
 62 }
 63 
 64 bool compNumber(Violation& vltn1,Violation& vltn2){
 65     return vltn1.number>vltn2.number; 
 66 } 
 67 
 68 bool compDate(Violation& vltn1,Violation& vltn2){
 69     return vltn1.date>vltn2.date; 
 70 } 
 71 
 72 bool compCarNumber(Violation& vltn1,Violation& vltn2){
 73     return vltn1.carNumber<vltn2.carNumber; 
 74 } 
 75 
 76 bool compLocation(Violation& vltn1,Violation& vltn2){
 77     return vltn1.location>vltn2.location; 
 78 } 
 79 
 80 bool compPoints(Violation& vltn1,Violation& vltn2){
 81     return vltn1.points>vltn2.points; 
 82 }
 83 
 84 istream& operator>>(istream& input,Violation& vltn){
 85     input>>vltn.number>>vltn.date>>vltn.carNumber>>vltn.tel>>vltn.location
 86          >>vltn.points>>vltn.isSpot>>vltn.police>>vltn.camera>>vltn.type
 87          >>vltn.fine>>vltn.isTreated>>vltn.treatmentDate>>vltn.notes;
 88     return input;
 89 }
 90 
 91 ostream& operator<<(ostream& output,Violation& vltn){
 92     output<<setw(6)<<vltn.number
 93           <<setw(9)<<vltn.date
 94           <<setw(9)<<vltn.carNumber
 95           <<setw(12)<<vltn.tel
 96           <<setw(11)<<vltn.location
 97           <<setw(5)<<vltn.points
 98           <<setw(9)<<vltn.isSpot
 99           <<setw(13)<<vltn.police
100           <<setw(17)<<vltn.camera
101           <<setw(11)<<vltn.type 
102           <<setw(5)<<vltn.fine
103           <<setw(9)<<vltn.isTreated
104           <<setw(9)<<vltn.treatmentDate
105           <<setw(33)<<vltn.notes<<endl;
106     return output;
107 }
108 
109 class List{
110     public:
111         friend class User;
112         int loadFile();         //读取文件 
113         int saveFile();         //保存到文件 
114         int insert();           //添加记录
115         int change();           //修改记录
116         int del();              //删除记录
117         int browse();           //浏览记录 
118         
119          int searchMenu();       //查询信息 
120          int searchCarNumber();  //按车牌号
121         int searchDate();       //按日期查找
122         int searchTel();        //按电话查找 
123         int searchLocation();   //按地点查询 
124         
125         int countMenu();        //统计信息 
126         int countDate();        //按日期统计违章 
127         int countCarNumber();   //按车牌统计违章
128         int countLocation();    //按地点统计违章
129         int countPoints();      //按扣分统计违章 
130         static List* getList();
131     private:
132         list <Violation> vltnlist;
133         static List* m_list;
134         List(){};
135         List(const List&){}
136         List& operator=(const List&){}
137 };
138 
139 const char* filepath="violation.dat";    //指定数据文件路径 
140 
141 bool checkNumber(string s,int size){
142     if(s.size()!=size) return false;
143     for(int i=0;i<size;i++)
144         if(s[i]<'0'||s[i]>'9') return false;
145     return true;
146 } 
147 
148 List* List::m_list=NULL;
149 List* List::getList(){
150     if(NULL==m_list) m_list=new List;
151     return m_list;
152 }
153 
154 int List::loadFile(){
155     ifstream infile(filepath,ios::in);
156     if(infile)
157         for(;!infile.eof();){
158             Violation vltn;infile>>vltn;
159             vltnlist.push_back(vltn);
160         }
161     infile.close();
162     return 0;
163 }
164 
165 int List::saveFile(){
166     ofstream outfile(filepath,ios::out);
167     list<Violation>::iterator it;
168     for(it=vltnlist.begin();it!=vltnlist.end();it++)
169         outfile<<endl<<it->number<<' '<<it->date<<' '<<it->carNumber<<' '
170                <<it->tel<<' '<<it->location<<' '<<it->points<<' '<<it->isSpot<<' '
171                <<it->police<<' '<<it->camera<<' '<<it->type<<' '<<it->fine<<' '
172                <<it->isTreated<<' '<<it->treatmentDate<<' '<<it->notes;
173     outfile.close();
174     return 0;
175 }
176 
177 int List::insert(){
178     list<Violation>::iterator it;
179     string number,date,carNumber,tel,location,isSpot,police,camera,type,
180            isTreated,treatmentDate,notes;
181      int points,fine;
182     cout<<"请输入违章编号【放弃添加 0】【5位数字,如16384】:";
183     for(;;){
184         cin>>number;cin.sync();
185         if(number=="0") return 0;
186         if(!checkNumber(number,5)) {
187             cout<<"请输入有效编号:"; 
188             continue;
189         }
190         Violation l(number);
191         it=find(vltnlist.begin(),vltnlist.end(),l);
192         if(it!=vltnlist.end())
193             cout<<"编号已存在,请重新输入:";
194         else break;
195     }
196     cout<<"请输入违章日期【8位数字,如20160630】:";
197     while(1){
198         cin>>date;cin.sync();
199         if(!checkNumber(date,8)){
200             cout<<"请输入有效日期:";
201             continue;
202         }
203         else break;
204     } 
205     cout<<"请输入违章车辆车牌号:";cin>>carNumber;cin.sync();
206     cout<<"请输入登记联系电话【11位数字,如13751516464】:";
207     while(1){
208         cin>>tel;cin.sync();
209         if(!checkNumber(tel,11)){
210             cout<<"请输入有效电话:";
211             continue;
212         }
213         else break;
214     }
215     cout<<"请输入违章地点:";cin>>location;cin.sync();
216     cout<<"请输入处罚扣分【0~12分】:";
217     while(1){
218         if(cin>>points){
219             cin.sync();
220             if(points<0||points>12){
221                 cout<<"请输入有效扣分:";
222                 continue;
223             }
224             else break;
225         }
226         else{
227             cin.clear();cin.sync();
228             cout<<"请输入有效扣分:";
229             continue;
230         }
231     }
232     cout<<"请输入是否现场【是 1】:";cin>>isSpot;cin.sync();
233     if(isSpot=="1"){
234         cout<<"请输入现场执勤交警:";cin>>police;cin.sync(); 
235         isSpot="";camera="现场";
236     }
237     else{
238         cout<<"请输入非现场摄像头编号【6位数字,如646464】:";
239         while(1){
240             cin>>camera;cin.sync();
241             if(!checkNumber(camera,6)){
242                 cout<<"请输入有效编号:";
243                 continue;
244             }
245             else break;
246         }
247         isSpot="";police="非现场"; 
248     }
249     cout<<"*******************************************************"<<endl;
250     cout<<"* ┌------------违章类别-------------请输入---------┐*"<<endl;
251      cout<<"* |                                                 | *"<<endl;
252        cout<<"* |          ◆ 超速                    1           | *"<<endl;
253     cout<<"* |          ◆ 酒驾                    2           | *"<<endl;
254     cout<<"* |          ◆ 闯红灯                  3           | *"<<endl;
255     cout<<"* |          ◆ 违规变道                4           | *"<<endl;
256     cout<<"* |          ◆ 未系安全带              5           | *"<<endl;
257     cout<<"* |          ◆ 超载                    6           | *"<<endl;
258     cout<<"* |                                                 | *"<<endl;
259     cout<<"* └------------------------------------------------┘*"<<endl;
260     cout<<"*******************************************************"<<endl;
261     cout<<"请选择违章类别:";
262     int Mark=1;
263     while(Mark){
264         char n;cin>>n;cin.sync();
265         switch(n){
266             case '1': type="超速";Mark=0;break;
267             case '2': type="酒驾";Mark=0;break;
268             case '3': type="闯红灯";Mark=0;break;
269             case '4': type="违规变道";Mark=0;break; 
270             case '5': type="未系安全带";Mark=0;break;
271             case '6': type="超载";Mark=0;break;
272             default : cout<<"输入有误,请重新输入:";
273         }
274     }
275     cout<<"请输入罚款金额【0~5000元】:";
276     while(1){
277         if(cin>>fine){
278             cin.sync();
279             if(fine<0||fine>50000){
280                 cout<<"请输入有效金额:";
281                 continue;
282             }
283             else break;
284         }
285         else{
286             cin.clear();cin.sync();
287             cout<<"请输入有效金额:";
288             continue;
289         }
290     }
291     cout<<"请输入是否处理【是 1】:";cin>>isTreated;cin.sync();
292     if(isTreated=="1"){
293         cout<<"请输入处理日期【8位数字,如20160630】:";//cin>>treatmentDate;cin.sync();
294         while(1){
295             cin>>treatmentDate;cin.sync();
296             if(!checkNumber(treatmentDate,8)){
297                 cout<<"请输入有效日期:";
298                 continue;
299             }
300             else break;
301         } 
302         isTreated=""; 
303     }
304     else{
305         isTreated="";treatmentDate="未处理"; 
306     }
307     cout<<"请输入备注【无 0】:";cin>>notes;cin.sync();
308     if(notes=="0") notes="";
309     Violation vltn(number,date,carNumber,tel,location,points,isSpot,police,camera,
310               type,fine,isTreated,treatmentDate,notes);
311     vltnlist.push_back(vltn);
312     saveFile();
313     cout<<"车辆违章信息添加成功!";getchar();
314     return 0;
315 }
316 
317 int List::change(){
318     list<Violation>::iterator it;
319     if(!vltnlist.size()){
320         cout<<"还没有记录,不能修改!"<<endl;getchar();
321         return 0;
322     }
323     string number,date,carNumber,tel,location,isSpot,police,camera,type,
324            isTreated,treatmentDate,notes;
325      int points,fine;
326     browse();
327     cout<<"请输入想要修改的记录编号【放弃0】:";
328     cin>>number;cin.sync();
329     if(number=="0") return 0;
330     Violation vltn(number);
331     it=find(vltnlist.begin(),vltnlist.end(),vltn);
332     if(it==vltnlist.end()){
333         cout<<"此编号不存在!";getchar();
334         return 0;
335     }
336     while(1){
337         system("cls");
338         cout<<"         当前信息                   请输入"<<endl;
339         cout<<"         违章编号:"<<setw(17)<<(*it).number<<"   1"<<endl
340             <<"         违章日期:"<<setw(17)<<(*it).date<<"   2"<<endl
341             <<"       车辆车牌号:"<<setw(17)<<(*it).carNumber<<"   3"<<endl
342             <<"     登记联系电话:"<<setw(17)<<(*it).tel<<"   4"<<endl
343             <<"         违章地点:"<<setw(17)<<(*it).location<<"   5"<<endl
344             <<"         处罚扣分:"<<setw(17)<<(*it).points<<"   6"<<endl
345             <<"         是否现场:"<<setw(17)<<(*it).isSpot<<endl
346             <<"     现场执勤交警:"<<setw(17)<<(*it).police<<"   7"<<endl
347             <<" 非现场摄像头编号:"<<setw(17)<<(*it).camera<<"   8"<<endl
348             <<"         违章类别:"<<setw(17)<<(*it).type<<"   9"<<endl
349             <<"         罚款金额:"<<setw(17)<<(*it).fine<<"   a"<<endl
350             <<"         是否处理:"<<setw(17)<<(*it).isTreated<<"   b"<<endl
351             <<"         处理日期:"<<setw(17)<<(*it).treatmentDate<<"   c"<<endl
352             <<"             备注:"<<endl<<setw(34)<<(*it).notes<<"     d"<<endl;
353           cout<<"请选择要修改的条目【放弃修改 0】:";
354           int Mark=1;
355         while(Mark){     
356             char n;cin>>n;cin.sync();
357             switch(n){
358                 case '0': return 0; 
359                 case '1': cout<<"请输入违章编号【5位数字,如16384】:";//cin>>(*it).number;cin.sync();
360                           for(;;){
361                                 cin>>number;cin.sync();
362                                 if(!checkNumber(number,5)) {
363                                     cout<<"请输入有效编号:"; 
364                                     continue;
365                                 }
366                                 Violation l(number);
367                                 list<Violation>::iterator nit;
368                                 nit=find(vltnlist.begin(),vltnlist.end(),l);
369                                 if(nit!=vltnlist.end())
370                                     cout<<"编号已存在,请重新输入:";
371                                 else {
372                                     (*it).number=number;break;
373                                 }
374                             }
375                           Mark=0;break;
376                 case '2': cout<<"请输入违章日期【8位数字,如20160630】:";//cin>>(*it).date;cin.sync();
377                             while(1){
378                                 cin>>date;cin.sync();
379                                 if(!checkNumber(date,8)){
380                                     cout<<"请输入有效日期:";
381                                     continue;
382                                 }
383                                 else {
384                                     (*it).date=date;break;
385                                 }
386                             } 
387                                       Mark=0;break;
388                 case '3': cout<<"请输入车辆车牌号:";cin>>(*it).carNumber;cin.sync();
389                           Mark=0;break;
390                 case '4': cout<<"请输入登记联系电话:";//cin>>(*it).tel;cin.sync();
391                           while(1){
392                                 cin>>tel;cin.sync();
393                                 if(!checkNumber(tel,11)){
394                                     cout<<"请输入有效电话【11位数字,如13751516464】:";
395                                     continue;
396                                 }
397                                 else {
398                                     (*it).tel=tel;break;
399                                 }
400                             }
401                           Mark=0;break;
402                 case '5': cout<<"请输入违章地点:";cin>>(*it).location;cin.sync();
403                           Mark=0;break;
404                 case '6': cout<<"请输入处罚扣分【0~12分】:";//cin>>(*it).points;cin.sync();
405                             while(1){
406                                 if(cin>>points){
407                                     cin.sync();
408                                     if(points<0||points>12){
409                                         cout<<"请输入有效扣分:";
410                                         continue;
411                                     }
412                                     else{
413                                         (*it).points=points;break;
414                                     }
415                                 }
416                                 else{
417                                     cin.clear();cin.sync();
418                                     cout<<"请输入有效扣分:";
419                                     continue;
420                                 }
421                             }
422                           Mark=0;break;
423                 case '7': cout<<"请输入现场执勤交警:";cin>>(*it).police;cin.sync();
424                           (*it).isSpot="";(*it).camera="现场";
425                           Mark=0;break;
426                 case '8': cout<<"请输入非现场摄像头编号【6位数字,如646464】:";//cin>>(*it).camera;cin.sync();
427                             while(1){
428                                 cin>>camera;cin.sync();
429                                 if(!checkNumber(camera,6)){
430                                     cout<<"请输入有效编号:";
431                                     continue;
432                                 }
433                                 else{
434                                     (*it).camera=camera;break;
435                                 }
436                             }
437                           (*it).isSpot="";(*it).police="非现场"; 
438                           Mark=0;break;
439                 case '9': {
440                              cout<<"*******************************************************"<<endl;
441                           cout<<"* ┌------------违章类别-------------请输入---------┐*"<<endl;
442                            cout<<"* |                                                 | *"<<endl;
443                              cout<<"* |          ◆ 超速                    1           | *"<<endl;
444                           cout<<"* |          ◆ 酒驾                    2           | *"<<endl;
445                           cout<<"* |          ◆ 闯红灯                  3           | *"<<endl;
446                           cout<<"* |          ◆ 违规变道                4           | *"<<endl;
447                           cout<<"* |          ◆ 未系安全带              5           | *"<<endl;
448                           cout<<"* |          ◆ 超载                    6           | *"<<endl;
449                           cout<<"* |                                                 | *"<<endl;
450                           cout<<"* └------------------------------------------------┘*"<<endl;
451                           cout<<"*******************************************************"<<endl;
452                           cout<<"请选择违章类别:";
453                             int Mark1=1;
454                              while(Mark1){
455                               char n1;cin>>n1;cin.sync();
456                               switch(n1){
457                                     case '1': (*it).type="超速";Mark1=0;break;
458                                   case '2': (*it).type="酒驾";Mark1=0;break;
459                                   case '3': (*it).type="闯红灯";Mark1=0;break;
460                                   case '4': (*it).type="违规变道";Mark1=0;break; 
461                                   case '5': (*it).type="未系安全带";Mark1=0;break;
462                                   case '6': (*it).type="超载";Mark1=0;break;
463                                   default : cout<<"输入有误,请重新输入:";
464                               }
465                           }
466                           Mark=0;break;
467                           }
468                 case 'a': cout<<"请输入罚款金额【0~5000元】:";//cin>>(*it).fine;cin.sync();
469                             while(1){
470                                 if(cin>>fine){
471                                     cin.sync();
472                                     if(fine<0||fine>50000){
473                                         cout<<"请输入有效金额:";
474                                         continue;
475                                     }
476                                     else{
477                                         (*it).fine=fine;break;
478                                     }
479                                 }
480                                 else{
481                                     cin.clear();cin.sync();
482                                     cout<<"请输入有效金额:";
483                                     continue;
484                                 }
485                             }
486                           Mark=0;break;
487                 case 'b': cout<<"请输入是否处理【是 1】:";cin>>(*it).isTreated;cin.sync();
488                               if((*it).isTreated=="1"){
489                                 cout<<"输入处理日期:";//cin>>(*it).treatmentDate;cin.sync();
490                                 while(1){
491                                     cin>>treatmentDate;cin.sync();
492                                     if(!checkNumber(treatmentDate,8)){
493                                         cout<<"请输入有效日期:";
494                                         continue;
495                                     }
496                                     else {
497                                         (*it).treatmentDate=treatmentDate;break;
498                                     }
499                                 } 
500                                 (*it).isTreated=""; 
501                             }
502                             else{
503                                 (*it).isTreated="";(*it).treatmentDate="未处理"; 
504                             }
505                           Mark=0;break;
506                 case 'c': cout<<"请输入处理日期【8位数字,如20160630】:";//cin>>(*it).treatmentDate;cin.sync();
507                             while(1){
508                                 cin>>treatmentDate;cin.sync();
509                                 if(!checkNumber(treatmentDate,8)){
510                                     cout<<"请输入有效日期:";
511                                     continue;
512                                 }
513                                 else{
514                                     (*it).treatmentDate=treatmentDate;break;
515                                 }
516                             } 
517                           Mark=0;break;
518                 case 'd': cout<<"请输入备注:";cin>>(*it).notes;cin.sync();
519                           Mark=0;break;
520                 default : cout<<"输入有误,请重新输入:";
521             }
522         }
523         saveFile();
524           cout<<"修改成功!"<<endl
525             <<"继续修改请输入任意键,修改完毕请输入0:";
526         char ch;cin>>ch;cin.sync();
527          if(ch=='0') return 0;
528     }
529 }
530 
531 int List::del(){
532     list<Violation>::iterator it;
533     if(!vltnlist.size()){
534         cout<<"还没有记录,不能删除!"<<endl;getchar();
535         return 0;
536     }
537     string number;
538     browse();
539     cout<<"请输入想要删除的编号【放弃0】:";
540     cin>>number;cin.sync();
541     if(number=="0") return 0;
542     Violation vltn(number);
543     it=find(vltnlist.begin(),vltnlist.end(),vltn);
544     if(it==vltnlist.end()){
545         cout<<"此编号不存在!";getchar();
546         return 0;
547     }
548     vltnlist.erase(it);
549     if(!vltnlist.size()) remove(filepath);
550     else saveFile();
551     cout<<"删除记录成功!";getchar();
552     return 0;
553 }
554 
555 int List::browse(){
556     list<Violation>::iterator it;
557     if(!vltnlist.size()){
558         cout<<"还没有记录!"<<endl;getchar();
559         return 0;
560     }
561     vltnlist.sort(compNumber);                  //按编号降序排列 
562     cout<<"当前共有 "<<vltnlist.size()<<"条记录,已按编号降序排列:"<<endl
563          <<"  编号     日期   车牌号    联系电话       地点 扣分 是否现场 现场执勤交警 非现场摄像头编号   违章类别 罚款 是否处理 处理日期                             备注"<<endl; 
564     for(it=vltnlist.begin();it!=vltnlist.end();it++)
565         cout<<*it;
566     getchar();
567     return 0;
568 }
569 
570 int List::searchMenu(){
571     if(!vltnlist.size()){
572         cout<<"还没有记录,不能查询!"<<endl;getchar();
573         return 0;
574     }
575     while(1)
576     {
577         system("cls");
578         cout<<"*******************************************************"<<endl;
579         cout<<"*             ★机动车违章处罚管理系统 ★             *"<<endl;
580         cout<<"*                                                     *"<<endl;
581         cout<<"*******************************************************"<<endl;
582         cout<<"* ┌-------------------查询菜单---------------------┐*"<<endl;
583         cout<<"* |                                                 | *"<<endl;
584         cout<<"* |              查询方式             请输入        | *"<<endl;
585         cout<<"* |          ◆ 按日期查询              1           | *"<<endl;
586         cout<<"* |          ◆ 按车牌号查询            2           | *"<<endl;
587         cout<<"* |          ◆ 按电话查询              3           | *"<<endl;
588         cout<<"* |          ◆ 按地点查询              4           | *"<<endl;
589         cout<<"* |                                                 | *"<<endl;
590         cout<<"* └------------------------------------------------┘*"<<endl;
591         cout<<"*******************************************************"<<endl;
592         cout<<"*            ● 返回主菜单              0             *"<<endl;
593         cout<<"*******************************************************"<<endl;
594         cout<<"请选择查询方式:";
595         int Mark=1;
596         while(Mark){
597             char n;cin>>n;cin.sync();
598             switch(n)
599             {
600                 case '1': searchDate();Mark=0;break;
601                 case '2': searchCarNumber();Mark=0;break;
602                 case '3': searchTel();Mark=0;break;
603                 case '4': searchLocation();Mark=0;break;
604                 case '0': return 0;
605                 default : cout<<"输入有误,请重新输入:";
606             }
607         }
608     }
609     vltnlist.sort(compNumber);
610     return 0;
611     getchar();return 0;
612 }
613 
614 int List::searchDate(){
615     list<Violation>::iterator it;
616     string date;
617     cout<<"请输入日期:";cin>>date;cin.sync();
618     Violation vltn("",date);
619     it=find(vltnlist.begin(),vltnlist.end(),vltn);
620     if(it!=vltnlist.end()){ 
621         cout<<"已找到日期为 "<<date<<" 的违章记录:"<<endl
622         <<"  编号     日期   车牌号    联系电话       地点 扣分 是否现场 现场执勤交警 非现场摄像头编号   违章类别 罚款 是否处理 处理日期             备注"<<endl
623         <<*it;
624         for(it++;it!=vltnlist.end();it++)
625             if(*it==vltn) cout<<*it;
626     }
627     else cout<<"没有该日期的违章记录!";
628     getchar();return 0;
629 }
630 
631 int List::searchCarNumber(){
632     list<Violation>::iterator it;
633     string carNumber;
634     cout<<"请输入车牌号:";cin>>carNumber;cin.sync();
635     Violation vltn("","",carNumber);
636     it=find(vltnlist.begin(),vltnlist.end(),vltn);
637     if(it!=vltnlist.end()){ 
638         cout<<"已找到车牌号为 "<<carNumber<<" 的违章记录:"<<endl
639         <<"  编号     日期   车牌号    联系电话       地点 扣分 是否现场 现场执勤交警 非现场摄像头编号   违章类别 罚款 是否处理 处理日期             备注"<<endl
640         <<*it;
641         for(it++;it!=vltnlist.end();it++)
642             if(*it==vltn) cout<<*it;
643     }
644     else cout<<"没有该车牌号的违章记录!";
645     getchar();return 0;
646 }
647     
648 int List::searchTel(){
649     list<Violation>::iterator it;
650     string tel;
651     cout<<"请输入联系电话:";cin>>tel;cin.sync();
652     Violation vltn("","","",tel);
653     it=find(vltnlist.begin(),vltnlist.end(),vltn);
654     if(it!=vltnlist.end()){ 
655         cout<<"已找到联系电话为 "<<tel<<" 的违章记录:"<<endl
656         <<"  编号     日期   车牌号    联系电话       地点 扣分 是否现场 现场执勤交警 非现场摄像头编号   违章类别 罚款 是否处理 处理日期             备注"<<endl
657         <<*it;
658         for(it++;it!=vltnlist.end();it++)
659             if(*it==vltn) cout<<*it;
660     }
661     else cout<<"没有该联系电话的违章记录!";
662     getchar();return 0;
663 }
664     
665 int List::searchLocation(){
666     list<Violation>::iterator it;
667     string location;
668     cout<<"请输入地点:";cin>>location;cin.sync();
669     Violation vltn("","","","",location);
670     it=find(vltnlist.begin(),vltnlist.end(),vltn);
671     if(it!=vltnlist.end()){ 
672         cout<<"已找到地点为 "<<location<<" 的违章记录:"<<endl
673         <<"  编号     日期   车牌号    联系电话       地点 扣分 是否现场 现场执勤交警 非现场摄像头编号   违章类别 罚款 是否处理 处理日期             备注"<<endl
674         <<*it;
675         for(it++;it!=vltnlist.end();it++)
676             if(*it==vltn) cout<<*it;
677     }
678     else cout<<"没有该地点的违章记录!";
679     getchar();return 0;
680 }
681     
682 int List::countMenu(){
683     list<Violation>::iterator it;
684     if(!vltnlist.size()){
685         cout<<"还没有记录,不能统计!"<<endl;getchar();
686         return 0;
687     }
688     while(1)
689     {
690         system("cls");
691         cout<<"*******************************************************"<<endl;
692         cout<<"*                                                     *"<<endl;
693         cout<<"*              ★机动车违章处罚管理系统 ★            *"<<endl;
694         cout<<"*                                                     *"<<endl;
695         cout<<"*******************************************************"<<endl;
696         cout<<"* ┌--------------------统计菜单--------------------┐*"<<endl;
697         cout<<"* |                                                 | *"<<endl;
698         cout<<"* |            统计方式               请输入        | *"<<endl;
699         cout<<"* |        ◆ 按日期统计违章数量        1           | *"<<endl;
700         cout<<"* |        ◆ 按车牌号统计违章次数      2           | *"<<endl;
701         cout<<"* |        ◆ 按地点统计违章数量        3           | *"<<endl;
702         cout<<"* |        ◆ 显示处罚>=12分的记录      4           | *"<<endl;
703         cout<<"* |                                                 | *"<<endl;
704         cout<<"* └------------------------------------------------┘*"<<endl;
705         cout<<"*******************************************************"<<endl;
706         cout<<"*            ● 返回主菜单              0             *"<<endl;
707         cout<<"*******************************************************"<<endl;
708         cout<<"请选择统计方式:";
709         int Mark=1;
710         while(Mark){
711             char n;cin>>n;cin.sync();
712             switch(n)
713             {
714                 case '1': countDate();Mark=0;break;
715                 case '2': countCarNumber();Mark=0;break;
716                 case '3': countLocation();Mark=0;break;
717                 case '4': countPoints();Mark=0;break;
718                 case '0': return 0;
719                 default : cout<<"输入有误,请重新输入:";
720             }
721         }
722     }
723     return 0;
724     getchar();return 0;
725 }
726 
727 int List::countDate(){
728     list<Violation>::iterator it;
729     vltnlist.sort(compDate);
730     int sumVltn=0;string y,m1,m2,date1,date2;
731     cout<<"输入日期范围:"<<endl ;
732     cout<<"输入年份:";cin>>y;cin.sync();
733     cout<<"输入起始月份:";cin>>m1;cin.sync();
734     cout<<"输入结束月份:";cin>>m2;cin.sync();
735     date1=y+m1;date2=y+m2;
736     for(it=vltnlist.begin();it!=vltnlist.end();it++){
737         if((*it).date>=date1&&(*it).date<=date2) sumVltn++;
738     }
739     cout<<"该段时间内违章数量为:"<<sumVltn;//getchar();
740     //vltnlist.push_back(Violation("cutme"));
741     //it=vltnlist.begin();
742     /*
743 cout<<"已按月份统计违章数量:"<<endl
744         <<"  违章日期 违章数量"<<endl;
745     int sumVltn=0;string mouth=((*it).date).substr(4,2),date=(*it).date.substr(0,4);
746     for(it=vltnlist.begin();it!=vltnlist.end();it++)
747         if((*it).date!=""){
748             if(mouth!=((*it).date).substr(4,2)){
749                 cout<<(*it).date.substr(0,4)<<"年"<<mouth<<"月"<<setw(9)<<sumVltn<<endl;
750                  sumVltn=1;mouth=(*it).date.substr(4,2);date=(*it).date.substr(0,4);
751             }
752             else {
753                 sumVltn++;
754             }
755         }
756         else{
757             cout<<date<<"年"<<mouth<<"月"<<setw(9)<<sumVltn<<endl;
758         }*/
759     //vltnlist.pop_back();
760     getchar();return 0;
761 }
762 
763 int List::countCarNumber(){
764     list<Violation>::iterator it;
765     vltnlist.sort(compCarNumber);
766     vltnlist.push_back(Violation("cutme"));
767     it=vltnlist.begin();
768     cout<<"已按车牌号统计违章次数:"<<endl
769         <<"   车牌号 违章次数"<<endl;
770     string carNumber=(*it).carNumber;int sumVltn=0;
771     for(it=vltnlist.begin();it!=vltnlist.end();it++)
772         if(carNumber!=(*it).carNumber){
773             cout<<setw(9)<<carNumber<<setw(9)<<sumVltn<<endl;
774          carNumber=(*it).carNumber;sumVltn=1;
775         }
776         else sumVltn++;
777     vltnlist.pop_back();
778     getchar();return 0;
779 }
780 
781 int List::countLocation(){
782     list<Violation>::iterator it;
783     vltnlist.sort(compLocation);
784     vltnlist.push_back(Violation("cutme"));
785     it=vltnlist.begin();
786     string location=(*it).location;int sumVltn=0;
787     cout<<"已按地点统计违章数量:"<<endl
788         <<"       地点 违章数量"<<endl;
789     for(it=vltnlist.begin();it!=vltnlist.end();it++)
790         if(location    !=(*it).location){
791             cout<<setw(11)<<location<<setw(9)<<sumVltn<<endl;
792          location=(*it).location;sumVltn=1;
793         }
794         else sumVltn++;
795     vltnlist.pop_back();
796     getchar();return 0;
797 }
798 
799 int List::countPoints(){
800     list<Violation>::iterator it;
801     vltnlist.sort(compCarNumber);
802     vltnlist.push_back(Violation("cutme"));
803     it=vltnlist.begin();
804     string carNumber=(*it).carNumber,tel=(*it).tel;
805     int sumPoints=0;
806     cout<<"已显示处罚>=12分的违章记录:"<<endl
807         <<"   车牌号    联系电话"<<endl;
808     for(it=vltnlist.begin();it!=vltnlist.end();it++)
809         if(carNumber!=(*it).carNumber){
810             if(sumPoints>11)
811                 cout<<setw(9)<<carNumber<<setw(12)<<tel<<endl;
812              carNumber=(*it).carNumber;sumPoints=(*it).points;tel=(*it).tel;
813         }
814         else sumPoints+=(*it).points;
815     vltnlist.pop_back();
816     getchar();return 0;
817 }
818 
819 int menu();
820 
821 int main(){
822     List* myList=List::getList();
823     myList->loadFile();
824     menu();
825     myList->saveFile();
826     return 0;
827 }
828 
829 int menu(){
830     while(1)
831     {
832         system("cls");
833         cout<<"*******************************************************"<<endl;
834         cout<<"*                                                     *"<<endl;
835         cout<<"*             ★机动车违章处罚管理系统 ★             *"<<endl;
836         cout<<"*                                                     *"<<endl;
837         cout<<"*******************************************************"<<endl;
838         cout<<"* ┌---------------------主菜单---------------------┐*"<<endl;
839         cout<<"* |                                                 | *"<<endl;
840         cout<<"* |                 功能              请输入        | *"<<endl;
841         cout<<"* |          ◆ 添加违章记录            1           | *"<<endl;
842         cout<<"* |          ◆ 修改违章记录            2           | *"<<endl;
843         cout<<"* |          ◆ 删除违章记录            3           | *"<<endl;
844         cout<<"* |          ◆ 浏览违章记录            4           | *"<<endl;
845         cout<<"* |          ◆ 查询违章记录            5           | *"<<endl;
846         cout<<"* |          ◆ 统计违章记录            6           | *"<<endl;
847         cout<<"* |                                                 | *"<<endl;
848         cout<<"* └------------------------------------------------┘*"<<endl;
849         cout<<"*******************************************************"<<endl;
850         cout<<"*            ● 退出管理系统            0             *"<<endl;
851         cout<<"*******************************************************"<<endl;
852         cout<<"请选择功能:";
853         int Mark=1;
854         while(Mark){
855             char n;cin>>n;cin.sync();
856                 List* myList=List::getList();
857             switch(n)
858             {
859                 case '1': myList->insert();Mark=0;break;
860                 case '2': myList->change();Mark=0;break;
861                 case '3': myList->del();Mark=0;break;
862                 case '4': myList->browse();Mark=0;break; 
863                 case '5': myList->searchMenu();Mark=0;break;
864                 case '6': myList->countMenu();Mark=0;break;
865                 case '0': exit(0);
866                 default : cout<<"输入有误,请重新输入:";
867             }
868         }
869     }
870     return 0;
871 }

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Win32消息循环机制等【转载】http://blog.csdn.net/u013777351/a

下一篇:POJ 1572 Automatic Editing 字符串替换,replace就够了