实训报告专业:班级:学号:姓名:课设题目:停车场模拟管理系统指导教师:目录一、需求分析 (1)二、总体设计 (1)2.1系统功能概述 (1)三、到达停车场准备进入停车场 (2)3.1进入停车场函数 (3)四、离开停车场 (3)五、详细设计 (6)5.1函数的调用关系 (6)5.2主要算法的流程图 (6)六、软件说明: (8)6.1使用环境:Visual C++ 6.0. (8)操作要求:程序运行后,用户根据所要进行的操作选择是进入停车场还是离开停车场并输入车牌号和时间 (8)6.2测试图: (8)七、总结 (10)附录:程序代码 (10)一、需求分析停车场模拟管理系统现在很多的大型超市等都有智能的停车场当你进入停车场门口就会自动的显示里面还有多少的空位并且指引你走到空的车位停下避免了把车辆开进去并且找不到空的车位和因为车子在停车场内乱走而导致想出来的车没有足够的时间出来。
导致空间和时间各种不必要的麻烦所以急需我们做一个停车场管理系统。
我们的停车场模拟管理系统有以下方面功能:1记录进入停车场的车辆的车牌号从而进入后可以知道其所停的停车位。
2车子离开停车场根据离开时间和进入时间从而计算出所需要交的费用。
3如果队列已经满了可以让要进入停车场的车子停在旁边的等候队列。
二、总体设计2.1系统功能概述(1)如果选择进入停车场就要判断停车场是否已经满了,如果未满直接进入,如果满了的话就直接排在旁边的便道上等待有车子离开停车场从而进入停车场。
(2)同时改程序还设立多了一个位置以便与有车进入同时有车离开可以停留在这里等候车子离开再进入。
(以防止车子停车场内的车未能离开进入的车又正在进入从而导致停车场堵塞的情况)(3)离开的时候根据离开的车牌号从而把它从停车场中的位置移开并且通过离开时间和进入停车场的时间来计算出该车子所需要交纳的费用。
2.11 总体设计图三、到达停车场准备进入停车场void parkingmanagement::arrival(carstack &cs,carqueue &cq,int cnum,double ctime){int pos;if(!(cs.full())){ 到达停车场的车子首先输入其判int fl(0),i; 断停车场是否已经满了如果则直for(i=0;i<=cs.top;i++){ 接进入等候车道否则就进入停场if(cs.s[i].number==cnum){fl=1;break;}}if(fl==1)cout<<"输入错误!请重新输入!如果到达的车的车牌号!=栈内已有车辆的车牌号"<<endl;else{pos=pushstack(cs,cnum,ctime);//入栈,返回车位信息cout<<"该停车场还有空位,请到"<<pos<<"号车位进行泊车"<<endl;cout<<endl;}}else{pos=pushqueue(cq,cnum,ctime);cout<<"该停车场已满,请将车停到便道"<<pos<<"号车位上"<<endl;cout<<endl;}}3.1进入停车场函数int parkingmanagement::pushstack(carstack &cs,int cnum,double ctime){if(cs.top==Max-1){cout<<"停车场已满!"<<endl;return Max;}else{cs.top++;(cs.s[cs.top]).number=cnum;(cs.s[cs.top]).time=ctime;return (cs.top+1);}}四、离开停车场void parkingmanagement::leave(carstack &cs,carqueue &cq,int cnum,double ctime){int i,flag(0),pstack,count(1),outcarnum;double hour;car *p;for(i=0;i<=cs.top;i++)if((cs.s[i]).number==cnum){flag=1;break;}if(flag){popstack(cs,cnum);hour=ctime-popstacktime;outcarnum=popqueue(cq);/pstack=pushstack(cs,outcarnum,ctime);cout<<"该车在本停车场内停留时间为"<<hour<<"分钟,应付金额"<<hour*(price/60)<<"元!"<<endl;cs.top--;}else{p=cq.front;while(p!=NULL) //如果所输入的车牌号的车子并不是 { 在停车内而是在等候车道内就可直接开走无需收费count++;p=p->next;if(p->number==cnum){deletequeue(cq,count);if(count>Max){cout<<"您的车在便道上的位置为"<<count<<"号车位,请自行驶离,无需付费!"<<endl;break;}}}if(p==NULL) cout<<"您的车不在本停车场内,或输入有误,请重新输入!"<<endl;}}五、详细设计5.1函数的调用关系如下图:图5.11 函数调用5.2主要算法的流程图主程序模块判断进入还是离开离开函数调到达函数输出模块图5.22主要算法图六、软件说明:6.1使用环境:Visual C++ 6.0.操作要求:程序运行后,用户根据所要进行的操作选择是进入停车场还是离开停车场并输入车牌号和时间6.2测试图:程序开始运行:图 6.1 程序主界面进入停车场输入选项和车牌号和时间:图6.2 进入停车场离开停车场输入D 车牌号时间:(根据车牌号找到相应的车)图6.3离开停车场显示结果七、总结在这一次的实训中才知道什么叫做真真正正的体会到什么叫做你看得懂程序听得懂课拿着中上的成绩你就口可以说你懂数据结构懂C++懂C了,无数次在修改代码无数次在询问老师问题同学问题,每一次编译错误减少一小个心里乐得跟开了花似的。
非常的感谢同学和老师在QQ上不厌其烦的一次又一次的回答我的问题哪怕是一个马虎的分号的错误。
正所谓勤能补拙往后的我要更加的努力去学习了。
附录:程序代码#include<iostream>using namespace std; const int Max=10;const double price=30;class car{public:double time;int number;car *next;};class carstack{friend class parkingmanagement;public:carstack();int empty();int full();car *s;int top;};carstack::carstack(){top=-1;s=new car[Max];if(s==NULL){cout<<"栈空间分配不成功!"<<endl;exit(1);}}int carstack::full(){return top==Max-1;}class carqueue{friend class parkingmanagement;public:carqueue();int full();car *front,*rear;};carqueue::carqueue(){rear=front=NULL;}class parkingmanagement{public:int pushstack(carstack &cs,int cnum,double ctime);void popstack(carstack &cs,int cnum);int pushqueue(carqueue &cq,int cnum,double ctime);int popqueue(carqueue &cq);void arrival(carstack &cs,carqueue &cq,int cnum,double ctime);void leave(carstack &cs,carqueue &cq,int cnum,double ctime);void deletequeue(carqueue &cq,int i);int popstacknumber;double popstacktime;};int parkingmanagement::pushstack(carstack &cs,int cnum,double ctime){if(cs.top==Max-1){//Max从1开始,top从0开始cout<<"停车场已满!"<<endl;return Max;}else{cs.top++;(cs.s[cs.top]).number=cnum;(cs.s[cs.top]).time=ctime;return (cs.top+1); }}void parkingmanagement::popstack(carstack &cs,int cnum) {int i;car p;carstack stemp;for(i=0; i<=cs.top; i++)if((cs.s[i]).number==cnum) break;p=cs.s[i];while(cs.top>i) stemp.s[++(stemp.top)]=cs.s[(cs.top)--];popstacknumber=p.number;int popstacknumber()popstacktime=p.time;double popstacktime()cs.top--;while(stemp.top>=0)cs.s[++(cs.top)]=stemp.s[(stemp.top)--];}int parkingmanagement::pushqueue(carqueue &cq,int cnum,double ctime){car *p,*countp;int count(1);p=new car;p->number=cnum;p->time=ctime;p->next=NULL;if (cq.front==NULL){cq.front=cq.rear=p;}else{p->next=(cq.rear)->next;(cq.rear)->next=p;cq.rear=(cq.rear)->next;}countp=(cq.front)->next;while(countp!=NULL){count++;countp=countp->next;}return count;}int parkingmanagement::popqueue(carqueue &cq){car p;if(cq.front!=NULL){p.number=((cq.front)->next)->number;p.time=((cq.front)->next)->time;p.next=((cq.front)->next)->next;}return p.number;}void parkingmanagement::arrival(carstack &cs,carqueue &cq,int cnum,double ctime){int pos;if(!(cs.full())){int fl(0),i;for(i=0;i<=cs.top;i++){if(cs.s[i].number==cnum){ fl=1;break;}}if(fl==1)cout<<"输入错误!请重新输入!如果到达的车的车牌号!=栈内已有车辆的车牌号"<<endl;Else{pos=pushstack(cs,cnum,ctime);//入栈,返回车位信息cout<<"该停车场还有空位,请到"<<pos<<"号车位进行泊车"<<endl;cout<<endl;}}Else{pos=pushqueue(cq,cnum,ctime);cout<<"该停车场已满,请将车停到便道"<<pos<<"号车位上"<<endl;cout<<endl;}}void parkingmanagement::leave(carstack &cs,carqueue &cq,int cnum,double ctime){int i,flag(0),pstack,count(1),outcarnum;double hour;car *p;for(i=0;i<=cs.top;i++)if((cs.s[i]).number==cnum){flag=1;break;}if(flag){popstack(cs,cnum);hour=ctime-popstacktime;outcarnum=popqueue(cq);pstack=pushstack(cs,outcarnum,ctime);cout<<"该车在本停车场内停留时间为"<<hour<<"分钟,应付金额"<<hour*(price/60)<<"元!"<<endl;cs.top--;}else{p=cq.front;while(p!=NULL){count++;//如果在过道中找到该车,则该车的位置为过道中的第count位置(count从1开始)p=p->next;if(p->number==cnum){ deletequeue(cq,count);if(count>Max){cout<<"您的车在便道上的位置为"<<count<<"号车位,请自行驶离,无需付费!"<<endl;break;}}}if(p==NULL) cout<<"您的车不在本停车场内,或输入有误,请重新输入!"<<endl;}}void parkingmanagement::deletequeue(carqueue &cq,int i){ car *p,*q;int j(0);p=cq.front;while(p && j<i-1){p=p->next;j++;}if(!p || !p->next) cout<<"i不合法";else{q=p->next;p->next=q->next;delete q;}}void print(){cout<<"= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ="<<endl;cout<<"= 欢迎光临!="<<endl;cout<<"= ="<<endl;cout<<"= 本停车场收费标准为:30元/小时;车库容量为:10 ="<<endl;cout<<"= ="<<endl;cout<<"= 请输入您的泊车信息:格式为:(到达/离去/退出);车牌号;现在时刻 ="<<endl;cout<<"= 其中,A:到达;D:离去;E:退出系统="<<endl;cout<<"= = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = = = ="<<endl;}int main(){char acc;int carnum;double cartime;parkingmanagement park;carstack cars;carqueue carq;while(1){print();cin>>acc>>carnum>>cartime;if(acc=='A') park.arrival(cars,carq,carnum,cartime);else if(acc=='D') park.leave(cars,carq,carnum,cartime);else if(acc=='E') break;elsecout<<"您的输入有误,请重新输入!"<<endl;}}。