停车场管理系统.docx

上传人:b****3 文档编号:6577357 上传时间:2023-05-10 格式:DOCX 页数:28 大小:393.75KB
下载 相关 举报
停车场管理系统.docx_第1页
第1页 / 共28页
停车场管理系统.docx_第2页
第2页 / 共28页
停车场管理系统.docx_第3页
第3页 / 共28页
停车场管理系统.docx_第4页
第4页 / 共28页
停车场管理系统.docx_第5页
第5页 / 共28页
停车场管理系统.docx_第6页
第6页 / 共28页
停车场管理系统.docx_第7页
第7页 / 共28页
停车场管理系统.docx_第8页
第8页 / 共28页
停车场管理系统.docx_第9页
第9页 / 共28页
停车场管理系统.docx_第10页
第10页 / 共28页
停车场管理系统.docx_第11页
第11页 / 共28页
停车场管理系统.docx_第12页
第12页 / 共28页
停车场管理系统.docx_第13页
第13页 / 共28页
停车场管理系统.docx_第14页
第14页 / 共28页
停车场管理系统.docx_第15页
第15页 / 共28页
停车场管理系统.docx_第16页
第16页 / 共28页
停车场管理系统.docx_第17页
第17页 / 共28页
停车场管理系统.docx_第18页
第18页 / 共28页
停车场管理系统.docx_第19页
第19页 / 共28页
停车场管理系统.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

停车场管理系统.docx

《停车场管理系统.docx》由会员分享,可在线阅读,更多相关《停车场管理系统.docx(28页珍藏版)》请在冰点文库上搜索。

停车场管理系统.docx

停车场管理系统

数据结构项目课程报告

 

一、问题描述及分析

题目要求:

设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。

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

试为停车场编制按上述要求进行管理的模拟程序。

分析:

由题目只有一个大门进出并且“先到后处理”可知,应使构造栈模拟停车场,进入离开停车场即入栈出栈的过程;而便道等候的汽车符合“先到先处理”原则,应构造线性队列模拟;构造存储结构,存放车辆信息,车牌号,到达离开时间;通过time.h头文件中的函数获取汽车到来以及离开时间,利用时间差计算价钱。

主要模块如下图:

二、

功能模块及数据结构描述

头文件、宏定义以及存储结构

结构体定义相关类型的链表空间有顺序栈的定义、链队、车辆信息结构体、时间计算结构体、车辆位置字符型结构体数组和循环单链表存储下一个地址空间。

#include

#include

#include

#include

#include

#defineOK1

#defineERROR0

typedefstructtime1

{

chartimes[100];

longtime2;

}time1;

typedefstructnode

{

charnum[10];

time1reach;

time1leave;

}Car;

typedefstructStack

{

Car*stack[100];

inttop;

}SqStack;

typedefstructcar

{

Car*data;

structcar*next;

}QNode;

typedefstructNode

{

QNode*front;

QNode*rear;

}LinkQueue;

主函数

voidmain()

