您的当前位置:首页数据结构-停车场管理程序代码

数据结构-停车场管理程序代码

2022-09-28 来源:乌哈旅游
源程序代码:

#include #include #include #include

#define MaxSize 5 #define fee 2 #define L 10000 #define M 20000 typedef int ElemType; ElemType tmpnum=0; ElemType tmptime=0; typedef struct {

ElemType car_num[MaxSize]; ElemType car_time[MaxSize]; int top; }STACK;

typedef struct qnode { ElemType car_num; ElemType car_time; struct qnode *next; }QTYPT;

typedef struct qptr { QTYPT *front; QTYPT *rear; }SQUEUE; SQUEUE LQ;

void InitStack(STACK *S){ S->top = -1; }

int Full(STACK *S){ if(S->top==MaxSize-1){

printf(\"\\n Stack is full! Push\"); return 0; }

return 1; }

int Push(STACK *S,ElemType num,ElemType time){ if(S->top==MaxSize-1){

printf(\"\\n Stack is full! Push\");

return 0; }

S->top++;

S->car_num[S->top]=num; S->car_time[S->top]=time; return 1; }

int Empty(STACK *S){

return (S->top==-1 ? 1:0); }

int Pop(STACK *S,ElemType *num,ElemType *time){ if(Empty(S)){

puts(\"Stack is free Pop\"); return 0; }

*num=S->car_num[S->top]; *time=S->car_time[S->top]; S->top--; return 1; }

int GetTop(STACK *S,ElemType *num,ElemType *time){ if(Empty(S)){

puts(\"Stack is free Gettop\"); }

*num=S->car_num[S->top]; *time=S->car_time[S->top]; return 1; }

void InitQueue(SQUEUE *LQ){ QTYPT *p=NULL;

p=(QTYPT *)malloc(sizeof(QTYPT)); p->next=NULL;

LQ->front=LQ->rear=p; }

int EnQueue(SQUEUE *LQ,ElemType num,ElemType time){ QTYPT *s;

s=(QTYPT *)malloc(sizeof(QTYPT)); s->car_num=num; s->car_time=time;

s->next=LQ->rear->next; LQ->rear->next=s; LQ->rear=s; return 1; }

int CountQueue(SQUEUE *LQ){ int i=1;

QTYPT *mfront=NULL; QTYPT *mrear=NULL;

mfront=LQ->front; mrear=LQ->rear;

while(!(LQ->front==LQ->rear)){ i++;

LQ->front=LQ->front->next; }

LQ->front=mfront; return i; }

int Empty_Q(SQUEUE *LQ){

return (LQ->front==LQ->rear?1:0); }

int OutQueue(SQUEUE *LQ,ElemType *num,ElemType *time){ QTYPT *p;

if(Empty_Q(LQ)){

puts(\"Quenue is free OutQuenue\"); return 0; }

p=LQ->front->next; *num=p->car_num; *time=p->car_time;

LQ->front->next=p->next; if(LQ->front->next==NULL) LQ->rear=LQ->front; free(p); return 1; }

int GetHead(SQUEUE *LQ,ElemType *num,ElemType *time){ if(Empty_Q(LQ)){

puts(\"Quenue is free GetHead\");

return 0; }

*num=LQ->front->next->car_num; *time=LQ->front->next->car_time; return 1; }

void sleep(int time){ clock_t goal;

goal=time*(CLOCKS_PER_SEC)+clock(); while(goal > clock()) { ; } }

int chackinput(STACK *S,int pnum){ int i=0; int num; num = pnum; i=S->top;

for(;!(i==-1);i--)

if(S->car_num[i]==num) return 1; return 0; }

int chacktime(STACK *S,int ptime){

return S->car_time[S->top] <= ptime ? 1 : 0; }

int displaystats(STACK *S,int pinput){ void displayhead(void); int i = 0; i = S->top;

switch(pinput){ case 10000: {

if(!Empty(S))

for(;!(i==-1);i--)

printf(\"<===%d时%d号车停与%d

===>\\n\

else

cout<<\"停车场为空\";

车位

printf(\"还有车%d个位\\n\ break; }

case 20000: {

displayhead(); break; }

default: {

return 1; } }

return 0; }

void displayhead(void){

cout<<'\\n'<<\"<===============CT停车场管理系统

===================>\"<cout<<\"<==操作说明: ******* ==>\"<\"<\"<\"<cout<<\"<==============================================>\"<void displayChange(STACK *S,ElemType pnum,int ptime){

printf(\" (单价 %d元/小时 )\\n\

printf(\"<======================电子收据===================>\\n\");

printf(\"<==停车时间:--------------------------%d小时

==>\\n\

printf(\"<==车牌号码:--------------------------%d

==>\\n\

printf(\"<==应收费用:--------------------------%d 元

==>\\n\

printf(\"<====================谢谢=欢迎下次再来

=============>\\n\");

printf(\"正在打印收据请稍等\\n\");

for(int count=1; count < 1;count++){ printf(\"=\"); fflush(stdout); sleep(1); }

printf(\">\\n\"); sleep(1); }

void wait(char *string){ printf(\"%s\\n\

for(int count=1; count < 1;count++){ printf(\"-\"); fflush(stdout); sleep(1); }

printf(\">\\n\"); }

int outparkstation(STACK *S1,STACK *TS,ElemType pnum){ int t_num=0; int t_time=0; while(1){

Pop(S1,&t_num,&t_time); if(t_num == pnum){ tmpnum=t_num; tmptime=t_time; while(!Empty(TS)){

Pop(TS,&t_num,&t_time); Push(S1,t_num,t_time); }

return 1; }

Push(TS,t_num,t_time); }

return 0; }

int inparkstation(STACK *S){ int parknum; int parktime;

printf(\"还有车%d个位\\n\ printf(\"请输入车牌号码:\"); cin>>parknum;

while(chackinput(S,parknum)){ printf(\"车牌号码重复,请输入%d1或者其他\ cin>>parknum; }

printf(\"请输入停车时间:\");

cin>>parktime;

printf(\"%d号车于%d时停靠在%d位\\n\ Push(S,parknum,parktime); return 1; }

int inbiandao(SQUEUE *SQ,STACK *S){ int parknum ;

printf(\"对不起,停车场已满,请您到便道等待.您将第\"); printf(\"%d进入停车场\\n\ printf(\"请输入车牌号码:\"); cin>>parknum;

while(chackinput(S,parknum)) { printf(\"车牌号码重复,请输入%d1或者其他\ cin>>parknum;

} EnQueue(SQ,parknum,0); return 1; }

int OutParkingStation(SQUEUE *biandao,STACK *car,STACK *tmp){ int parknum = 0; int parktime = 0; int buf=0;

if(!Empty(car)){

displaystats(car,10000);

printf(\"请输入您要调出的车牌号码:\"); cin>>parknum;

while(!chackinput(car,parknum)) { printf(\"没有您要的%d的车牌号码,请输入正确的车牌号码:

\

cin>>parknum;

} outparkstation(car,tmp,parknum); printf(\"%d时%d号车进入停车场\\n\ printf(\"请输入现在的时间:\"); cin>>parktime;

while(!chacktime(car,parktime)) { cout<<\"输入时间小于停车时间,请重新输入:\";

cin>>parktime; }

displayChange(car,parknum,parktime); if(biandao->front==biandao->rear) { }

else{ printf(\"%d号车位空开\\n\

printf(\"%d时便道上的%d号汽车驶入%d号车位\

OutQueue(biandao,&parknum,&buf); Push(car,parknum,parktime); } return 2; }

printf(\"停车场为空\\n\"); return 1; };

int main(int argc,char* agv[]){ char chance='A'; STACK car;

InitStack(&car); STACK tmp;

InitStack(&tmp); SQUEUE biandao;

InitQueue(&biandao); loop: while(1){

displayhead(); cout<<\"=>:\"; cin>>chance; switch(chance) { case 'A': {

wait(\"正在查询车位,请稍等:\");

if(Full(&car)) inparkstation(&car); else

inbiandao(&biandao,&car); break; }

case 'D': {

OutParkingStation(&biandao,&car,&tmp); break; }

case 'L': {

displaystats(&car,10000);

break; }

case 'M': {

displaystats(&car,20000); break; }

case 'E': {

wait(\"正在保存数据程序即将退出\\n命令执行中:\"); exit(0); }

default: {

cout<<\"输入错误\"<system(\"PAUSE\"); return 0; }

因篇幅问题不能全部显示,请点此查看更多更全内容