C语言实现简易停车场管理系统_第1页
C语言实现简易停车场管理系统_第2页
C语言实现简易停车场管理系统_第3页
C语言实现简易停车场管理系统_第4页
C语言实现简易停车场管理系统_第5页
已阅读5页,还剩6页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第C语言实现简易停车场管理系统本文实例为大家分享了C语言实现停车场管理系统的具体代码,供大家参考,具体内容如下

问题描述:

设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列(大门在最南端,最先到达的第一辆车停放在车场的最北端),若车场内已停满n辆汽车,则后来的汽车只能在门外的便道上等候,一旦有车开走,则排在便道上的第一辆车即可开入;当停车场内某辆车要离开时,在它之后开入的车辆必须先退出车场为它让路,待该辆车开出大门外,其它车辆再按原次序进入车场,每辆停放在车场的车在它离开停车场时必须按它停留的时间长短交纳费用。

由题得,此系统要实现的功能为:

(1)设计停车场内的结构。(由题分析为一个栈,因为只有一个门所以其就像数据结构中学到的栈,但是因为既要出栈又要入栈,此处我就将这个栈简化为了一个链表)

(2)当车库满时,在车库外等待的结构。(就像排队一样,先来先进后来后进,只能从一端进,另一端出)。

(3)车辆的结构,一辆车要有什么信息?首先要有这辆车的车牌号,可以用一个字符数组来存储(因为车牌不一定全是数字,还可能有汉字,英文字母等),题中要求要用要计算收费,就要知道驶入时间和驶出时间(怎样获取在下面会说到)。

算法描述:

1、刚开始定义结构类型,如车的类型,车库里的类型,车库外等待的类型。

2、声明所要用到的函数:

voidmenu(Stack*cheku,SequenQueue*paidui);//开始菜单

//就是展示出菜单的函数

//队列的相关操作

SequenQueue*InitQueue();//申请一个空队

intEmptyQueue(SequenQueue*Q);//判断队空

intFullQueue(SequenQueue*Q);//判断队满

intEnQueue(SequenQueue*Q,ElemType*e);//入队

intDeQueue(SequenQueue*Q,ElemType*e);//出队

Stack*build();//建链表

intfullstack(Stack*cheku);//判断链表满

voidtingche(Stack*cheku,SequenQueue*paidui);//停车的函数

voidlikai(Stack*cheku,SequenQueue*paidui);//离开的函数

voidchakan(Stack*cheku,SequenQueue*paidui);//查看车库停车情况的函数

3、一些可能不理解的说明的说明。

(1).获取时间的函数,写头文件#includetime.h,定义一个time_t类型的变量starttime,starttime=time(NULL);就是获取1970年1月1日到当前的秒数,定义一个字符数组tmp2[100],strftime(tmp2,sizeof(tmp2),%Y-%m-%d%H:%M:%S,localtime(q-a.starttime));用这一句就能把当前时间的年月日时分秒存进字符数组中,puts(tmp2),就得到了当前的时间。

(2).代码中用到了Sleep函数,这个函数的功能为延时,要用到一个头文件,#includetime.h,此函数是与(3)中的配合使用。

(3).(2)中提到的就是system(cls),他的作用就是清屏,(2)的作用就是把结果让用户看到。故两者配合,就能得到奇效。

程序代码:

#includestdio.h

#includestdlib.h

#includetime.h

#includewindows.h

#includestring.h

#defineTRUE1

#defineFALSE0

#defineMAXSIZE1024

staticintmaxsize;

typedefcharElemType;

typedefstruct

char

num[10];//车牌

time_tstarttime,endtime;//进入推出时间

}car;

//车

typedefstructStack

inttop;

cara;

structStack*next;

}Stack;

typedefstruct

chara[10];

}dat;

typedefstruct

{//队列结构定义

dat

data[MAXSIZE];

int

front;

int

rear;

}SequenQueue;

voidmenu(Stack*cheku,SequenQueue*paidui);//开始菜单

SequenQueue*InitQueue();//申请一个空队

intEmptyQueue(SequenQueue*Q);//判断队空

intFullQueue(SequenQueue*Q);//判断队满

intEnQueue(SequenQueue*Q,ElemType*e);//入队

intDeQueue(SequenQueue*Q,ElemType*e);//出队

Stack*build();//建链表

voidtingche(Stack*cheku,SequenQueue*paidui);

intfullstack(Stack*cheku);

voidlikai(Stack*cheku,SequenQueue*paidui);

voidchakan(Stack*cheku,SequenQueue*paidui);