{

SqStackIn,Out;

LinkQueueWait;

intch;

intMAX;

floatprice;

printf("请输入停车场的容量:

");

scanf("%d",&MAX);

printf("请输入停车场的收费标准(元/小时):

");

scanf("%f",&price);

InitStack(&In,MAX);

InitStack(&Out,MAX);

InitQueue(&Wait);

while

(1)

{

system("color0A");

printf("=======欢迎使用停车场管理系统====================\n");

printf("输入的停车场容量为%d位,费用为%2.1f元/小时,请按任意键进入系统",MAX,price);

getchar();

system("CLS");

printf("=======欢迎使用停车场管理系统==================\n");

printf("您输入的停车场容量为%d位,费用为%2.1f元/小时。

\n",MAX,price);

printf("\n=========================\n");

printf("

(1)车辆到达\n

(2)车辆离开\n(3)停车场信息\n(4)退出系统\n请选择\n");

printf("\n===========================\n");

while

(1)

{

printf("请输入操作的序号");

scanf("%d",&ch);

switch(ch)

{

case1:

arrive(&In,&Wait,MAX,price);

break;

case2:

leave(&In,&Out,&Wait,MAX,price);

break;

case3:

info(In,Wait);

break;

case4:

{

system("CLS");

printf("\n============================\n");

printf("谢谢使用!

\n");

printf("\n=========================================\n");

exit(0);

}

default:

printf("\n按键无效,请重新按键选择");

getchar();

}

system("CLS");

printf("==========欢迎使用停车场管理系统=========\n");

printf("您输入的停车场容量为%d位,费用为%2.1f元/小时。

\n",MAX,price);

printf("\n========================================\n");

printf("

(1)车辆到达\n

(2)车辆离开\n(3)停车场信息\n(4)退出系统\n请选择\n");

printf("\n==========================================\n");

}

}

}

费用计算函数,通过时间差计算费用

voidprint(Car*p,introom,intMAX,floatprice)

{

time_trawtime;

structtm*timeinfo;

longA1,A2,B1,B2;

time(&rawtime);

timeinfo=localtime(&rawtime);

p->leave.time2=rawtime;

printf("\n车离开的时间为:

%s",asctime(timeinfo));

strcpy(p->leave.times,asctime(timeinfo));

printf("\n车牌号码:

");

puts(p->num);

printf("\n车到达的时间是:

%s",p->reach.times);

printf("\n车离开的时间是:

%s",p->leave.times);

A1=p->leave.time2;

A2=p->reach.time2;

B1=p->leave.time2-p->reach.time2;

if(B1<=3600&&B1>=0)

printf("\n费用为:

%2.1f元",price);

else

printf("\n费用为:

%2.1f元",B1/3600*price);

free(p);

}//消费计算函数

车辆到达函数,获取车辆信息,判断是否有车位,进行入栈或入队操作

intarrive(SqStack*In,LinkQueue*W,intMAX,floatprice)

{

Car*p;

QNode*t;

time_trawtime;

structtm*timeinfo;

//time(&rawtime);//获取时间,以秒计,从1970年1月一日起算,存于rawtime

//timeinfo=localtime(&rawtime);//转为当地时间,tm时间结构

//printf("当前系统时间:

%s",asctime(timeinfo));

//asctime(timeinfo);//转为标准ASCII时间格式:

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

printf("=====================欢迎使用停车场管理系统=====================\n");

printf("您输入的停车场容量为%d位,费用为%2.1f元/小时。

\n",MAX,price);

printf("停车场还有%d停车位,车可先进入便道等待",MAX-In->top);

printf("\n请输入车牌号码(例:

警A1035):

");

getchar();

scanf("%s",p->num);

getchar();

if(In->top

{

time(&rawtime);

p->reach.time2=rawtime;

timeinfo=localtime(&rawtime);

In->top++;

printf("停车的位置:

%d号停车位。

",In->top);

printf("\n车到达的时间为%s:

",asctime(timeinfo));

strcpy(p->reach.times,asctime(timeinfo));

In->stack[In->top]=p;

printf("请按任意键返回\n");

printf("\n==============================================\n");

getchar();

returnOK;

}

else

{

printf("=========欢迎使用停车场管理系统=================\n");

printf("您输入的停车场容量为%d位,费用为%2.1f元/小时。

\n",MAX,price);

printf("\n=========================================\n");

printf("停车位已满,该车须在便道等待!

");

t=(QNode*)malloc(sizeof(QNode));

t->data=p;

t->next=NULL;

W->rear->next=t;

W->rear=t;

printf("\n请按任意键返回");

getchar();

returnOK;

}

getchar();

}

车辆离开函数,如果是最前面的车离开,后面的车必须都进行出栈操作进入到另一个栈中让需要离开的车离开后再重新进入;如果便道有车那么便道的前面的车即先入队的车进行出队入栈

voidleave(SqStack*In,SqStack*Out,LinkQueue*W,intMAX,floatprice)

{

intplace;

Car*p,*t;

QNode*q;

time_trawtime;

structtm*timeinfo;

system("CLS");

if(In->top>0)

{

while

(1)

{

printf("========欢迎使用停车场管理系统==================\n");

printf("您输入的停车场容量为%d位,费用为%2.1f元/小时。

\n",MAX,price);

printf("\n===================================================\n");

printf("请输入车在停车场的位置(1-%d):

",In->top);

scanf("%d",&place);

if(place>=1&&place<=In->top)break;

}

while(In->top>place)

{

Out->top++;

Out->stack[Out->top]=In->stack[In->top];

In->stack[In->top]=NULL;

In->top--;

}

p=In->stack[In->top];

In->stack[In->top]=NULL;

In->top--;

while(Out->top>=1)

{

In->top++;

In->stack[In->top]=Out->stack[Out->top];

Out->stack[Out->top]=NULL;

Out->top--;

}

print(p,place,MAX,price);

if((W->front!

=W->rear)&&In->top

{

time(&rawtime);

timeinfo=localtime(&rawtime);

q=W->front->next;

t=q->data;

In->top++;

printf("\n便道的%s号车进入车场第%d号停车位。

",t->num,In->top);

printf("\n车到达的时间:

%s",asctime(timeinfo));

t->reach.time2=rawtime;

strcpy(t->reach.times,asctime(timeinfo));

W->front->next=q->next;

if(q==W->rear)W->rear=W->front;

In->stack[In->top]=t;

free(q);

}

}

else

printf("\n=================================================\n");

printf("停车场里没有车\n");

printf("\n请按任意键返回");

printf("\n\n===================================================\n");

getchar();

getchar();

}

停车场信息函数,遍历队列和栈能知道便道中和停车场中车辆信息

voidinfo1(SqStack*S)

{

inti;

if(S->top>0)

{

printf("\n停车场\n");

for(i=1;i<=S->top;i++)

{

printf("\n位置:

\n%d\n",i);

printf("到达时间:

\n%s车牌号:

\n%s\n",S->stack[i]->reach.times,S->stack[i]->num);

}

}

else

{

printf("\n=========================================\n");

printf("停车场里没有车");

}

}

voidinfo2(LinkQueue*W)

{

QNode*p;

p=W->front->next;

if(W->front!

=W->rear)

{

printf("\n便道中车辆的号码为:

\n");

while(p!

=NULL)

{

printf("%s\n",p->data->num);

p=p->next;

}

}

elseprintf("\n便道里没有车\n");

printf("\n请按任意键返回\n");

printf("\n\n==========================================\n");

getchar();

}

voidinfo(SqStackS,LinkQueueW)

{

system("CLS");

info1(&S);

info2(&W);

getchar();

}

队列和栈的初始化

voidInitStack(SqStack*s,intMAX)

{

inti;

s->top=0;

for(i=0;i<=MAX;i++)

s->stack[s->top]=NULL;

}

intInitQueue(LinkQueue*Q)

{

Q->front=(QNode*)malloc(sizeof(QNode));

if(Q->front!

=NULL)

{

Q->front->next=NULL;

Q->rear=Q->front;

returnOK;

}

elsereturnERROR;

}//队列和栈初始函数

三、主要算法流程描述及部分核心算法

流程描述

1.车辆到达停车场

其中车辆到达时需要用户输入车辆信息,接着要判断栈是否已满,如当前栈未满,则进行入栈操作,即车辆进入停车场;如果栈已满,则车辆必须进入便道等待。

2.车辆进入停车场

车辆进入,则进行入栈操作,即将车辆信息结点进行入栈操作。

3.车辆离开停车场

车辆的离开,则需要另设一个栈,给离去的汽车让路而从停车场退出来的汽车临时停放,也用顺序栈实现,车辆离开后需检查便道内是否有车辆等待,若有等待车辆则进行便道内的车辆进入停车场的操作,即将车辆信息结点进行入栈操作,输入当前时间后开始计费,最后进行出队操作,表示车辆已离开便道。

核心算法

车辆到达停车场

获取车辆到达时间

 

车辆进入停车场

车辆离开停车场

四、系统使用说明

运行环境为VC++6.0,如果需要在VS上运行需要改动scanf函数为scanf_s

运行截图

附:

源码

#include

#include

#include

#include

#include

#defineOK1

#defineERROR0

typedefstructtime1

{

chartimes[100];

longtime2;

}time1;

typedefstructnode

{

charnum[10];

time1reach;

time1leave;

}Car;

typedefstructStack

{

Car*stack[100];

inttop;

}SqStack;

typedefstructcar

{

Car*data;

structcar*next;

}QNode;

typedefstructNode

{

QNode*front;

QNode*rear;

}LinkQueue;

voidprint(Car*p,introom,intMAX,floatprice);

intarrive(SqStack*In,LinkQueue*W,intMAX,floatprice);

voidleave(SqStack*In,SqStack*Out,LinkQueue*W,intMAX,floatprice);

voidinfo1(SqStack*S);

voidinfo2(LinkQueue*W);

voidinfo(SqStackS,LinkQueueW);

voidInitStack(SqStack*s,intMAX);

intInitQueue(LinkQueue*Q);

 

voidmain()

{

SqStackIn,Out;

LinkQueueWait;

intch;

intMAX;

floatprice;

printf("请输入停车场的容量:

");

scanf("%d",&MAX);

printf("请输入停车场的收费标准(元/小时):

");

scanf("%f",&price);

InitStack(&In,MAX);

InitStack(&Out,MAX);

InitQueue(&Wait);

while

(1)

{

system("color0A");

printf("=======欢迎使用停车场管理系统====================\n");

printf("输入的停车场容量为%d位,费用为%2.1f元/小时,请按任意键进入系统",MAX,price);

getchar();

system("CLS");

printf("=======欢迎使用停车场管理系统==================\n");

printf("您输入的停车场容量为%d位,费用为%2.1f元/小时。

\n",MAX,price);

printf("\n=========================\n");

printf("

(1)车辆到达\n

(2)车辆离开\n(3)停车场信息\n(4)退出系统\n请选择\n");

printf("\n===========================\n");

while

(1)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2