2022年数据结构课程方案设计书--停车场管理系统.docx
精选学习资料 - - - - - - - - - 数据结构课程设计班 级 网络营销指导老师 吕向阳学 号 1040412123 姓 名 魏华二 012 年 1 月 7 日名师归纳总结 - - - - - - -第 1 页,共 16 页精选学习资料 - - - - - - - - - 一课程设计题目某停车场内只有一个可停放n 辆汽车的狭长通道,且只有一个大门可供汽车进出;汽车在停车场内按车辆到达时间的先后次序,依次由北向南排列(大 门在最南端,最先到达的第一辆汽车停放在最北端),如停车场内已经停满 n 辆车,就后来的汽车只能在门外的便道即候车场上等候,一旦有车开走,就排在便道上的第一辆车即可开入;当停车场内某辆车要离开时;在它之后进入的车辆必需先退出车场为它让路,该车辆开出大门外,其它车辆再按原次序进入停车场,每辆停放在车场的车在它离开停车场时必需按它停留的时间长短交纳费用;试为该停车场编制按上述要求进行治理的模拟程序;二流程及图示停车 显示信息离开 收费系统查询 显示信息退出名师归纳总结 - - - - - - -第 2 页,共 16 页精选学习资料 - - - - - - - - - a 1 a 2 a 3 a n 停 车场(栈 1)栈 2通道(队列)三、程序运行及截图1.开头界面第一是登陆界面,只要用户名跟密码一样就可以登陆,输入正确后,有一个推迟程序,让使用者感觉更真实名师归纳总结 - - - - - - -第 3 页,共 16 页精选学习资料 - - - - - - - - - 假如输入错误了,就是直接退出了2.主界面 登录胜利后,就是如下的功能界面:3 . 停车场治理系统 你可以挑选停车,离开,或者查看,当操作完了,可以直接挑选退名师归纳总结 出; 当你输入1 后,会提示你输入停车的车号:在这里输入你想要停车的车号,然后会第 4 页,共 16 页提示你停车的时间:输入停车时间后,就会显示你刚停车的具体的信息:- - - - - - -精选学习资料 - - - - - - - - - 4.离开 输入 2 ,就会提示你要离开的车号:然后输入离开的车号后,会提示你输入该车离开的时间,输入离开的时间,就 会显现如下界面:5 停车场治理系统 系统就会把你刚离开的车俩的具体信息给你打印出来:拉开的车号,所用时间 以及应收的费用;这个时间治理员,可以对比表收费了;名师归纳总结 - - - - - - -第 5 页,共 16 页精选学习资料 - - - - - - - - - 6.查看 当你要查看停车场所停车的信息时,你可以挑选 3 ;同样,挑选 3 确定后会提示你要查看的车号,然后就会把信息打印在界面上:位置上;系统会告知你这俩停在停车场里面的那个7.退出 当你一切操作完了后,就可以挑选退出了,输入 4 停车场治理系统任凭按个键就退出该系统了;四、程序代码#include<iostream> #include<conio.h> #include<iomanip> #include<fstream> #include<string> #include <stdlib.h> #include <windows.h> using namespace std;#define Max_Size 2/ 停车的最大容量 #define HourFare 2 / 每小时的停车费用 int CountForStack=0; / 栈里现有的车数 int CountForQueue=0 ; / 排队等候的车数 typedef struct char Condition ;/ 到达或者离开的状态-1,表示没有到达 int Arrivetime ;/ 到达时间,默认为 int Leavetime;/ 离开时间,默认为-1,表示没有离开 int License;/ 车牌号 CarNode;/ 储存每辆车的信息 typedef struct/ 栈的定义 CarNode *base; / 栈底指针 CarNode *top ;/ 栈顶指针 int Stacksize;/ 栈的最大容量 CarStack; typedef struct QNode char Condition ;/ 到达或者离开的状态 int Arrivetime ;/ 到达时间,默认为-1,表示没有到达 int Leavetime;/ 离开时间,默认为-1,表示没有离开 int License;/ 车牌号 QNode *next ; QNode;typedef struct/ 队列的定义名师归纳总结 - - - - - - -第 6 页,共 16 页精选学习资料 - - - - - - - - - QNode *front ;/ 对头指针 QNode * rear ;/ 队尾指针 Queue; bool InitStackCarStack &S1/ 初始化栈 S1 S1.base=CarNode*mallocMax_Size*sizeofCarNode ; if.S1.base cout<<" 栈 S1 内存安排失败 "<<endl; return false ; S1.top=S1.base; S1.Stacksize=Max_Size; return true ; bool InitQueueQueue &Q Q.front=QNode*mallocsizeofQNode ; if.Q.front cout<<"队列 Q 内存安排失败!"<<endl ; return false; Q.rear=Q.front; Q.front->next=NULL; return true ; bool EnQueueQueue &Q,QNode &e/ 插入元素 e 为 Q 的新的队尾元素 QNode *p=QNode *mallocsizeofQNode ; if.p cout<<"p 内存安排失败 "<<endl ; return false; 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;名师归纳总结 - - - - - - -第 7 页,共 16 页精选学习资料 - - - - - - - - - return true ; bool DeQueueQueue &Q,QNode &t/ 出队列函数 ifQ.front=Q.rear cout<<" 队列为空! "<<endl; return false; QNode *p=Q.front->next ; t.Arrivetime=p->Arrivetime ; t.Condition=p->Condition ; t.Leavetime=p->Leavetime ; t.License=p->License; Q.front->next=p->next ; ifQ.rear=p Q.rear=Q.front ; freep ; return true ; void InitCarNodeCarNode &C,char condition,int arrivetime,int leavetime,int license C.Arrivetime=arrivetime ;C.Condition=condition ;C.Leavetime=leavetime;C.License=license; bool PushCarStack &S1,CarNode &car/ 插入新的元素 car 为的栈顶元素 ifS1.top-S1.base>=S1.Stacksize cout<<" 此栈已满,不能压入新的信息 "<<endl ; return false ; *S1.top.Arrivetime=car.Arrivetime ; *S1.top.Condition=car.Condition ; *S1.top.Leavetime=car.Leavetime ; *S1.top.License=car.License; +S1.top;/ 栈顶指针上移 return true ; bool PopCarStack &S1,CarNode &t/ 出栈操作名师归纳总结 - - - - - - -第 8 页,共 16 页精选学习资料 - - - - - - - - - ifS1.top=S1.base cout<<" 栈 S1 为空,不能执行出栈操作 "<<endl ; return false; -S1.top;/ 栈顶指针下移 t.Arrivetime=*S1.top.Arrivetime; t.Condition=*S1.top.Condition ; t.Leavetime=*S1.top.Leavetime ; t.License=*S1.top.License; return true ; bool IsStackFullCarStack &S1/判定 S1 栈是否已满 ifS1.top-S1.base>=S1.Stacksize return true ; else return false ; bool IsStackEmptyCarStack &S1/判定 S1 栈是否已空 ifS1.top=S1.base return true ; else return false ; bool IsQueueEmptyQueue &Q/ 判定队列是否为空 ifQ.front=Q.rear return true ; else return false ; bool SearchInStackCarStack &S1,int a/a 表示要查找的车牌号,假如在停车场里 面,就返 回 true bool tag=false; if.IsStackEmptyS1/ 假如栈 S1 非空 CarNode *p=S1.top-1; whilep.=S1.base if*p.License=a 名师归纳总结 - - - - - - -第 9 页,共 16 页精选学习资料 - - - - - - - - - tag=true ; -p; if*p.License=a tag=true ; return tag ; bool SearchInQueueQueue &Q,int a/a 表示要查找的车牌号,假如在通道里面,就返回 true bool tag=false; if.IsQueueEmptyQ/ 假如队列非空 QNode *p=Q.front->next ; whilep.=Q.rear if*p.License =a tag=true; p=p->next; / 退出此 while 循环时 p 指向最终一个元素 if*p.License =a tag=true ; return tag ; void InCarCarStack &S1,Queue &Q,int a1,int a2/表示进入车辆 ,a1 表示到达时间,a2 表示车牌号码 ifSearchInStackS1,a2 cout<<" 车号 "<<a2<<" 已经存在于停车场内,输入有误 "<<endl ; return ; ifSearchInQueueQ,a2 cout<<" 车号 "<<a2<<" 已经存在于通道内,输入有误 "<<endl; return ; ifIsStackFullS1/ 假如堆栈已满,说明停车场已满,需要停车在通道里面 QNode qnode ; qnode.Arrivetime=-1 ;/ 在通道里面不收费,所以不计时 qnode.Condition='A' ; qnode.Leavetime=-1 ;/ 定义为 -1,说明仍没有开头离开名师归纳总结 - - - - - - -第 10 页,共 16 页精选学习资料 - - - - - - - - - qnode.License=a2; EnQueueQ,qnode ;/ 停在通道上 +CountForQueue;置"<<endl ; cout<<" 车号 :"<<qnode.License<<" 停在通道的第 "<<CountForQueue<<" 号 位 else CarNode carnode; carnode.Arrivetime=a1 ; carnode.Condition='A' ; carnode.Leavetime=-1 ; carnode.License=a2; PushS1,carnode; +CountForStack;cout<<" 车号:"<<carnode.License<<" , 到达时间 :"<<carnode.Arrivetime<<" 点,停在停车场的第 "<<CountForStack<<"号位置 "<<endl ; void SreachCarStack &S1,Queue &Q,int a ifSearchInStackS1,a cout<<" 车号: "<<a<<"已存在停车场里面的第"<<CountForStack<<"号位置"<<endl ; return ; ifSearchInQueueQ,a cout<<" 停 车 场 已 满 , 车 号 "<<a<<" 存 在 于 通 道 里 面 的 第 "<<CountForQueue<<" 号位置,在次等候 "<<endl ; return ; else cout<<" 对不起 .你查找的车号不在停车场里面 "<<endl; return ; void OutCarCarStack &S1,Queue &Q,int a1,int a2/出车函数, a1 表示离开时间, a2 表示车牌号码 ifSearchInQueueQ,a2 名师归纳总结 - - - - - - -第 11 页,共 16 页精选学习资料 - - - - - - - - - cout<<" 车 号 "<<a2<<" 存 在 于 通 道 里 面 , 仍 没 有 进 入 停 车 场 , 不 能 离 开 "<<endl ; return ; if.SearchInStackS1,a2 cout<<" 车号 "<<a2<<" 该车不在停车场内 "<<endl ; return; CarStack tempstack; InitStacktempstack ;/ 新建一个栈,存放让路的汽车 bool tag1=false ;/ 标志这个停车场出车以前是否已满,默认为没有满 tag1=IsStackFullS1; bool tag2=true ; / 标志通道是否有汽车在等待,默认为通道为空 tag2=IsQueueEmptyQ; CarNode temp ;/ 用来储存临时取出的汽车 bool tag3=false ; while1 PopS1,temp; iftemp.License=a2 ifa1<temp.Arrivetime cout<<" 离开失败! "<<endl; tag3=true ; Pushtempstack,temp ; else cout<<" 车号: "<<a2<<" 现在离开停车场,所用时间为:"<<a1-temp.Arrivetime<<"小 时 , 应 收RMB 为 :"<<a1-temp.Arrivetime*HourFare<<"元"<<endl ; break; else Pushtempstack,temp ;/ 进入暂存栈 就把前面倒出的车再次放 while.IsStackEmptytempstack/ 假如临时栈不空,入停车场 Poptempstack,temp ; PushS1,temp; QNode tempqnode;/ 用来临时储存从通道出来的汽车名师归纳总结 - - - - - - -第 12 页,共 16 页精选学习资料 - - - - - - - - - iftag1=true&&tag2=false&&tag3=false/假如出车前停车场已满,并且通道不为空,并且离开没有失败 DeQueueQ,tempqnode ; -CountForQueue ; temp.Arrivetime=a1 ; temp.Condition=tempqnode.Condition ; temp.Leavetime=tempqnode.Leavetime ; temp.License=tempqnode.License; PushS1,temp; iftag3=false/ 假如停车通道是空的,停车场没有满,并且离开胜利 -CountForStack; void showmenuCarStack &S1,Queue &Q cout<<"*;选择菜单*"<<endl cout<<" 1: 停车 "<<endl ; cout<<" 2: 离开停车场 "<<endl ; cout<<" 3: 查看车辆信息 "<<endl ; cout<<" 4: 退出系统 "<<endl ; cout<<"*;请按键选择*"<<endl int tag; cin>>tag; whiletag.=1&&tag.=2&&tag.=3&&tag.=4 cin>>tag; int a1; unsigned int a2;switchtag case 1: cout<<" 请输入到达的车号:"<<endl ; cin>>a1; cout<<" 请输入到达的时间:"<<endl ; cin>>a2; InCarS1,Q,a2,a1; SreachS1,Q,a1; break; case 2: 名师归纳总结 - - - - - - -第 13 页,共 16 页精选学习资料 - - - - - - - - - cout<<"请输入离开的车号:"<<endl; cin>>a1; cout<<"请输入离开的时间:"<<endl; cin>>a2; OutCarS1,Q,a2,a1; break; case 3: "<<endl; cout<<" 请输入你要查看的车号: cin>>a1; SreachS1,Q,a1; break; case 4: return ; break; showmenuS1,Q; void logingCarStack &S1,Queue &Q char Administrator15,password15; int a;printf"t*n";printf"t*n"; printf"t* *n" ; printf"t* 欢迎使用停车场治理系统 *n" ; printf"t* *n" ; printf"t* *n" ; printf"t*n"; printf"t*n" printf"nt 提示:账号跟密码一样就行 "; printf"nnnnt 请输入治理员帐号 :" ; fflushstdin ; getsAdministrator ; printf"ttttttttttt 请输入密码 :"; fflushstdin; getspassword; / 比较用户名和密码 ifstrcmpAdministrator,Administrator = 0 && strcmppassword,Administrator = 0 printf"nnttt 您已胜利登陆 ,请稍侯 .nnttt"; / 推迟 fora = 0;a<20;a+ printf">" ; Sleep150;名师归纳总结 - - - - - - -第 14 页,共 16 页精选学习资料 - - - - - - - - - /进入页面时清屏 system"cls"; showmenuS1,Q; else printf"nnttt 您输入的帐号或者密码错误.nnttt"; return; void main CarStack carstack; InitStackcarstack;/ 建立并且初始化用于停车场的堆栈 Queue carQueue; InitQueuecarQueue ; / 建立并且初始化用于通道的队列 logingcarstack,carQueue; 五、心的体会在生活与工作中很多领域都用到数据结构,但关键是如何将问题模型转换,变 换成我们熟知的学问应用,即抽象具体化;第一是要把所学的学问重新好 好巩 固下,其次,每次课程设计总会有些东西不懂的,这时我们就要上网去查资 料,这样会让我们养成一个好的自主学习的习惯;这次的课程设计,我开头是 分 析了这个系统需要做些什么,然后分析要用到哪些代码,哪些结构,哪些算法开 实现这些功能;它让我明白了栈和队列实际会用在哪些方面,同时我有些不懂的,我会看书,或是在网上找,渐渐的也增 加了自己的学问量;这次的停车场系统做的很简洁,和真正的停车场系统来比,根本就不算什么 了;真正的停车场是不会那么退出停车场的,每次离开都要人家后面的让道,仍不被人骂么?不过这次只是一次小小的试手,更难得仍在后面,因此我们也需不断学习充实自己;六、参考资料 Visual c+ 程序设计数据结构( c+版)名师归纳总结 - - - - - - -第 15 页,共 16 页精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 16 页,共 16 页