1、停车场管理系统 程序设计一、停车场管理系统1.1设计要求1。1.1问题描述设计一个停车场管理系统,模拟停车场的运作,此程序具有以下功能:1汽车到达,则显示汽车在停车场内或便道上的停车位置。2若车离去,则显示汽车在停车场内停留的时间和应缴纳的费用(在便道上停留的时间不收费)。1.1。2基本要求要求以栈模拟停车场,以队列模拟车场外地便道,按照从终端读入的输入数据序列进行模拟管理。2求处理的数据元素包括三个数据项:汽车“到达”或“离去信息.汽车牌照号码以及离去的时刻。3要求栈以顺序结构实现,队列以链表实现。1。1.3测试数据自行设计一组在停车场上停车的数据和便道上停车的数据.1。1.4实现提示该停车
2、场能容纳车辆的数量,便道上的停车数量。车辆到达对应栈的入栈操作,车辆离开对应栈的出栈操作。1。2设计代码及注释include#includetime.h#includectimeincludedos。hincludeusing namespace std;#define PASS 20#define POT 20struct passLot/便道队列数据结构 int num;/车位号 time_t timep;/停车时间 int carNum;/停车的车牌号码;struct potLot/停车场栈数据结构int num; time_t timep; int carNum;;void print
3、Line()/打印下划线(作为主界面图表的框架)coutttt_”endl;return;void printStar()/打印星号coutendltt*”endl;class erroFull/停车位满时异常类public: erroFull() system(color 3c); void ex() coutendlttt!!停车场位已满!”endl; _sleep(2000); erroFull();class erroEmp/停车位空时异常类public: erroEmp() system(color 3c”); void ex() coutcarNum=0; po=(potLot)m
4、alloc(sizeof(potLot); bi=po; bi-num=i+1; bi-carNum=0; parkingLot() cout”tt停车场数据已清空.”endl; void passLG()/便道管理函数 try if(flag=20) throw erroFull();/如果停车位已满,则抛出车位慢得异常情况 system(”cls”); printStar(); couttttt您进入了便道停车界面”endl; coutendl”ttt便道停车场共有20个车位,现共停flag个车位.”endlendl; coutarear-carNum; areartimep=time(N
5、ULL); coutendlttt!汽车停放在arear-num”车位成功,系统将在一秒后返回上层界面!!endl; rear=(rear+1)PASS; flag+; _sleep(1000); catch(erroFull &err) err。ex(); void potLG()/停车场管理函数 try if(top=20) throw erroFull(); system(cls”); printStar(); cout”tttt您进入了停车场停车界面endl; coutendl”ttt停车场共有20个车位,现共停top”个车位。”endlendl; coutbtop-carNum; b
6、toptimep=time(NULL); coutendl”ttt!!汽车停放在”btop-num车位成功,系统将在一秒后返回上层界面!”endl; top+; _sleep(1000); catch(erroFull &err) err.ex(); void arrive()/汽车到达 int choice=1; if(top=20&flag=20) throw erroFull(); for(;) system(”cls); printStar(); cout”tttt欢迎进入停车场endlendl; printLine(); cout”ttt|1.停车场停车ttt ”endl;/打印两个
7、空格/ printLine(); coutttt|2。便道停车ttt endl; printLine(); coutttt|3.返回 ttt ”endl; printLine(); printStar(); coutchoice; switch(choice) case 1:potLG();break; case 2:passLG();break; case 3:break; default:system(”color 3c);coutendltttt输入格式不正确!”endl; _sleep(1000);break; if(choice=3)break; return;int feep(ti
8、me_t* tmp)/费用计算 int gap=0,m=0,hour=0,min=0,sec=0;/设置数据用来计算时间间隔,停车时、分、秒. local=localtime(tmp);/将存储的时间转化为当地时间日历 coutlocaltm_hour:”tm_min:” tm_sectm_hour;/保存停车时刻 min=local-tm_min; sec=local-tm_sec; now=time(NULL); nowp=localtime(now); couttm_hourtm_mintm_sectm_hourhour;/求出停车的时间间隔 min= nowptm_min-min; s
9、ec= nowp-tm_sec-sec;if(sec0)min;sec=60+sec;/进行秒、分钟、秒时间转换 if(min0) hour;min=60+min; coutt汽车共停了 hour小时 min分 sec秒”endl; if((0!=min)|(0!=sec)) m=1; gap= hour+m;/停车应收费的时间(单位:小时) return gap;void passOut()/便道离开try if(flag=0) throw erroEmp(); int fee=0; system(cls); printStar(); couttttt您进入了便道离开界面”endl; cou
10、tendl”ttt便道停车场共有20个车位,现共停”flag1”个车位。 endlendl; cout”ttt将要离开车的信息为:”endl; coutcarNumt车位:便道afrontnum ”号tt停车时间:; fee=feep(&afront-timep)0; cout”t该车应缴纳停车费为:”fee ”元(便车道停车免费)carNum=0; front=(front+1)PASS; flag-; coutendlttt!汽车离开成功,按任意键返回!endl; system(”pause); catch(erroEmp &err) err。ex(); void potOut()/停车场
11、离开try if(top=0) throw erroEmp(); int fee=0; top-; system(”cls); printStar(); couttttt您进入了停车场离开界面endl; coutendl”ttt停车场共有20个车位,现共停top”个车位。” endlendl; coutttt将要离开车的信息为:endl; coutt车牌号码:carNum”t车位:停车场num 号tt停车时间:; fee=feep(&btop-timep)8;/计费公式,每小时8元 cout”t该车应缴纳停车费为:”fee ”元(每小时8元,不足一小时按一小时计算)”carNum=0; cou
12、tendl”ttt!!汽车离开成功,按任意键返回!endl; system(”pause); catch(erroEmp err) err。ex(); void depart()/汽车离开 int choice=1; if(top=0&flag=0) throw erroEmp(); for(;;) system(”cls); system(color 3a); printStar(); couttttt欢迎下次光临停车场endlendl; printLine(); cout”ttt|1.停车场离开ttt |endl;/打印两个空格/ printLine(); cout”ttt2。便道离开tt
13、t |endl; printLine(); coutttt3。返回 ttt endl; printLine(); printStar(); cout”tt请输入你的选项:”; cinchoice; switch(choice) case 1:potOut();break; case 2:passOut();break; case 3:break; default:system(color 3c”);coutendl”tttt输入格式不正确!”endl; _sleep(1000);break; if(choice=3)break; return;void searchNum()/查询车牌号码 i
14、nt numCar,i=0,flag=1; coutnumCar; for(;iPASS;i+) if(ai-carNum=numCar) coutendlttt车牌号为”numCar”的车子停在便车道num位”endl; flag=0; if(flag)for(i=0;iPOT;i+) if(bicarNum=numCar) coutendlttt车牌号为”numCarnum”位”endl; flag=0; if(flag) coutendl”该汽车未停在本停车场!endl; system(pause);void searchPot() int potCar,nn; cout”tt操作说明:
15、按照停车类型加位置来输入所要查找的车位信息ntt如:停车场10号位,即输入110。停车场三号位,103。便道场5号位,205endl; coutpotCar; if((potCar121&potCar100)(potCar200)) if(potCar/100=1) nn=potCar1001; if(bnncarNum=0) cout”tt你说查询的车位没有停车endl; else cout停车场nn车位停车的车牌号是:carNumendl; if(potCar/100=2) nn=potCar100-1; if(anncarNum=0) couttt你说查询的车位没有停车endl; els
16、e cout”便车道”nn”车位停车的车牌号是:anncarNumendl; else couttt您所输入的数字不正确!”endl; system(pause);void search()/号码查询 int choice=-1; if(top=0&flag=0) throw erroEmp(); for(;) system(”cls”); system(color 3a); printStar(); couttttt您进入了号码查询界面”endlendl; printLine(); cout”ttt|1。根据车牌号码查询tt ”endl;/*打印两个空格*/ printLine(); cou
17、t”ttt2.直接查询指定车位tt |endl; printLine(); coutttt3.返回 ttt |endl; printLine(); printStar(); coutchoice; switch(choice) case 1:searchNum();break; case 2:searchPot();break; case 3:break; default:system(”color 3c);coutendltttt输入格式不正确!endl; _sleep(1000);break; if(choice=3)break; return;private: int flag,fron
18、t,rear,top,base;/设置访问栈和队列 passLot* aPASS;/以顺序方式存储栈和队列,并且都设为20个车位 potLot bPOT; tm local,*nowp; time_t now; /设置时间型变量;/停车场类结束void main()/程序运行主函数parkingLot a;int choice=1;for(;)/使主界面能够自动初始化和重复使用 system(cls); system(”color 3a);/设为主背景为湖蓝色 printStar(); cout”tttt欢迎进入停车场管理系统endlendl; time_t t; /时间结构或者对象 t=ti
19、me(NULL); /获取当前系统的日历时间 couttttttt”ctime(&t); /显示当前时间 printLine(); cout”ttt1。汽车到达ttt ”endl;/*打印两个空格*/ printLine(); coutttt2.汽车离去ttt |”endl; printLine(); cout”ttt|3.汽车牌号查询ttt |”endl; printLine(); cout”ttt|4.退出管理系统ttt |endl; printLine(); printStar(); cout”tt请输入你的选项:; cinchoice; switch(choice) case 1: t
20、ry a。arrive(); catch (erroFull &erro) erro。ex(); break; case 2:a.depart();break; case 3:a.search();break; case 4:break; default:system(color 3c);coutendl”tttt输入格式不正确!endl; _sleep(2000);break; if(choice=4) break;return;1。3测试结果以及运行情况1.3。1运行主界面1.3.2汽车到达界面1.3.2。1停车场停车测试界面测试数据(按输入的先后排序)表1序号12345678910牌照号
21、2001200220032004200520062007200820092010序号11121314151617181920牌照号2011201220132014201520162017201820192020输入情况界面(部分)异常情况处理,当停车场已经满20位时,便抛出异常(界面显示为红色,并停止工作)1。3。2.2便车道停车测试测试数据表2序号12345678910牌照号3001300230033004300530063007300830093010序号11121314151617181920牌照号3011301230133014301530163017301830193020输入界面(
22、部分)异常情况处理,当停车场已经满20位时,便抛出异常(界面显示为红色,并停止工作)1.3.3汽车离开界面1.3.3.1停车场离开界面当停车场为空时,抛出异常为空(颜色变红)1.3。3。2便车道离开界面当便车道为空时,抛出异常为空(颜色变红)1.3。4号码查询界面1。3。4.1根据车牌号码查询1。3。4。2直接查询指定车位界面1。4评估与改进1.4。1评估该系统能够完成题目要求的几项基本操作以及显示结果,并且显示的信息完全正确.在此基础上还加上了异常处理机制以及由异常处理导致的终端显示变异功能,同时在查询方面不仅完成了输入车牌号码查询功能,还能实现查找特定车位上停车情况的功能.实验基本达到要求。1。4.2改进真正的停车场不可能只按栈或者队列的顺序来停车,故此系统具有一定的局限性。应根据停车场的具体情况对停车储存方式进行灵活地改善.代码也比较冗余,希望能够不断简化。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1