停车场管理方案计划系统源代码.doc
./停车场管理系统 #include<stdio.h>#include<stdlib.h>#define OVERFLOW 0#define ERROR 0#define OK 1#define STACKSIZE 2 /车库容量 /时间节点typedef struct timeint hour;int min;Time; /车辆信息typedef structchar CarNum;float time; int pos_a; /车在停车场中的位置 int pos_b; /车在便道上的位置 int flag;Car,Car2;/车库信息 (顺序栈)typedef structCar *top;Car *base;int stacksize;SqStack; /初始化 int InitStack(SqStack &S)S.base=new CarSTACKSIZE; if(!S.base) exit(OVERFLOW);S.top=S.base;S.stacksize=STACKSIZE;return OK;/判空 int StackEmpty(SqStack S)if(S.top=S.base) return OK;elsereturn ERROR;/判满int StackFull(SqStack S)if(S.top-S.base>=S.stacksize) return OK;elsereturn ERROR; /入栈int Push(SqStack &S,Car e)if(S.top-S.base=S.stacksize) return ERROR;*S.top+=e;return OK; /出栈int Pop(SqStack &S,Car &e)if(S.top=S.base) return ERROR;e=*-S.top; return OK; /遍历栈int StackTraverse(SqStack S) Car *p=S.top; Car *q=S.base;int l=1;if(StackEmpty(S)for(int j=1;j<=STACKSIZE;j+)printf("t车牌: ");printf("tt到达时间: ");printf("t位置%d:空空",j);printf("n");return OK; while(p!=q)Car car=*(q);printf("t车牌: %d",car.CarNum);printf("tt到达时间:%5.2f",car.time);printf("tt位置:%d",l+);printf("n");q+;return OK;/备用车道 (顺序栈)typedef struct Car2 *top2;Car2 *base2; / int stacksize2;SqStack2; /初始化 int InitStack2(SqStack2 &S2) S2.base2=new Car2STACKSIZE; if(!S2.top2) exit(OVERFLOW); / S2.top2=S2.base2; S2.stacksize2=STACKSIZE; return OK; /判空int StackEmpty2(SqStack2 S2)if(S2.top2=S2.base2) return OK;else return ERROR; /进栈int Push2(SqStack2 &S2,Car2 e2)if(S2.top2-S2.base2=STACKSIZE) return ERROR;*S2.top2+=e2;return OK; /出栈int Pop2(SqStack2 &S2,Car2 &e2)if(S2.top2=S2.base2) return ERROR;e2=*-S2.top2;return OK; /车道信息(链队) typedef struct QNodeCar data;struct QNode *next;QNode,*QueuePtr; typedef structQueuePtr front;QueuePtr rear;LinkQueue;/初始化int InitQueue(LinkQueue &Q)Q.front=Q.rear=new QNode;Q.front->next=NULL;return OK; /进队int EnQueue(LinkQueue &Q,Car e)QueuePtr p;p=new QNode;p->data=e;p->next=NULL;Q.rear->next=p;Q.rear=p;return OK; /判空int QueueEmpty(LinkQueue Q)if(Q.front=Q.rear) return OK;else return ERROR; /出队 int DeQueue(LinkQueue &Q,Car &e)QueuePtr p;if(Q.front=Q.rear) return ERROR;p=Q.front->next;e=p->data;Q.front->next=p->next;delete p;return OK; /主函数 int main()int i=1;int j=1; int status;float time,money;LinkQueue Q;Car car_I,car_D,car_M;SqStack S;SqStack2 S2; InitStack(S); InitStack2(S2);InitQueue(Q);while(1)printf("ttt欢迎来到XXX停车场!n"); printf("*n");printf("ttt1-车辆到达停车场n"); printf("ttt2-车辆离开停车场n"); printf("ttt3-停车场存放车辆情况n"); printf("ttt0-退出程序n");printf("*n");printf("选择(0-3):n"); scanf("%d",&status) ;if(status=1)printf("t请输入车牌号:");scanf("%d",&car_I.CarNum);printf("t请输入车到达的时间:");scanf("%f",&car_I.time);if(!StackFull(S)Push(S,car_I); /车进入车库 car_I.pos_a=i;car_I.flag=1;i=i+1;for(int m=1;m<50;m+) /边线 printf("-");printf("n");printf("t车牌号:");printf("%d",car_I.CarNum);printf("t到达时间:");printf("%5.1ft",car_I.time); printf("t车库中的位置是:%dn",car_I.pos_a);for(int m=1;m<50;m+) /边线 printf("-");printf("n");printf("n");printf("n");elseEnQueue(Q,car_I);car_I.pos_b=j;car_I.flag=0; /+j;printf("n"); printf("tSorry!我们的车库已满!,您可以把车!免费!停在车道上!n");printf("n");for(int m=1;m<50;m+) /边线 printf(".");printf("n");printf("t车牌号:");printf("%d",car_I.CarNum);printf("t便道上的位置为:%dn",car_I.pos_b); for(int m=1;m<50;m+) /边线 printf(".");printf("n");printf("n");printf("n"); else if(status=2)/指令为 2, 开车离去(如果车在车库里收取停车费;在便道上则免费) printf("请输入客户的车牌号:");scanf("%d",&car_D.CarNum);printf("请输入现在的时间:");scanf("%f",&car_D.time);i=i-1; int flag=0;/判断车是否在便道上 if(StackFull(S)Car *p=S.top; Car *q=S.base; while(p!=q) Car car=*(q); if(car.CarNum!=car_D.CarNum)flag+;if(car.CarNum=car_D.CarNum)goto loop;q+;/whileif(flag>=STACKSIZE)printf("您的车停在便道上,所以免费!"); printf("n");printf("n");printf("n"); /ifelseloop:do /挡在前面的车给要出去的车让路 Pop(S,car_M); /加一个判断,判断是不是停车场里的车 if(car_D.CarNum!=car_M.CarNum)Push2(S2,car_M);elsecar_I.time=car_M.time;while(car_D.CarNum!=car_M.CarNum);while(!StackEmpty2(S2)/让路的车返回去 Pop2(S2,car_M); Push(S,car_M);while(!QueueEmpty(Q)&&!StackFull(S) if(!StackFull(S)DeQueue(Q,car_M); /便道上的车离开后进入停车场,那么后面的车的位置都得变。car_M.flag=1; Push(S,car_M);printf("车牌为%d的车离开车库,车道上车牌为%d的车进入车库n",car_D.CarNum,car_M.CarNum); time=car_D.time-car_I.time;if(time<0.0) printf("输入时间有错!请重新输入!");if(time>0.0&&time<=3.0)money=time*4;else money=time*6;printf("你的车牌为%d的车,应收费%5.2f元。",car_D.CarNum,money);printf("欢迎下次光临我们的车库n");printf("n");printf("n");printf("n"); else if(status=3) /指令为 3 ;查看车库停车情况; StackTraverse(S);else if(status!=1&&status!=2&&status!=3&&status!=0)printf("t指令错误! 请在下面重新输入:"); else if(status=0)break;