《停车场管理系统设计报告.docx》由会员分享,可在线阅读,更多相关《停车场管理系统设计报告.docx(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、数据结构课程设计报告1、 需求分析在停车场管理中,往往涉及到计费的问题,记录每个车辆的【进出时间】,以及根据特定的【收费标准】来计算费用,是停车场管理的关键所在。在此基础之上,引导用户【设置收费标准】以及【设置停车场、便道大小】是广泛适用于任何停车场的必要前提。(已实现)用户的不同,导致所给权限不同。管理者只需记录进出车辆即可,而负责人需要根据需要调整收费标准,给这两种人不同的权限与界面也一定程度上让系统更加广泛的使用与任何停车场。(未实现)为保护数据安全,也可增加操作日志。(未实现)2、 概要设计2.1 栈的抽象数据类型定义(模板类-链式)template class Elementpubl
2、ic:Element();/构造函数Element(Type Goal);/重载构造函数,定义栈的大小public:Type Value;/保存数值Element *Top;/栈顶指针Element *Prior;/由栈顶指向下一个template class Stackpublic:Stack(int Max_Size_Value = 300000);/构造函数,默认栈的大小为300000inline bool push(Type Goal);/入栈inline Type top();/取出栈顶元素inline bool pop();/出栈inline int size();/栈中元素个数i
3、nline bool resize(int Num);/重置栈的空间inline bool clear();/清空栈inline bool empty();/判断是否为空,为空返回trueprivate:Element *Head;/头指针,保护数据不被修改int Now_Size;/当前栈中元素个数int Max_Size;/栈的最大存储空间2.2 队列的抽象数据类型定义(模板类-链式)template class Element public:Element();/构造函数Element(Type Goal);/重载构造函数,定义栈的大小public:Type Value;/保存数值Ele
4、ment *Front;/指向队头元素Element *Tail;/指向队尾元素Element *Prior;/每个元素的前驱指针Element *Next;/每个元素的后继指针template class Queuepublic:Queue(int Max_Size_Value=300000);/构造函数,默认队列大小为300000inline bool push(Type Goal);/入队inline bool pop();/出队inline bool connect();/循环队列连接,头尾相连inline bool disconnect();/将头尾断开,循环队列变为单队列inlin
5、e Type front();/取出队头元素inline Type back();/取出队尾元素inline bool empty();/判断是否为空,为空返回trueinline int size();/队列中元素个数private:Element *Head;/头指针,保护数据不被修改int Now_Size;/当前队列中元素个数int Max_Size;/队列的最大存储空间bool JudgeConnect;/循环队列判断标记,为循环队列时,值为true2.3 主要功能调用(Main函数)int main()Initialization();/初始化,加载外部数据Print_Help()
6、;/在屏幕上打印“帮助文件”while (true)string Command;cout Command;/命令行if (Command = Help) Print_Help();else if (Command = Now) Get_NowTime();else if (Command = Getinfo) Get_Infomation();else if (Command = I | Command = i) InPutStorage();else if (Command = O | Command = o) OutPutStorage();else if (Command = SetM
7、oney) Set_Money_Index();else if (Command = SetTime) Set_Time_Index();else if (Command = SetCarStorage) Set_Storage_Index();else if (Command = SetCarRoad) Set_Road_Index();else if (Command = Save) Save_Infomation();else if (Command = End)Exit();break;elsecout 命令无法识别,请重新输入。 endl;return 0;PS:具体帮助文档内容,见
8、附录 图 1 。2.4 所需数组与函数列表(定义)int Money_Index3;/收费标准档次int Time_Index2;/时间分段int Storage_Index;/停车场最大容量int Road_Index;/便道最大容量bool OutPutToTxt = false;/输出到文件标记,当值为true时,将不在控制台中输出内容。Stack CarStorage(Storage_Index);/停车场内车辆数据Stack CarRoad(Road_Index);/便道内车辆数据void Initialization();/初始化void Print_Help();/打印帮助文档v
9、oid Get_NowTime();/获取当前系统时间void Get_Infomation();/获取所有信息void Get_StorageInfomation();/获取停车场信息void Get_RoadInfomation();/获取便道信息void InPutStorage();/进入停车场void OutPutStorage();/离开停车场void InPutRoad();/进入便道void OutPutRoad(string Goal);/离开便道time_t Set_NowTime();/设置当前时间CarInfo UpData_Now_Money(CarInfo &Goa
10、l);/更新当前费用CarInfo UpData_StorageNum(CarInfo &Goal);/更新停车场序号CarInfo UpData_RoadNum(CarInfo &Goal);/更新便道序号void UpData_Index();/更新收费标准void Set_Money_Index();/设置收费标准中的费用void Set_Time_Index();/设置收费标准中的时间段void Set_Storage_Index();/设置停车场存放车辆的数量void Set_Road_Index();/设置便道存放车辆的数量void Save_Infomation();/保存数据到
11、D盘根目录void RoadToStorage();/便道车辆进入停车场bool Rechecking(string Goal);/重复车牌检查void Exit();/退出系统2.5 函数关系调用图PS:上图中,有四个更新数据函数为指出,具体关系见下表。UpData_Now_Money();UpData_StorageNUm();UpData_RoadNum();UpData_Index();Get_Infomation();Get_StorageInfomation();Get_RoadInfomation();Set_Money_Index();Set_Time_Index();Set_
12、Storage_Index();Set_Road_Index();3、 详细设计3.1 链式栈的实现template Element:Element()Top = NULL;Prior = NULL;template Element:Element(Type Goal)Value = Goal;Top = NULL;Prior = NULL;template Stack:Stack(int Max_Size_Value = 300000)Head = new Element();Type *Top = NULL;Type *Prior = NULL;Now_Size = 0;Max_Size
13、= Max_Size_Value;template inline bool Stack:push(Type Goal)if (Now_Size = Max_Size) return false;Element *NewElement = new Element(Goal);NewElement-Prior = Head-Top;Head-Top = NewElement;Now_Size+;return true;template inline Type Stack:top()return Head-Top-Value;template inline bool Stack:pop()if (N
14、ow_Size = 0) return false;Element *Transcript = Head-Top;Head-Top = Head-Top-Prior;delete Transcript;Now_Size-;return true;template inline int Stack:size()return Now_Size;templateinline bool Stack:resize(int Num)Max_Size=Num;return true;template inline bool Stack:empty()if (Now_Size = 0) return true
15、;return false;template inline bool Stack:clear()if (empty() = true) return false;while (size() != 0) pop();return false;3.2 链式队列的实现template Element:Element()Front=NULL;Tail=NULL;Prior=NULL;Next=NULL;template Element:Element(Type Goal)Value=Goal;Front=NULL;Tail=NULL;Prior=NULL;Next=NULL;template Queu
16、e:Queue(int Max_Size_Value=300000)Now_Size=0;Max_Size=Max_Size_Value;Head=new Element();JudgeConnect=false;template inline bool Queue:push(Type Goal)Element *NewElement=new Element(Goal);if(Now_Size=Max_Size) delete NewElement;return false;else if(Now_Size=0) Head-Front=NewElement;elseNewElement-Pri
17、or=Head-Tail;Head-Tail-Next=NewElement;Head-Tail=NewElement;Now_Size+;return true;template inline bool Queue:pop()Element *Transcript;if(size()=0) delete Transcript;return false;else Transcript=Head-Front;Head-Front=Head-Front-Next;if(JudgeConnect=false)Head-Front-Prior=NULL;elseHead-Front-Prior=Hea
18、d-Tail;Head-Tail-Next=Head-Front;delete Transcript;template inline bool Queue:connect()if(JudgeConnect=true) return false;JudgeConnect=true;Head-Front-Prior=Head-Tail;Head-Tail-Next=Head-Front;return true;template inline bool Queue:disconnect()if(JudgeConnect=false) return false;JudgeConnect=false;H
19、ead-Front-Prior=NULL;Head-Tail-Next=NULL;return true;template inline Type Queue:front()return Head-Front-Value;template inline Type Queue:back()return Head-Tail-Value;template inline bool Queue:empty()if(Now_Size=0) return true;else return false;template inline int Queue:size()return Now_Size;3.3 保存
20、车辆信息的结构体定义struct CarInfoint Num;string Number;time_t InTime;time_t OutTime;int Now_Money;transcript;/transcript用来保存临时使用的变量,省去了每次定义的麻烦。无实际意义。3.4 主要函数(初始化函数、进出车库函数及更新数据函数)void Initialization()/初始化函数FILE *stream;freopen_s(&stream, d:/Index.txt, r, stdin);/从D盘根目录下读取标准数据int Money, Time;int Storage, Road;
21、int i;for (i = 0; i Money;Money_Indexi = Money;for (i = 0; i Time;Time_Indexi = Time;cin Storage;Storage_Index = Storage;cin Road;Road_Index = Road;freopen_s(&stream, CON, r, stdin);/让输入转回控制台CarStorage.resize(Storage_Index);/重新定义停车场的大小CarRoad.resize(Road_Index);/重新定义便道的大小void InPutStorage()/车辆入库stri
22、ng CarNum;if (CarStorage.size() = Storage_Index)char cmd;cout cmd)if (cmd = Y | cmd = y)InPutRoad();return;else if (cmd = N | cmd = n) return;elsecout 3)cout 输入错误次数超过三次,入库失败! endl;return;cout CarNum;CarNum = CarNum.substr(0, 8);if (Rechecking(CarNum)cout 车牌重复,不得入库! endl;return;transcript.Num = CarSt
23、orage.size() + 1;transcript.Number = CarNum;transcript.InTime = Set_NowTime();transcript.Now_Money = Money_Index0;CarStorage.push(transcript);Get_StorageInfomation();void OutPutStorage()/车辆出库if (CarStorage.size() = 0)cout 车库为空! endl;return;cout CarNum;CarNum = CarNum.substr(0, 8);Stack CarStorage_Tr
24、anscript;bool Judge = false;while (!(CarStorage.empty() CarStorage_Transcript.push(CarStorage.top();CarStorage.pop();CarInfo Goal_Car;while (!(CarStorage_Transcript.empty() if (CarStorage_Transcript.top().Number = CarNum)Judge = true;Goal_Car = CarStorage_Transcript.top();Goal_Car.OutTime = time(0);
25、elseCarStorage.push(CarStorage_Transcript.top();CarStorage_Transcript.pop();if (Judge = false)char cmd;cout cmd)if (cmd = Y | cmd = y)OutPutRoad(CarNum);return;else if (cmd = N | cmd = n) return;elsecout 3)cout 输入错误次数超过三次,出库失败! endl;return;if (!(CarRoad.empty() RoadToStorage();Get_StorageInfomation(
26、);cout 出库车辆信息: 车牌号: Goal_Car.Number 入库时间:;time_t t = Goal_Car.InTime;char tmp64;strftime(tmp, sizeof(tmp), %X, localtime(&t);cout tmp;cout 出库时间:;t = Goal_Car.OutTime;strftime(tmp, sizeof(tmp), %X, localtime(&t);cout tmp;Goal_Car = UpData_Now_Money(Goal_Car);cout 停车费用: Goal_Car.Now_Money endl;void In
27、PutRoad()/车辆入便道string CarNum;if (CarRoad.size() = Road_Index)cout 便道已满,入库失败! endl;return;cout CarNum;CarNum = CarNum.substr(0, 8);if (Rechecking(CarNum)cout 车牌重复,不得入库! endl;return;transcript.Num = CarRoad.size() + 1;transcript.Number = CarNum;transcript.InTime = Set_NowTime();CarRoad.push(transcript
28、);Get_RoadInfomation();void OutPutRoad(string Goal)/车辆出便道if (CarRoad.size() = 0)cout 便道为空! endl;return;cout 请输入车牌:;string CarNum = Goal;Stack CarRoad_Transcript;bool Judge = false;while (!(CarRoad.empty() CarRoad_Transcript.push(CarRoad.top();CarRoad.pop();CarInfo Goal_Car;while (!(CarRoad_Transcrip
29、t.empty() if (CarRoad_Transcript.top().Number = CarNum)Judge = true;Goal_Car = CarRoad_Transcript.top();Goal_Car.OutTime = time(0);elseCarRoad.push(CarRoad_Transcript.top();CarRoad_Transcript.pop();if (Judge = false)cout 未找到该车辆! endl;return;Get_RoadInfomation();cout 出库车辆信息: 车牌号: Goal_Car.Number 入库时间
30、:;time_t t = Goal_Car.InTime;char tmp64;strftime(tmp, sizeof(tmp), %X, localtime(&t);cout tmp;cout 出库时间:;t = Goal_Car.OutTime;strftime(tmp, sizeof(tmp), %X, localtime(&t);cout tmp endl;void RoadToStorage()/便道的第一辆车进入停车场Stack CarRoad_Transcript;while (!(CarRoad.empty() CarRoad_Transcript.push(CarRoad.
31、top();CarRoad.pop();CarInfo Goal_Car;Goal_Car = CarRoad_Transcript.top();CarRoad_Transcript.pop();while (!(CarRoad_Transcript.empty() CarRoad.push(CarRoad_Transcript.top();CarRoad_Transcript.pop();Goal_Car.InTime = Set_NowTime();Goal_Car.Now_Money = Money_Index0;CarStorage.push(Goal_Car);bool Rechec
32、king(string Goal)/重复检查bool Judge = false;Stack CarStorage_Transcript;while (!(CarStorage.empty() CarStorage_Transcript.push(CarStorage.top();CarStorage.pop();while (!(CarStorage_Transcript.empty() if (CarStorage_Transcript.top().Number = Goal) Judge = true;CarStorage.push(CarStorage_Transcript.top()
33、;CarStorage_Transcript.pop();if (Judge = true) return true;Stack CarRoad_Transcript;while (!(CarRoad.empty() CarRoad_Transcript.push(CarRoad.top();CarRoad.pop();while (!(CarRoad_Transcript.empty() if (CarRoad_Transcript.top().Number = Goal) Judge = true;CarRoad.push(CarRoad_Transcript.top();CarRoad_
34、Transcript.pop();if (Judge = true) return true;return false;3.5 设置标准信息函数void Set_Money_Index()/设置收费标准中的费用if (!(CarStorage.empty() | !(CarRoad.empty()cout 无法修改收费标准,请确保没有车辆在停车场或便道内! endl;return;cout setw(70) setfill(-) endl;Get_NowTime();cout 收费标准: 停车时间 费用 endl;cout 【1】 setw(15) setfill( ) 小于 setw(8)
35、setfill( ) Time_Index0 秒 setw(9) setfill( ) Money_Index0 元/次 endl;cout 【2】 setw(15) setfill( ) 小于 setw(8) setfill( ) Time_Index1 秒 setw(9) setfill( ) Money_Index1 元/次 endl;cout 【3】 setw(15) setfill( ) 大于等于 setw(8) setfill( ) Time_Index1 秒 setw(9) setfill( ) Money_Index2 元/秒 endl;cout 备注:费用计算不叠加,按最高档
36、次计算费用! endl;cout setw(70) setfill(-) endl;string cmd;int Times = 0;while (true)cout cmd;if (cmd = 1)cout Money;Money_Index1 - 1 = Money;else if (cmd = 2)cout Money;Money_Index2 - 1 = Money;else if (cmd = 3)cout Money;Money_Index3 - 1 = Money;else if (cmd = Over)UpData_Index();return;elsecout 输入错误,请重
37、新输入!(1/2/3/Over) 3)cout 输入错误次数超过三次,修改失败! endl;return;void Set_Time_Index()/设置收费标准中的时间段if (!(CarStorage.empty() | !(CarRoad.empty()cout 无法修改收费标准,请确保没有车辆在停车场或便道内! endl;return;cout setw(70) setfill(-) endl;Get_NowTime();cout 收费标准: 停车时间 费用 endl;cout 【1】 setw(15) setfill( ) 小于 setw(8) setfill( ) Time_Index0 秒 setw(9) setfill( ) Money_Index0 元/次 endl;cout 【2】 setw(15) setfill( ) 小于 setw(8) setfill( ) Time_Index1 秒 setw(9) setfill( ) Money_Index1 元/次 endl;cout 【3】 setw(15) setfill( ) 大于等于 setw(8) setfill( ) Time_I
限制150内