数据结构课程设计c++版停车场管理系统Word格式文档下载.docx
- 文档编号:22332864
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:23
- 大小:260.41KB
数据结构课程设计c++版停车场管理系统Word格式文档下载.docx
《数据结构课程设计c++版停车场管理系统Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计c++版停车场管理系统Word格式文档下载.docx(23页珍藏版)》请在冰豆网上搜索。
#include〈iostream〉
#include〈conio.h>
#include〈iomanip〉
#include<
fstream>
string>
#include<
stdlib.h〉
#include<
windows.h>
usingnamespacestd;
#defineMax_Size2//停车的最大容量
#defineHourFare2//每小时的停车费用
intCountForStack=0;
//栈里现有的车数
intCountForQueue=0;
//排队等候的车数
typedefstruct
{
charCondition;
//到达或者离开的状态
intArrivetime;
//到达时间,默认为-1,表示没有到达
intLeavetime;
//离开时间,默认为-1,表示没有离开
intLicense;
//车牌号
}
CarNode;
//保存每辆车的信息
typedefstruct//栈的定义
{
CarNode*base;
//栈底指针
CarNode*top;
//栈顶指针
intStacksize;
//栈的最大容量
CarStack;
typedefstructQNode
charCondition;
//到达或者离开的状态
//到达时间,默认为—1,表示没有到达
intLeavetime;
//离开时间,默认为—1,表示没有离开
QNode*next;
QNode;
typedefstruct//队列的定义
{
QNode*front;
//对头指针
QNode*rear;
//队尾指针
Queue;
boolInitStack(CarStack&S1)//初始化栈S1
S1.base=(CarNode*)malloc(Max_Size*sizeof(CarNode));
if(!
S1。
base)
cout<
〈"
栈S1内存分配失败"
<
endl;
returnfalse;
}
S1.top=S1。
base;
S1。
Stacksize=Max_Size;
returntrue;
}
boolInitQueue(Queue&Q)
Q.front=(QNode*)malloc(sizeof(QNode));
Q。
front)
{
cout〈〈”队列Q内存分配失败!
”〈<
endl;
}
Q.rear=Q.front;
Q.front->
next=NULL;
boolEnQueue(Queue&Q,QNode&
e)//插入元素e为Q的新的队尾元素
QNode*p=(QNode*)malloc(sizeof(QNode));
p)
cout<
p内存分配失败”〈<
returnfalse;
p-〉Arrivetime=e。
Arrivetime;
p-〉Leavetime=e。
Leavetime;
p—>
Condition=e.Condition;
p->
License=e。
License;
//将e赋给P
p-〉next=NULL;
Q.rear->
next=p;
Q。
rear=p;
}
boolDeQueue(Queue&Q,QNode&t)//出队列函数
if(Q.front==Q.rear)
cout〈<
"
队列为空!
”〈〈endl;
QNode*p=Q。
front-〉next;
t.Arrivetime=p-〉Arrivetime;
t。
Condition=p->
Condition;
t.Leavetime=p->
Leavetime;
t.License=p—〉License;
front—〉next=p-〉next;
if(Q。
rear==p)
Q。
rear=Q.front;
free(p);
returntrue;
}
voidInitCarNode(CarNode&
C,charcondition,intarrivetime,intleavetime,intlicense)
C。
Arrivetime=arrivetime;
Condition=condition;
C.Leavetime=leavetime;
License=license;
boolPush(CarStack&S1,CarNode&car)//插入新的元素car为的栈顶元素
if(S1。
top—S1。
base>
=S1.Stacksize)
cout〈〈”此栈已满,不能压入新的信息”〈<
returnfalse;
(*S1.top)。
Arrivetime=car。
Arrivetime;
(*S1。
top)。
Condition=car.Condition;
(*S1。
top).Leavetime=car.Leavetime;
License=car.License;
++S1。
top;
//栈顶指针上移
boolPop(CarStack&
S1,CarNode&t)//出栈操作
if(S1.top==S1.base)
〈”栈S1为空,不能执行出栈操作"
—-S1.top;
//栈顶指针下移
t.Arrivetime=(*S1。
top).Arrivetime;
Condition=(*S1。
top).Condition;
Leavetime=(*S1。
License=(*S1。
License;
boolIsStackFull(CarStack&
S1)//判断S1栈是否已满
top—S1.base〉=S1。
Stacksize)
returntrue;
else
boolIsStackEmpty(CarStack&
S1)//判断S1栈是否已空
{
if(S1.top==S1.base)
else
boolIsQueueEmpty(Queue&Q)//判断队列是否为空
front==Q。
rear)
returntrue;
boolSearchInStack(CarStack&
S1,inta)//a表示要查找的车牌号,如果在停车场里面,就返回true
booltag=false;
IsStackEmpty(S1))//如果栈S1非空
CarNode*p=S1。
top-1;
while(p!
=S1。
{
if((*p)。
License==a)
tag=true;
——p;
}
if((*p).License==a)
tag=true;
}
returntag;
boolSearchInQueue(Queue&
Q,inta)//a表示要查找的车牌号,如果在通道里面,就返回true
if(!
IsQueueEmpty(Q))//如果队列非空
QNode*p=Q.front—>
next;
while(p!
=Q.rear)
if((*p).License==a)
tag=true;
p=p->
}//退出此while循环时p指向最后一个元素
License==a)
returntag;
voidInCar(CarStack&S1,Queue&
Q,inta1,inta2)//表示进入车辆,a1表示到达时间,a2表示车牌号码
if(SearchInStack(S1,a2))
”车号”〈<
a2<
已经存在于停车场内,输入有误”〈〈endl;
return;
if(SearchInQueue(Q,a2))
车号"
a2〈〈”已经存在于通道内,输入有误”〈〈endl;
if(IsStackFull(S1))//如果堆栈已满,说明停车场已满,需要停车在通道里面
QNodeqnode;
qnode.Arrivetime=-1;
//在通道里面不收费,所以不计时
qnode。
Condition='
A'
;
qnode.Leavetime=—1;
//定义为—1,说明还没有开始离开
License=a2;
EnQueue(Q,qnode);
//停在通道上
++CountForQueue;
车号:
”<
qnode.License〈〈”停在通道的第”〈<
CountForQueue〈〈"
号位置”<
CarNodecarnode;
carnode.Arrivetime=a1;
carnode。
Leavetime=-1;
Push(S1,carnode);
++CountForStack;
cout〈〈"
车号:
"
〈<
carnode.License<
,到达时间:
〈carnode.Arrivetime<
点,停在停车场的第”〈<
CountForStack<
号位置"
voidSreach(CarStack&S1,Queue&Q,inta)
if(SearchInStack(S1,a))
a〈〈”已存在停车场里面的第"
CountForStack〈〈”号位置"
〈endl;
if(SearchInQueue(Q,a))
{
cout<
”停车场已满,车号"
a<
”存在于通道里面的第"
CountForQueue〈<
”号位置,在次等候”<
return;
else
cout〈〈"
对不起!
你查找的车号不在停车场里面”〈<
return;
voidOutCar(CarStack&
S1,Queue&
Q,inta1,inta2)//出车函数,a1表示离开时间,a2表示车牌号码
if(SearchInQueue(Q,a2))
车号”<
〈a2〈〈”存在于通道里面,还没有进入停车场,不能离开"
SearchInStack(S1,a2))
”车号"
a2〈〈”该车不在停车场内"
return;
CarStacktempstack;
InitStack(tempstack);
//新建一个栈,存放让路的汽车
booltag1=false;
//标志这个停车场出车以前是否已满,默认为没有满
tag1=IsStackFull(S1);
booltag2=true;
//标志通道是否有汽车在等待,默认为通道为空
tag2=IsQueueEmpty(Q);
CarNodetemp;
//用来保存暂时取出的汽车
booltag3=false;
while
(1)
Pop(S1,temp);
if(temp.License==a2)
if(a1〈temp.Arrivetime)
{
cout<
”离开失败!
tag3=true;
Push(tempstack,temp);
}
else
”〈〈a2〈<
现在离开停车场,所用时间为:
”<
a1-temp。
Arrivetime〈〈"
小时,应收RMB为:
(a1-temp.Arrivetime)*HourFare<
”元”<
}
break;
Push(tempstack,temp);
//进入暂存栈}则把前面倒出的车再次放
while(!
IsStackEmpty(tempstack))//如果临时栈不空,入停车场
{
Pop(tempstack,temp);
Push(S1,temp);
}
QNodetempqnode;
//用来暂时保存从通道出来的汽车
if(tag1==true&
&tag2==false&
&tag3==false)//如果出车前停车场已满,并且通道不为空,并且离开没有失败
DeQueue(Q,tempqnode);
—-CountForQueue;
temp。
Arrivetime=a1;
Condition=tempqnode。
Leavetime=tempqnode.Leavetime;
temp.License=tempqnode。
Push(S1,temp);
if(tag3==false)//如果停车通道是空的,停车场没有满,并且离开成功
—-CountForStack;
voidshowmenu(CarStack&S1,Queue&
Q)
cout〈<
”******************************选择菜单*******************************”<
”1:
停车"
2:
离开停车场”〈<
”3:
查看车辆信息"
〈endl;
4:
退出系统”〈〈endl;
”*****************************请按键选择******************************"
inttag;
cin〉〉tag;
while(tag!
=1&
&
tag!
=2&
=3&
tag!
=4)
cin>
>
tag;
inta1;
unsignedinta2;
switch(tag)
case1:
”请输入到达的车号:
〈〈endl;
cin〉>
a1;
请输入到达的时间:
cin〉〉a2;
InCar(S1,Q,a2,a1);
Sreach(S1,Q,a1);
break;
case2:
cout〈〈"
请输入离开的车号:
”〈〈endl;
cout〈〈”请输入离开的时间:
cin〉〉a2;
OutCar(S1,Q,a2,a1);
case3:
”请输入你要查看的车号:
Sreach(S1,Q,a1);
break;
case4:
showmenu(S1,Q);
voidloging(CarStack&S1,Queue&Q)
{
charAdministrator[15],password[15];
inta;
printf(”\t*****************************************************\n"
);
printf(”\t*****************************************************\n"
);
printf(”\t****\n"
printf("
\t**欢迎使用停车场管理系统**\n”);
printf(”\t****\n”);
printf(”\t*****************************************************\n"
printf(”\t*****************************************************\n”);
printf(”\n\t(提示:
账号跟密码一样就行)"
printf(”\n\n\n\n\t请输入管理员帐号:
fflush(stdin);
gets(Administrator);
printf(”\t\t\t\t\t\t\t\t\t\t\t请输入密码:
fflush(stdin);
gets(password);
//比较用户名和密码
if(strcmp(Administrator,Administrator)==0&
&strcmp(password,Administrator)==0)
printf(”\n\n\t\t\t您已成功登陆,请稍侯!
\n\n\t\t\t"
//延迟
for(a=0;
a〈20;
a++)
printf(”〉”);
Sleep(150);
//进入页面时清屏
system("
cls"
showmenu(S1,Q);
printf(”\n\n\t\t\t您输入的帐号或者密码错误!
\n\n\t\t\t”);
voidmain()
CarStackcarstack;
InitStack(carstack);
//建立并且初始化用于停车场的堆栈
QueuecarQueue;
InitQueue(carQueue);
//建立并且初始化用于通道的队列
loging(carstack,carQueue);
}
五、心的体会
在生活与工作中许多领域都用到数据结构,但关键是如何将问题模型转换,变换成我们熟知的知识应用,即抽象具体化。
首先是要把所学的知识重新好好巩固下,其次,每次课程设计总会有些东西不懂的,这时我们就要上网去查资料,这样会让我们养成一个好的自主学习的习惯.这次的课程设计,我开始是分析了这个系统需要做些什么,然后分析要用到哪些代码,哪些结构,哪些算法开实现这些功能。
它让我明白了栈和队列实际会用在哪些方面,同时我有些不懂的,我会看书,或是在网上找,慢慢的也增加了自己的知识量。
这次的停车场系统做的很简单,和真正的停车场系统来比,根本就不算什么了。
真正的停车场是不会那么退出停车场的,每次离开都要人家
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 课程设计 c+ 停车场 管理 系统