停车场管理系统.docx

上传人:wj 文档编号:7395732 上传时间:2023-05-11 格式:DOCX 页数:11 大小:200.87KB
下载 相关 举报
停车场管理系统.docx_第1页
第1页 / 共11页
停车场管理系统.docx_第2页
第2页 / 共11页
停车场管理系统.docx_第3页
第3页 / 共11页
停车场管理系统.docx_第4页
第4页 / 共11页
停车场管理系统.docx_第5页
第5页 / 共11页
停车场管理系统.docx_第6页
第6页 / 共11页
停车场管理系统.docx_第7页
第7页 / 共11页
停车场管理系统.docx_第8页
第8页 / 共11页
停车场管理系统.docx_第9页
第9页 / 共11页
停车场管理系统.docx_第10页
第10页 / 共11页
停车场管理系统.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

停车场管理系统.docx

《停车场管理系统.docx》由会员分享,可在线阅读,更多相关《停车场管理系统.docx(11页珍藏版)》请在冰点文库上搜索。

停车场管理系统.docx

问题描述:

设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可以供汽车进出。

汽车在停车场内按照车辆到达的先后顺序,依次由北向南排列,大门在最南段。

若停车场内车位已经停满,则后来的车位只能停在过道上等候。

一旦停车场内有车离开,停靠在过道上的车辆就能开进停车场停放。

根据每辆车在停车场的停靠时间计费。

请设计一个停车场管理系统。

实验代码如下:

#include

#include

#include

#include

#include

#include

#include

usingnamespacestd;

#defineMAXNUM5

#definePRICE2.0

structcar

{

charnum[10];

structtmintime;

structtmoutime;

doubleexpense;

intlength;

intposition;

};

//////////thestackofcar//////////////////////////////

typedefstruct

{

carcarlist[MAXNUM];

inttop;

}Seqstack;

voidStackinit(Seqstack*s)

{

s->top=-1;

}

intIsempty(Seqstack*s)

{

if(s->top==-1)

return1;

else

return0;

}

intIsfull(Seqstack*s)

{

if(s->top==MAXNUM-1)

return1;

else

return0;

}

voidStackpush(Seqstack*s,carcar1)

{

if(!

Isfull(s))

{

s->top++;

s->carlist[s->top]=car1;

}

else

{

cout<<"it'sfullnow"<

}

}

carStackpop(Seqstack*s)

{

carcar1;

if(!

Isempty(s))

{

car1=s->carlist[s->top];

s->top--;

returncar1;

}

}

carStackgettop(Seqstack*s)

{

carcar1;

if(!

Isempty(s))

{

car1=s->carlist[s->top];

returncar1;

}

}

//////////thequeueofcarinttunnel//////////////////////////////

structcarnode

{

cardata;

structcarnode*next;

};

structcarnodequeue

{

carnode*head;

carnode*rear;

};

voidcarnodequeueinit(carnodequeue*q)

{

if(!

(q->head=(carnode*)malloc(sizeof(carnode))))

{

cout<<"failedtomalloc!

"<

exit(0);

}

q->rear=q->head;

q->head->next=NULL;

q->rear->next=NULL;

}

intcarnodequeueisempty(carnodequeue*q)

{

if(q->rear==q->head)

return1;

else

return0;

}

voidcarnodequeuein(carnodequeue*q,carcc)

{

carnode*p;

if(!

(p=(carnode*)malloc(sizeof(carnode))))

{

cout<<"failedtomalloc!

"<

exit(0);

}

p->data=cc;

p->next=NULL;

q->rear->next=p;

q->rear=p;

}

carcarnodequeueout(carnodequeue*q)

{

carnode*p;

carcc;

if(q->head!

=q->rear)

{

p=q->head->next;

if(p->next==NULL)

{

cc=p->data;

q->rear=q->head;

free(p);

}

else

{

q->rear->next=p->next;

cc=p->data;

free(p);

}

returncc;

}

}

//////theseparatorofcout//////////////////////////

voidseparator(intn,charch,charnewline)

