C C++ 停车场管理系统
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
停车场管理系统
某停车场可以停放n辆汽车,该停车场只有一个大门,每辆汽车离开停车场都要求之前的汽车必须先退出停车场为它让道,而后让道的汽车再次驶入停车场,停车场示意图如下:
要求设计停车管理系统,实现车辆的进入、离开并根据停车时间计费。
程序:
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <time.h>
#define OK 1
#define NULL 0
#define ERROR 0
#define TURE 1
#define FALSE 0
#define OVERFLOW -2
typedef int Status;
#define MAXQSIZE 100
{
int e;
*come=*come+1;
Pop(S,e);
set[e].setnumber=e;
copy(set[e].num,number);
struct tm *newtime;
char am_pm[] = "AM";
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_timeHale Waihona Puke Baidu); /* Convert to local time. */
set[e].reach.hour=newtime->tm_hour;
set[e].reach.mday=newtime->tm_mday;
set[e].reach.min=newtime->tm_min;
void copy(char *a,char *b)
{
int i;
for(i=0;(a[i]=b[i])!='\0';i++){;}
}
void CreateList_L(LinkList &L)
{
L=(LinkList) malloc (sizeof(LNode));
L->next=NULL;
}
Status is_long(char *num)
{
return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}
Status w_total(SqQueue Q)
{
return QueueLength(Q);
};/*在便车道的车辆总数*/
Status EnQueue(SqQueue &Q,int e)
{
if((Q.rear+1)%MAXQSIZE==Q.front)
#define MAX 3/*车库容量*/
#define price 0.05 /*每车每分钟费用*/
struct now_time
{
int mday;
int hour;
int min;
};
struct information
{
int setnumber;
char num[10];
struct now_time reach;
}
Status lListInsert_Link(LinkList &llist,int i,int lset,int totalhour,float fee,int day,int hour,int min)
{
LNode *p,*s;
int j;
p=llist;
j=0;
while(p&&j<i-1)
struct now_time leave;
}set[MAX+1];/*车位信息*/
typedef struct
{
char *base;
int front;
int rear;
}SqQueue;
typedef struct
{
int *base;
int *top;
int stacksize;
}SqStack;
{
printf("*****车场并没有停车*******\n");
return ERROR;
}
else
{
if(lset>MAX ||lset<1)
{
printf("*****您输入有误,该车号并不存在!*******\n请重新输入您的车位号:\n");
t=1;
}
else
{
if(set[lset].num[1]=='#')
S.base=(int * )malloc(MAX * sizeof(int));
if(!S.base)exit(OVERFLOW);
S.top=S.base;
S.stacksize=MAX;
for(i=1;i<=MAX;i++)
{
*S.top++=i;
}
return OK;
}
/*模拟车站*/
Status initQueue(SqQueue &Q)
newtime = localtime( &long_time ); /* Convert to local time. */
totalhour=(newtime->tm_mday-set[lset].reach.mday)*24*60+(newtime->tm_hour-set[lset].reach.hour)*60+(newtime->tm_min-set[lset].reach.min);
s->data.reach.hour=set[setnumber].reach.hour;
s->data.reach.mday=set[setnumber].reach.mday;
s->data.reach.min=set[setnumber].reach.min;
copy(s->data.num,set[setnumber].num);
int lset,t;
int j=1;
int totalhour;
float fee;
printf ("请输入您的车位号");
do{
scanf ("%d",&lset);
getchar();
for(int i=0;i<=MAX;i++)
{
if(set[lset].num[1]=='#')
j=0;
}
if(j==0)
{
printf("***该车位为空,不能进行离开操作!***\n请重新输入:\n");
t=1;
}
else{
struct tm *newtime;
char am_pm[] = "AM";
time_t long_time;
time( &long_time ); /* Get time as long integer. */
{
int j=0,m=0,k;
int a=0;
for(int i=0;num[i]!='\0';i++)
{
j++;
}
for(i=1;i<=MAX;i++)
{
if(strcmp(set[i].num,num)==0)
{
m=1;
break;
}
}
if(j!=3||m==1)
return 1;
else
return 0;
typedef struct LNode
{
struct
{
int stnumber;
char num[10];
struct now_time reach;
struct now_time leave;
float fee;
int totalhour;
}data;
struct LNode *next;
}LNode,*LinkList;
return ERROR;
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;
return OK;
}
Status enterlane(SqQueue &Q,int waitenumber)
{
EnQueue(Q,waitenumber);
return OK;
}/*进入便车道等待*/
printf( "离开时间%d:%d:%d\n", newtime->tm_mday,newtime->tm_hour,newtime->tm_min);
printf( "您的停车费用总共:%f",fee);
printf("\n\n------------------------------\n\t*******谢谢您的光临,祝您一路平安********!\n\n");
{
LNode *p,*s;
int j;
p=L;
j=0;
while(p&&j<i-1)
{
p=p->next;
++j;
}
if(!p||j>i-1)
return ERROR;
s=(LinkList)malloc(sizeof(LNode));
s->data.stnumber=set[setnumber].setnumber;
printf("\n\n****请核对您的停车信息****\n");
printf("车牌号:%s\n",set[e].num);
printf("停车车位号:%d\n",set[e].setnumber);
printf( "到达时间%d:%d:%d\n", set[e].reach.mday,set[e].reach.hour,set[e].reach.min);
ccord(clist,*come,set[e].setnumber);
}/*进入停车场*/
Status DeQueue(SqQueue &Q)
{
if(Q.front==Q.rear)
return ERROR;
Q.front=(Q.front+1)%MAXQSIZE;
return OK;
}
Status EmptyQueue(SqQueue Q)
return OK;
else
return ERROR;
}/*判断是否还有停车位*/
Status Pop(SqStack &S,int &e)
{
if(S.top==S.base)
return ERROR;
e=*--S.top;
return OK;
}/*弹栈*/
Status QueueLength(SqQueue Q)
fee=price*totalhour;
printf("****以下是您本次停车的信息****\n");
printf("车牌号:%s\n",set[lset].num);
printf("停车车位号:%d\n",set[lset].setnumber);
printf( "到达时间%d:%d:%d\n", set[lset].reach.mday,set[lset].reach.hour,set[lset].reach.min);
s->next=p->next;
p->next=s;
return OK;
}
void ccord(LinkList clist,int i,int setnumber)
{
ListInsert_Link(clist,i,setnumber);
}
Status initStack(SqStack &S)
{
int i;
{
p=p->next;
++j;
}
if(!p||j>i-1)
return ERROR;
s=(LinkList)malloc(sizeof(LNode));
s->data.fee=fee;
s->data.totalhour=totalhour;
s->data.stnumber=lset;
s->data.leave.mday=day;
{
Q.base=(char*)malloc(100*sizeof(char[10]));
if(!Q.base)exit(OVERFLOW);
Q.front=Q.rear=0;
return OK;
}
/*模拟通道*/
Status stack_empty(SqStack S)
{
if(S.top==S.base)
{
if(Q.front==Q.rear)
return OK;
else
return ERROR;
}
Status leavestop(LinkList llist,LinkList clist,SqStack &S,SqQueue &Q,int *come,int*leave)
{
char number[10];
Status Push(SqStack &S,int e)
{
if(S.top-S.base>=S.stacksize)
{
if(!S.base)
exit(OVERFLOW);
S.top=S.base+S.stacksize;
}
*S.top++=e;
return OK;
}
void enterstop( LinkList clist,SqStack &S,char number[10],int *come)
s->data.leave.hour=hour;
s->data.leave.min=min;
copy(s->data.num,set[lset].num);
s->next=p->next;
p->next=s;
return OK;
}
Status ListInsert_Link(LinkList &L,int i,int setnumber)
某停车场可以停放n辆汽车,该停车场只有一个大门,每辆汽车离开停车场都要求之前的汽车必须先退出停车场为它让道,而后让道的汽车再次驶入停车场,停车场示意图如下:
要求设计停车管理系统,实现车辆的进入、离开并根据停车时间计费。
程序:
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <time.h>
#define OK 1
#define NULL 0
#define ERROR 0
#define TURE 1
#define FALSE 0
#define OVERFLOW -2
typedef int Status;
#define MAXQSIZE 100
{
int e;
*come=*come+1;
Pop(S,e);
set[e].setnumber=e;
copy(set[e].num,number);
struct tm *newtime;
char am_pm[] = "AM";
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_timeHale Waihona Puke Baidu); /* Convert to local time. */
set[e].reach.hour=newtime->tm_hour;
set[e].reach.mday=newtime->tm_mday;
set[e].reach.min=newtime->tm_min;
void copy(char *a,char *b)
{
int i;
for(i=0;(a[i]=b[i])!='\0';i++){;}
}
void CreateList_L(LinkList &L)
{
L=(LinkList) malloc (sizeof(LNode));
L->next=NULL;
}
Status is_long(char *num)
{
return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}
Status w_total(SqQueue Q)
{
return QueueLength(Q);
};/*在便车道的车辆总数*/
Status EnQueue(SqQueue &Q,int e)
{
if((Q.rear+1)%MAXQSIZE==Q.front)
#define MAX 3/*车库容量*/
#define price 0.05 /*每车每分钟费用*/
struct now_time
{
int mday;
int hour;
int min;
};
struct information
{
int setnumber;
char num[10];
struct now_time reach;
}
Status lListInsert_Link(LinkList &llist,int i,int lset,int totalhour,float fee,int day,int hour,int min)
{
LNode *p,*s;
int j;
p=llist;
j=0;
while(p&&j<i-1)
struct now_time leave;
}set[MAX+1];/*车位信息*/
typedef struct
{
char *base;
int front;
int rear;
}SqQueue;
typedef struct
{
int *base;
int *top;
int stacksize;
}SqStack;
{
printf("*****车场并没有停车*******\n");
return ERROR;
}
else
{
if(lset>MAX ||lset<1)
{
printf("*****您输入有误,该车号并不存在!*******\n请重新输入您的车位号:\n");
t=1;
}
else
{
if(set[lset].num[1]=='#')
S.base=(int * )malloc(MAX * sizeof(int));
if(!S.base)exit(OVERFLOW);
S.top=S.base;
S.stacksize=MAX;
for(i=1;i<=MAX;i++)
{
*S.top++=i;
}
return OK;
}
/*模拟车站*/
Status initQueue(SqQueue &Q)
newtime = localtime( &long_time ); /* Convert to local time. */
totalhour=(newtime->tm_mday-set[lset].reach.mday)*24*60+(newtime->tm_hour-set[lset].reach.hour)*60+(newtime->tm_min-set[lset].reach.min);
s->data.reach.hour=set[setnumber].reach.hour;
s->data.reach.mday=set[setnumber].reach.mday;
s->data.reach.min=set[setnumber].reach.min;
copy(s->data.num,set[setnumber].num);
int lset,t;
int j=1;
int totalhour;
float fee;
printf ("请输入您的车位号");
do{
scanf ("%d",&lset);
getchar();
for(int i=0;i<=MAX;i++)
{
if(set[lset].num[1]=='#')
j=0;
}
if(j==0)
{
printf("***该车位为空,不能进行离开操作!***\n请重新输入:\n");
t=1;
}
else{
struct tm *newtime;
char am_pm[] = "AM";
time_t long_time;
time( &long_time ); /* Get time as long integer. */
{
int j=0,m=0,k;
int a=0;
for(int i=0;num[i]!='\0';i++)
{
j++;
}
for(i=1;i<=MAX;i++)
{
if(strcmp(set[i].num,num)==0)
{
m=1;
break;
}
}
if(j!=3||m==1)
return 1;
else
return 0;
typedef struct LNode
{
struct
{
int stnumber;
char num[10];
struct now_time reach;
struct now_time leave;
float fee;
int totalhour;
}data;
struct LNode *next;
}LNode,*LinkList;
return ERROR;
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;
return OK;
}
Status enterlane(SqQueue &Q,int waitenumber)
{
EnQueue(Q,waitenumber);
return OK;
}/*进入便车道等待*/
printf( "离开时间%d:%d:%d\n", newtime->tm_mday,newtime->tm_hour,newtime->tm_min);
printf( "您的停车费用总共:%f",fee);
printf("\n\n------------------------------\n\t*******谢谢您的光临,祝您一路平安********!\n\n");
{
LNode *p,*s;
int j;
p=L;
j=0;
while(p&&j<i-1)
{
p=p->next;
++j;
}
if(!p||j>i-1)
return ERROR;
s=(LinkList)malloc(sizeof(LNode));
s->data.stnumber=set[setnumber].setnumber;
printf("\n\n****请核对您的停车信息****\n");
printf("车牌号:%s\n",set[e].num);
printf("停车车位号:%d\n",set[e].setnumber);
printf( "到达时间%d:%d:%d\n", set[e].reach.mday,set[e].reach.hour,set[e].reach.min);
ccord(clist,*come,set[e].setnumber);
}/*进入停车场*/
Status DeQueue(SqQueue &Q)
{
if(Q.front==Q.rear)
return ERROR;
Q.front=(Q.front+1)%MAXQSIZE;
return OK;
}
Status EmptyQueue(SqQueue Q)
return OK;
else
return ERROR;
}/*判断是否还有停车位*/
Status Pop(SqStack &S,int &e)
{
if(S.top==S.base)
return ERROR;
e=*--S.top;
return OK;
}/*弹栈*/
Status QueueLength(SqQueue Q)
fee=price*totalhour;
printf("****以下是您本次停车的信息****\n");
printf("车牌号:%s\n",set[lset].num);
printf("停车车位号:%d\n",set[lset].setnumber);
printf( "到达时间%d:%d:%d\n", set[lset].reach.mday,set[lset].reach.hour,set[lset].reach.min);
s->next=p->next;
p->next=s;
return OK;
}
void ccord(LinkList clist,int i,int setnumber)
{
ListInsert_Link(clist,i,setnumber);
}
Status initStack(SqStack &S)
{
int i;
{
p=p->next;
++j;
}
if(!p||j>i-1)
return ERROR;
s=(LinkList)malloc(sizeof(LNode));
s->data.fee=fee;
s->data.totalhour=totalhour;
s->data.stnumber=lset;
s->data.leave.mday=day;
{
Q.base=(char*)malloc(100*sizeof(char[10]));
if(!Q.base)exit(OVERFLOW);
Q.front=Q.rear=0;
return OK;
}
/*模拟通道*/
Status stack_empty(SqStack S)
{
if(S.top==S.base)
{
if(Q.front==Q.rear)
return OK;
else
return ERROR;
}
Status leavestop(LinkList llist,LinkList clist,SqStack &S,SqQueue &Q,int *come,int*leave)
{
char number[10];
Status Push(SqStack &S,int e)
{
if(S.top-S.base>=S.stacksize)
{
if(!S.base)
exit(OVERFLOW);
S.top=S.base+S.stacksize;
}
*S.top++=e;
return OK;
}
void enterstop( LinkList clist,SqStack &S,char number[10],int *come)
s->data.leave.hour=hour;
s->data.leave.min=min;
copy(s->data.num,set[lset].num);
s->next=p->next;
p->next=s;
return OK;
}
Status ListInsert_Link(LinkList &L,int i,int setnumber)