
#include #include #include #include using namespace std; template public: Che(); void ShuRuChePai(string);//输入车牌 void JinRu(string);//输入车进入停车场的时间 void LiKai(string);//输入车离开停车场的时间 bool Compare(string); void ShuChuM(double); private: string s;//车牌号记录 double st;//车到停车场的时间 double et;//车离开停车场的时间 };//车的类 template st=0; et=0; } template s=a; } template int aa,bb,cc=1; int xx=0; int i; double d; for(i=0;i<8;i++){ if(y[i]!=':')xx=y[i]-'0'+10*xx; else{ if(cc==1)aa=xx; if(cc==2)bb=xx; cc++;xx=0; } } d=60.0*(60*aa+bb)+xx; st=d; } template int aa,bb,cc=1; int xx=0; int i; double d; for(i=0;i<8;i++){ if(y[i]!=':')xx=y[i]-'0'+10*xx; else{ if(cc==1)aa=xx; if(cc==2)bb=xx; cc++;xx=0; } } d=60.0*(60*aa+bb)+xx; et=d; } template if(s.compare(a)==0)return true; else return false; } template cout.precision(2); cout<<"停车应支付的费用为:"< int main(){ int c,i,j,m,n[101],w[101],k,bb;//n[101]为当前车数,w[101]记录停车场当前的车数,m为停车场的个数,bb记录车子在哪个停车场,k记录后备队列里的车数; double money;//money为每秒钟的钱 string x;//x为车牌号 string str; string y;//输入的时间 bool abc,xyz; stack< Che stack< Che queue< Che cout<<"\\\\停车场管理系统"< Che memset(n,0,sizeof(n)); k=0; m=-1; while(1){ c=0; bb=0; abc=false; xyz=false; do{ cout<<" ************************************************************************** "; cout<<"\0:停车场初始化\\1:进入停车场\\2:离开停车场"< cout<<"输入数字(没有前导0,例如01为非法输入;除上面数字的其他数字都为非法输入)"< if(str.size()>1||!(str[0]=='1'||str[0]=='2'||str[0]=='3'||str[0]=='0'||str[0]=='9')) {cout<<"输入数字错误,请重新输入"< if(c==0){ cout<<"输入拥有的停车场个数"< cout<<"输入每秒的停 车费用"< for(i=1;i<=m;i++){ cout<<"输入第"<cin>>w[i]; } continue; } if(c==3)goto C; if(c==9)exit(0); } while(!(c==1||c==2)); if(m==-1)goto C; cout<<"输入车牌号"< getline(cin,x); car.ShuRuChePai(x); if(c==1){ for(i=1;i<=m;i++){ if(n[i] for(j=0;j cout<<"输入错误"< } car.JinRu(y); TCC[i].push(car); n[i]++; break; } else { if(i!=m)cout<<"第"<else { cout<<"第"<cout<<"所有停车场已满,进入后备队列"< k++; } } } } if(c==2){ bool aa=false; for(i=1;i<=m;i++) if(n[i]>0){ aa=true; break; } if(aa){ i=1; do{ if(TCC[i].empty()){ while(!TCC2.empty()){ TCC[i].push(TCC2.top()); TCC2.pop(); } i++; if(i==m)break; else continue; } lscar=TCC[i].top(); TCC2.push(lscar); TCC[i].pop(); abc=lscar.Compare(x); if(abc==true)bb=i; }while(!abc); if(lscar.Compare(x)==false){ do{ if(TCC[i].empty()){ cout<<"停车场没有该车"< TCC[i].push(TCC2.top()); TCC2.pop(); } goto C; } lscar=TCC[i].top(); TCC2.push(lscar); TCC[i].pop(); xyz=lscar.Compare(x); }while(!xyz); } TCC2.pop(); if(abc==true)n[bb]--; if(xyz==true) n[m]--; cout<<"输入离开的时间(以XX:XX:XX形式输入)"< for(j=0;j cout<<"输入错误"< } lscar.LiKai(y); lscar.ShuChuM(money); while(!TCC2.empty()){ if(abc==true)TCC[bb].push(TCC2.top()); else TCC[m].push(TCC2.top()); TCC2.pop(); } if(!HouBei.empty()){ lscar=HouBei.front(); lscar.JinRu(y); for(i=1;i<=m;i++){ if(n[i] n[i]++; HouBei.pop(); k--; break; } } } } else{ cout<<"停车场是空的,没有车"< } } C:if(m!=-1){ for(i=1;i<=m;i++) cout<<"第"<cout<<"后备队列上有"< return 0; }