intmain()

Stack*cheku=build();

SequenQueue*paidui=InitQueue();

printf("请输入车库最大容量:");

scanf("%d",maxsize);

system("cls");

menu(cheku,paidui);

return0;

voidmenu(Stack*cheku,SequenQueue*paidui)

printf("**********

欢迎来停车!

**********\n");

printf("**********

请选择一项

**********\n");

printf("**********

1:park.

**********\n");

printf("**********

2:leave.

**********\n");

printf("**********

3:view.

**********\n");

printf("**********

4:exit.

**********\n");

intoption;

scanf("%d",option);

system("cls");

switch(option)

{

case1:

{

tingche(cheku,paidui);

menu(cheku,paidui);

break;

}

case2:

{

likai(cheku,paidui);

menu(cheku,paidui);

break;

}

case3:

{

chakan(cheku,paidui);

menu(cheku,paidui);

break;

}

case4:

{

printf("**********

欢迎再次使用,谢谢!

**********\n");

break;

}

default:{

printf("**********

请输入正确的指令!

**********\n");

Sleep(1000);

menu(cheku,paidui);

system("cls");

break;

}

}

intfullstack(Stack*cheku)

if(cheku-topmaxsize-1)

return1;

else

return0;

SequenQueue*InitQueue()

SequenQueue*Q=NULL;

Q=(SequenQueue*)malloc(sizeof(SequenQueue));

Q-front=Q-rear=0;

returnQ;

intDeQueue(SequenQueue*Q,ElemType*e)

if(EmptyQueue(Q))

returnFALSE;

else

{

strcpy(e,Q-data[Q-front].a);

Q-front=(Q-front+1)%MAXSIZE;

returnTRUE;

}

intEnQueue(SequenQueue*Q,ElemType*e)

if(FullQueue(Q))

{

printf("等待的车辆太多,请下次再来");

returnFALSE;

}

strcpy(Q-data[Q-front].a,e);

Q-rear=(Q-rear+1)%MAXSIZE;

returnTRUE;

intFullQueue(SequenQueue*Q)

if((Q-rear+1)%MAXSIZE==Q-front)

{

returnTRUE;

}

else

{

returnFALSE;

}

intEmptyQueue(SequenQueue*Q)

if(Q-front==Q-rear)

returnTRUE;

else

returnFALSE;

Stack*build(Stack*cheku,SequenQueue*paidui)

Stack*a;

a=(Stack*)malloc(sizeof(Stack));

a-top=-1;

returna;

voidtingche(Stack*cheku,SequenQueue*paidui)

Stack*p;

p=(Stack*)malloc(sizeof(Stack));

printf("请输入车牌号\n");

fflush(stdin);

gets(p-a.num);

if(fullstack(cheku))

{

p-next=cheku-next;

cheku-next=p;

p-a.starttime=time(NULL);

cheku-top++;

printf("停车成功\n");

Sleep(1000);

system("cls");

}

else

{

printf("车库已满请在门口等待\n");

EnQueue(paidui,p-a.num);

Sleep(1000);

system("cls");

}

voidlikai(Stack*cheku,SequenQueue*paidui)

charm[10];

Stack*p,*q;

chare[10];

intn=0;

p=cheku;

if(cheku-top==-1)

{

printf("车库为空\n");

Sleep(1000);

system("cls");

}

else

{

printf("请输入离开的车牌:\n");

fflush(stdin);

gets(m);

while(p-next!='\0')

{

doublemoney;

if(strcmp(p-next-a.num,m)==0)

{

q=p-next;

p-next=q-next;

q-a.endtime=time(NULL);

money=(q-a.endtime-q-a.starttime)*0.00139;

chartmp1[100],tmp2[100];

strftime(tmp1,sizeof(tmp1),"%Y-%m-%d

%H:%M:%S",localtime(q-a.endtime));

strftime(tmp2,sizeof(tmp2),"%Y-%m-%d

%H:%M:%S",localtime(q-a.starttime));

printf("停车时间:%s\n",tmp2);

printf("离开时间:%s\n",tmp1);

printf("共停%ds\n",q-a.endtime-q-a.starttime);

printf("收费%.5lf元(一小时五元)\n",money);

Sleep(3000);

free(q);

system("cls");

cheku-top--;

n++;

if(EmptyQueue(paidui)==0)

{

DeQueue(paidui,e);

Stack*d=(Stack*)malloc(sizeof(Stack));

strcpy(d-a.num,e);

d-a.starttime=time(NULL);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论