关键代码如下所示:
#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++语言实现机动车违章处罚管理系统的关键代码,代码附有注释,有不明白的地方欢迎给我留言,小编会及时回复大家的,大家可以更加需求适当的添加修改删除。
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索c++
机动车违章处罚标准、机动车违章处罚条例、机动车违章停放处罚、机动车违章处罚对照表、机动车违章处罚决定书,以便于您获取更多的相关知识。
时间: 2024-09-26 09:40:55