{

for(inti=0;i

cout<

if(newline==1)

cout<

}

/////printthetimestruct//////////////////////////////

voidprintdata(structtmgm_data)

{

cout<

"<

"<

}

/////showpark////////////////////////////////////////

voidshowpark(Seqstack*s)

{

structtmgm;

cout<<"theparkinformationisfollow:

"<

separator(40,'-',1);

if(Isempty(s))

cout<<"theparkisempty!

"<

else

{

cout<<"positionnumberintime"<

for(inti=0;i<=s->top;i++)

{

cout<carlist[i].position<<""<carlist[i].num<<"";

printdata(s->carlist[i].intime);

}

cout<<"thetotalis"<top+1<<"cars."<

if(s->top==MAXNUM-1)

cout<<"andtheparkisfullnow!

"<

else

cout<<"andtheparkhave"<top<<"positionisempty!

"<

}

separator(40,'-',1);

}

////////////////showaisleofcar/////////////////////////////////

voidshowaisle(carnodequeue*q)

{

if(!

carnodequeueisempty(q))

{

carnode*p;

p=q->head->next;

cout<<"theailseinformationisfollow:

"<

separator(30,'-',1);

cout<<"numbertheintime"<

while(p!

=NULL)

{

cout<data.num<<"";

printdata(p->data.intime);

p=p->next;

}

}

else

{

cout<<"theailseisempty!

"<

}

separator(30,'-',1);

cout<

}

//////////////showparkandailse/////////////////////////////

voidshowall(Seqstack*s,carnodequeue*q)

{

showpark(s);

showaisle(q);

}

/////////////inpark//////////////////////////////////////////

voidInpark(Seqstack*s,carnodequeue*q)

{

carcc;

structtm*gm_data;

time_tseconds;

time(&seconds);//getthetime

gm_data=gmtime(&seconds);

cout<<"thenumberofcar"<

cin>>cc.num;

cc.intime=*gm_data;

if(!

Isfull(s)&&carnodequeueisempty(q))

{

cc.position=(s->top)+2;

Stackpush(s,cc);

showpark(s);

}

elseif(Isfull(s)||!

carnodequeueisempty(q))

{

cout<<"theparkiffull,thecarcanonlyparkinttheailse."<

cc.position=MAXNUM;

carnodequeuein(q,cc);

showall(s,q);

}

}

////////////////theoutpark/////////////////////////////////

voidOutpark(Seqstack*s,carnodequeue*q)

{

structtm*gm_data;

time_tseconds;

Seqstackp;

charnowtime[10];

inti,pos;

carcc;

Stackinit(&p);

if(Isempty(s))

{

cout<<"theparkisempty,nocarneedtoleave."<

exit(0);

}

else

{

cout<<"theparkinformationisfollow."<

showpark(s);

cout<<"whichoneneedtoleave?

"<

cin>>pos;

if(pos>0&&pos<=s->top+1)

{

for(i=s->top+1;i>pos;i--)

{

cc=Stackpop(s);

cc.position=cc.position-1;

Stackpush(&p,cc);

}

cc=Stackpop(s);

time(&seconds);

gm_data=gmtime(&seconds);

cc.outime=*gm_data;

cc.length=mktime(&cc.outime)-mktime(&cc.intime);

cc.expense=(cc.length/3600+1)*PRICE;

cout<<"theinformationwhichcaristoleaveisfollow."<

cout<

while(!

Isempty(&p))

{

cc=Stackpop(&p);

Stackpush(s,cc);

}

while(!

Isempty(s)&&!

carnodequeueisempty(q))

{

cc=carnodequeueout(q);

time(&seconds);

gm_data=gmtime(&seconds);

cc.intime=*gm_data;

Stackpush(s,cc);

}

}

else

{

cout<<"thecarpositioniswrong!

"<

}

}

}

主函数调用为:

#include"stdafx.h"

#include"example34_car.h"

intmain()

{

SeqstackPark;

carnodequeueAisle;

Stackinit(&Park);

carnodequeueinit(&Aisle);

charchoice;

do

{

cout<

separator(10,'-',0);

cout<<"themanagementofpark"<

separator(30,'-',1);

cout<<"1.thecarin"<

cout<<"2.thecarout"<

cout<<"3.watchtheparkinformation"<

cout<<"0.exit"<

separator(56,'-',1);

cout<<"thetotalis"<

cin>>choice;

switch(choice)

{

case'1':

Inpark(&Park,&Aisle);break;

case'2':

Outpark(&Park,&Aisle);break;

case'3':

showall(&Park,&Aisle);break;

}

}while(choice!

='0');

return0;

}

实验结果展示:

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2