停车场管理系统的代码

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

设停车场是一个可停放n辆车的狭长通道,且只有一个大门可供汽车进出。在停车场内,汽车按到达的先后次序,由北向南依次排列(假设大门在最南端)。若车场内已停满n辆车,则后来的汽车要在门外的便道上等候,当有车开走时,便道上的第一辆车即可开入。当停车场内某辆车要离开时,在它之后进去的车辆必须先推出车场为它让路,待该辆车开出大门以后,其他车辆再按原次序返回车场。每辆车离开停车场时,应按其停留时间的长短交费(在便道上停留的时间不收费)。试编写程序,模拟上述管理过程。要求以顺序栈模拟停车场,以链队列模拟便道。从终端读入汽车到达或离去的数据,每组数据包括三项:(1)是“到达”还是“离去”(2)汽车牌照号码;(3)“到达”或“离去”的时刻。与每组输入信息相应的输出信息为:如果是到达的车辆,则输出其在停车场中或便道上的位置;如果是离去的车辆,则输出其在停车场中停留的时间和应缴的费用。(需另设一个栈,临时停放为让路而从车场退出的车。)

#include

#define M 5

using namespace std;

typedef int Datatype;

typedef struct

{

Datatype bianhao[M];

int top;

int h[M]; //时

int m[M]; //分

int s[M]; //秒

}Seqstack; //停车场栈的定义

typedef struct Node //便道结点,表示一辆汽车

{

Datatype bianhao;

struct Node *next;

}node;

typedef struct

{

node *front;

node *rear;

int count;

}biandao; //便道

//停车场顺序栈初始化

void InitSeqstack(Seqstack *t)

{

t->top=-1;

}

//进栈,即进入停车场

int Push(Seqstack *t,int x,int h,int m,int s)

{

if(t->top==M-1)

return 0; //停车场栈已满

t->top++;

t->bianhao[t->top]=x;

t->h[t->top]=h;

t->m[t->top]=m;

t->s[t->top]=s;

return 1;

}

//出栈,即离开停车场

int Pop(Seqstack *t,int *x,int *h,int *m,int *s)

{

if(t->top==-1)

return 0;

else

{

*x=t->bianhao[t->top];

*h=t->h[t->top];

*m=t->m[t->top];

*s=t->s[t->top];

t->top--;

return 1;

}

}

//查找某牌照的车在停车场中的位置,若找到则返回其位置,否则返回-1

int Find(Seqstack t,int x)

{

int i;

for(i=0;i<=t.top;i++)

{ if(t.bianhao[i]!=x)

continue;

else

break;

}

if(i>t.top)

return(-1);

else

return(i);

}

//判断停车场内是否已满

int IsSeqstackFull(Seqstack t)

{

if(t.top==M-1)

return 1;

else

return 0;

}

//判断停车场内是否已没有车辆

int IsSeqstackEmpty(Seqstack t)

{

if(t.top==-1)

return 1;

else

return 0;

}

//依次显示停车场内停放的所有车辆

void ShowSeqstack(Seqstack t)

{

int i;

if(t.top==-1)

cout<<"停车场内没有停放车辆"<

else

for(i=0;i<=t.top;i++)

cout<<"牌照:"<

}

//队列初始化

int Initbiandao(biandao *Q)

{

Q->front=new node;

if(Q->front!=NULL)

{

Q->rear=Q->front;

Q->front->next=NULL;

Q->count=0;

return(true);

}

else return(false);

}

//入队操作,即当停车场满了的时候,再到达的车辆进去便道队列

int Enterbiandao(biandao *Q,int x)

{

node *NewNode;

NewNode=new node;

if(NewNode!=NULL)

{

NewNode->bianhao=x;

NewNode->next=NULL;

Q->rear->next=NewNode;

Q->rear=NewNode;

Q->count++;

return(true);

}

else return(false);

}

//出队操作,即便道上的车辆从便道开出来

int Deletebiandao(biandao *Q,int *x)

{

node *p;

if(Q->front==Q->rear)

return(false);

相关文档
最新文档