数据结构项目课程报告停车场管理系统Word格式.docx
《数据结构项目课程报告停车场管理系统Word格式.docx》由会员分享,可在线阅读,更多相关《数据结构项目课程报告停车场管理系统Word格式.docx(28页珍藏版)》请在冰豆网上搜索。
}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);
请输入停车场的收费标准(元/小时):
%f"
price);
InitStack(&
In,MAX);
Out,MAX);
InitQueue(&
Wait);
while
(1)
{
system("
color0A"
printf("
=======欢迎使用停车场管理系统====================\n"
输入的停车场容量为%d位,费用为%2.1f元/小时,请按任意键进入系统"
MAX,price);
getchar();
CLS"
=======欢迎使用停车场管理系统==================\n"
您输入的停车场容量为%d位,费用为%2.1f元/小时。
\n"
\n=========================\n"
(1)车辆到达\n
(2)车辆离开\n(3)停车场信息\n(4)退出系统\n请选择\n"
\n===========================\n"
while
(1)
{
printf("
请输入操作的序号"
scanf("
ch);
switch(ch)
{
case1:
arrive(&
In,&
Wait,MAX,price);
break;
case2:
leave(&
Out,&
case3:
info(In,Wait);
case4:
system("
printf("
\n============================\n"
printf("
谢谢使用!
\n=========================================\n"
exit(0);
}
default:
printf("
\n按键无效,请重新按键选择"
getchar();
system("
==========欢迎使用停车场管理系统=========\n"
\n========================================\n"
\n==========================================\n"
}
}
}
费用计算函数,通过时间差计算费用
voidprint(Car*p,introom,intMAX,floatprice)
time_trawtime;
structtm*timeinfo;
longA1,A2,B1,B2;
time(&
rawtime);
timeinfo=localtime(&
p->
leave.time2=rawtime;
\n车离开的时间为:
%s"
asctime(timeinfo));
strcpy(p->
leave.times,asctime(timeinfo));
\n车牌号码:
puts(p->
num);
\n车到达的时间是:
%s"
p->
reach.times);
\n车离开的时间是:
leave.times);
A1=p->
leave.time2;
A2=p->
reach.time2;
B1=p->
leave.time2-p->
if(B1<
=3600&
&
B1>
=0)
\n费用为:
%2.1f元"
price);
else
B1/3600*price);
free(p);
}//消费计算函数
车辆到达函数,获取车辆信息,判断是否有车位,进行入栈或入队操作
intarrive(SqStack*In,LinkQueue*W,intMAX,floatprice)
Car*p;
QNode*t;
//time(&
//获取时间,以秒计,从1970年1月一日起算,存于rawtime
//timeinfo=localtime(&
//转为当地时间,tm时间结构
//printf("
当前系统时间:
%s"
asctime(timeinfo));
//asctime(timeinfo);
//转为标准ASCII时间格式:
p=(Car*)malloc(sizeof(Car));
=====================欢迎使用停车场管理系统=====================\n"
停车场还有%d停车位,车可先进入便道等待"
MAX-In->
top);
\n请输入车牌号码(例:
警A1035):
getchar();
%s"
if(In->
top<
MAX)
time(&
p->
reach.time2=rawtime;
timeinfo=localtime(&
In->
top++;
停车的位置:
%d号停车位。
In->
\n车到达的时间为%s:
"
strcpy(p->
reach.times,asctime(timeinfo));
stack[In->
top]=p;
请按任意键返回\n"
\n==============================================\n"
returnOK;
=========欢迎使用停车场管理系统=================\n"
停车位已满,该车须在便道等待!
t=(QNode*)malloc(sizeof(QNode));
t->
data=p;
next=NULL;
W->
rear->
next=t;
rear=t;
\n请按任意键返回"
车辆离开函数,如果是最前面的车离开,后面的车必须都进行出栈操作进入到另一个栈中让需要离开的车离开后再重新进入;
如果便道有车那么便道的前面的车即先入队的车进行出队入栈
voidleave(SqStack*In,SqStack*Out,LinkQueue*W,intMAX,floatprice)
intplace;
Car*p,*t;
QNode*q;
system("
top>
0)
========欢迎使用停车场管理系统==================\n"
\n===================================================\n"
请输入车在停车场的位置(1-%d):
place);
if(place>
=1&
place<
=In->
top)break;
while(In->
place)
Out->
stack[Out->
top]=In->
top];
In->
top]=NULL;
top--;
p=In->
while(Out->
top>
=1)
top]=Out->
print(p,place,MAX,price);
if((W->
front!
=W->
rear)&
In->
top<
MAX)
time(&
timeinfo=localtime(&
q=W->
front->
next;
t=q->
data;
\n便道的%s号车进入车场第%d号停车位。
t->
num,In->
\n车到达的时间:
t->
strcpy(t->
W->
next=q->
if(q==W->
rear)W->
rear=W->
front;
top]=t;
free(q);
\n=================================================\n"
停车场里没有车\n"
\n\n===================================================\n"
停车场信息函数,遍历队列和栈能知道便道中和停车场中车辆信息
voidinfo1(SqStack*S)
inti;
if(S->
\n停车场\n"
for(i=1;
i<
=S->
top;
i++)
\n位置:
\n%d\n"
i);
到达时间:
\n%s车牌号:
\n%s\n"
S->
stack[i]->
reach.times,S->
停车场里没有车"
voidinfo2(LinkQueue*W)
QNode*p;
p=W->
if(W->
rear)
\n便道中车辆的号码为:
while(p!
=NULL)
%s\n"
data->
p=p->
elseprintf("
\n便道里没有车\n"
\n请按任意键返回\n"
\n\n==========================================\n"
voidinfo(SqStackS,LinkQueueW)
info1(&
S);
info2(&
W);
队列和栈的初始化
voidInitStack(SqStack*s,intMAX)
s->
top=0;
for(i=0;
=MAX;
s->
stack[s->
intInitQueue(LinkQueue*Q)
Q->
front=(QNode*)malloc(sizeof(QNode));
if(Q->
Q->
rear=Q->
elsereturnERROR;
}//队列和栈初始函数
三、主要算法流程描述及部分核心算法
流程描述
1.车辆到达停车场
其中车辆到达时需要用户输入车辆信息,接着要判断栈是否已满,如当前栈未满,则进行入栈操作,即车辆进入停车场;
如果栈已满,则车辆必须进入便道等待。
2.车辆进入停车场
车辆进入,则进行入栈操作,即将车辆信息结点进行入栈操作。
3.车辆离开停车场
车辆的离开,则需要另设一个栈,给离去的汽车让路而从停车场退出来的汽车临时停放,也用顺序栈实现,车辆离开后需检查便道内是否有车辆等待,若有等待车辆则进行便道内的车辆进入停车场的操作,即将车辆信息结点进行入栈操作,输入当前时间后开始计费,最后进行出队操作,表示车辆已离开便道。
核心算法
车辆到达停车场
获取车辆到达时间
是
车辆进入停车场
车辆离开停车场
四、系统使用说明
运行环境为VC++6.0,如果需要在VS上运行需要改动scanf函数为scanf_s
运行截图
附:
源码
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);