《停车场管理系统.docx》由会员分享,可在线阅读,更多相关《停车场管理系统.docx(9页珍藏版)》请在第壹文秘上搜索。
1、问遨描述,设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可以供汽车进出C汽车在停车场内依据车辆到达的先后依次,依次由北向南排列,大门在最南段.若停车场内车位已羟铮满,则后来的车位只能停在过道上等候。一旦停车场内有车离开,停靠在过道上的车辆就能开迸停年场停放。依据的辆车在停下场的停城时间计费,请设计一个停车场管理系统.试验代码如下:#inc1.udeiostrceinc1.udeinc1.udeinc1.ude#inc1.udeSinc1.udeMinc1.udeusingnamespacestd:?defineXN1.M5HdefinePRICE2.0structcarcharnu
2、m10;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;voidStackpushC
3、Seqstack*s,carcar1.)if(!Isfu1.Ks)(s-top+:s-car1.ists-top=car1.;e1.se(coutit,sfu1.1.noucar1.ists-1.op;s-top-;returncar1.:carStackgettop(Seqstack*s)carcar1.;if(!Isenpty(三)(car1.=s-car1.ist(s-top;returncar1.:/thequeueofcarinttunne1./structcarnodecardata;structcarnode*next;;structcarnodequeue(carncxiehe
4、ad=(carrode*)ma1.Ioc(si2e0f(carnode)(cout*fai1.edtoma1.1.oc*end1.:exitrear=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)carnodep:if(!(p=(carno1.c*)ma1Ioc(sizef(carnode)(cout,fai1.edtom
5、a1.1.oc!*datacc;p-next=NU1.1.;q-rear-next=;q-rear=p;carcarnodehead!=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=0inziOcoutch;if(new1.ine=1)coutend1.;
6、/printtheIiBestruct/voidPrinIdaIa(SIrUC1.tinwndata)coutgm_data.tm_mon*gm_data.tmjnday*gm_data.tJour+8g111.data.gm_data.t*_secend1.:I1.1.1.1.Showpark/voidshoupark(Seqstack*s)structtngm;coutarator(40,-,1):if(Isempty(三)cout*theparkisempty!*e11d1.;e1.se(cout*positionnuriberin1.ime*end1.:for(inti=0:itop;
7、i0(coutcar1isti.position*car1.istij.numcar1.isti.intime);CoUtthetota1.is*top+1.*cars,*top=MAXNUM-1)CoUIandtheparkisfu1.1.now!*end1.:e1.secout*andtheparkhave*top*positionise三pty!*head-next:cout*theai1.seinfurnationisfo1.1.ow:*end1.;separator(30.1):cout*numbertheintime*end1.;uhiIe(p!=NU1.1.)(coutdata.
8、numdata.intime);p=-next:)e1.se(cout*thcai1.seise三pty!4rcnd1.:)separator(30.-,1);coutend1.;/showparkandni1.se/voidShowa1.KSeqstack*s,carnodeqeueak)showprk(三);showais1.e(q);/inpark/voidInpark(Seqstack*s,carnodequeue*q)carcc;structtsg_da1.fi;timeseconds;time(4seconds);/getthe1.imegm_data-gmtiBe(seconds
9、):cout*thenumberofcar*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);/theoutpar
10、k/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.os;if(pos0&postop1)(for(i=s-top+1.;ipos;i)(cc-St
11、ackpop(三);cc.position=cc.position-1;Stackpush(,cc);)cc-Stackpop(三);tiBeseconds);gm.data=gmtime(fesecoris):cc.outi11e=g11-data;cc.1.ength-mktime(Acc.outime)mktime(Acc.intime);cc.expense=(cc.1.ength/36001)*I,RICE;cout*thcinfo1111tionwhichcaristo1.eaveisfo1.1.ow,*end1.;coutcc.num*cc.1.ength*cc.expenseend1.;三hi1.e(!Isempty(Ap)cc-Stackpop(4p);Stackpush(stcc);)whi1.c(!Isctnp1.y(三)&!crnodcqueucisvmty(q)(cc=Carnodequeueout