停车场管理系统.docx
问遨描述,设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可以供汽车进出C汽车在停车场内依据车辆到达的先后依次,依次由北向南排列,大门在最南段.若停车场内车位已羟铮满,则后来的车位只能停在过道上等候。一旦停车场内有车离开,停靠在过道上的车辆就能开迸停年场停放。依据的辆车在停下场的停城时间计费,请设计一个停车场管理系统.试验代码如下:#inc1.ude<iostrc<m>einc1.ude<vector>inc1.ude<set>inc1.ude<map>#inc1.ude<strirg>Sinc1.ude<math.h>Minc1.ude<tiae.h>usingnamespacestd:?defineXN1.M5HdefinePRICE2.0structcarcharnum10;structtaintise;structtaoutie;doub1.eexpense;int1.ength;intposition;/thestackofcar/IyPCdefstructcarcar1.istMAXNUM;inttop;Seqstack;voidStackinitCSeqstacks)(s->top=-1.;intIsempty(SeqstackS)if(s->top=-1.)return1;e1.sereturnO;intIsfu1.1.(Seqstack*s)if(s->top=MAXNUM-1.)return1;e1.sereturn0;voidStackpushCSeqstack*s,carcar1.)if(!Isfu1.Ks)(s->top+:s->car1.ists->top=car1.;e1.se(cout<<it,sfu1.1.nou"<<end1.:carStackpopSeqstack*s)carcar1.:if(!ISeBPty(三)(car1.=s->car1.ists->1.op;s->top-;returncar1.:carStackgettop(Seqstack*s)carcar1.;if(!Isenpty(三)(car1.=s->car1.ist(s->top;returncar1.:/thequeueofcarinttunne1./structcarnodecardata;structcarnode*next;;structcarnodequeue(carncxie<head:carnoderear;Hvoidcarnodequeueinit(carnodequeue*q)(if(!(q->head=(carrode*)ma1.Ioc(si2e0f(carnode)(cout<<*fai1.edtoma1.1.oc*<<end1.:exit<O);)q->rear=q->head:q->head->next=NU.1.;q->rear->nexI=NU1.1.:intCarnOdeqUeUeiSemPty(CarnOdeqUeUe*q)(if(q->rear=q->head)return1;e1.sereturnO:voidcarnodequeuei11(carnodequeueq,carcc)carnode«p:if(!(p=(carno<1.c*)ma1Ioc(sizef(carnode)(cout<<,fai1.edtoma1.1.oc!*<<end1.:exit(O):p->datacc;p->next=NU1.1.;q->rear->next=;q->rear=p;carcarnode<jueueout(carnodeqee*q)carnodep:carcc:if(q->head!=q->rear)(p=q->head->11ext:if(p->next=NUI.1.)(cc=p->data:q->rear=q->head;free(p):)e1.se(q->rear->next=p->next:cc=p->data:frce(p):)returncc:/theseparatorofCoUt/voidSeparatorfintn,charch,charnew1.ine)for(inti=0i<nzi÷Ocout<<ch;if(new1.ine=1)cout<<end1.;/printtheIiBestruct/voidPrinIdaIa(SIrUC1.tinwndata)cout<<gm_data.tm_mon«*«gm_data.tmjnday<<*"«gm_data.tJour+8<<>"<×g111.data."«gm_data.t*_sec<<end1.:I1.1.1.1.Showpark/voidshoupark(Seqstack*s)structtngm;cout<<*theparkinformationisfo1.1.ow:*«end1.;sc>arator(40,'-,1):if(Isempty(三)cout<<*theparkisempty!*<<e11d1.;e1.se(cout<<*positionnuriberin1.ime*<<end1.:for(inti=0:i<=s->top;i<0(cout<<s->car1isti.position<<*<<s->car1.istij.num<<*rin1.dau(s->car1.isti.intime);CoUt<<"thetota1.is*<<s->top+1.<<*cars,*<<end1.;if(s->top=MAXNUM-1)CoUI<<"andtheparkisfu1.1.now!*<<end1.:e1.secout<<*andtheparkhave*<<MAXNUM-1-s->top<<*positionise三pty!*<<end1.;Jseparator(40,.1);/Shgais1.eofcar/voidshowais1.e(carnodequeue*q)if(!Carnodequeueiscff1.pty(q)(carnode*p:p=q->head->next:cout<<*theai1.seinfurnationisfo1.1.ow:*<<end1.;separator(30.''.1):cout<<*numbertheintime*<<end1.;uhiIe(p!=NU1.1.)(cout<<p->data.num<<*"printdata(p->data.intime);p=->next:)e1.se(cout<<*thcai1.seise三pty!4r<<cnd1.:)separator(30.'-,1);cout<<end1.;/showparkandni1.se/voidShowa1.KSeqstack*s,carnodeqeueak)showp<rk(三);showais1.e(q);/inpark/voidInpark(Seqstack*s,carnodequeue*q)carcc;structtsg«_da1.fi;timeseconds;time(4seconds);/getthe1.imegm_data-gmtiBe(seconds):cout<<*thenumberofcar*<<end1.:cin>>cc.nu三;cc.intime=g三-da1.a;if(!Isfu1.I(三)kCamodequeueisempty(q)(cc.position=(s->to)+2:Stackpush(s,cc):showpark(三);Ie1.seif(Isfu1.1.(三)!carnodequeueiscmpty(q)(cout<<*theparkiffu1.1.,thecarcanon1.yparkinttheai1.se.*<<end1.;cc.position=MXN1.M;Carnodequeuein(q.cc);shown11(s.q);/theoutpark/voidOutpark(Seqstack*s,carnodequeueak)structtng三data;time,seconds;Seqstackp;charnowti三c10;inti.pos;carcc;S1.ackini1.(&p);if(Isempty(三)cout<<*thcparkiscniipty,nocarneedto1.eave.*<<end1.;exit(0);e1.secout<<*theparkinfonationisfo1.1.o<.*<<end1.;showpark(三);CoU1.<<"whichoneneedto1.eave?*«end1.;cin>>os;if(pos>0&&pos<三s->top1)(for(i=s->top+1.;i>pos;i)(cc-Stackpop(三);cc.position=cc.position-1;Stackpush(,cc);)cc-Stackpop(三);tiBeseconds);gm.data=gmtime(fesecoris):cc.outi11>e=g11-data;cc.1.ength-mktime(Acc.outime)mktime(Acc.intime);cc.expense=(cc.1.ength/3600÷1)*I,RICE;cout<<*thcinfo1111<tionwhichcaristo1.eaveisfo1.1.ow,*<<end1.;cout<<cc.num<<*<<cc.1.ength<<*<<cc.expense<<end1.;三hi1.e(!Isempty(Ap)cc-Stackpop(4p);Stackpush(stcc);)whi1.c(!Isctnp1.y(三)&&!crnodcqueucisvmty(q)(cc=Carnodequeueout