停車場管理系統(tǒng)程序設(shè)計_第1頁
停車場管理系統(tǒng)程序設(shè)計_第2頁
停車場管理系統(tǒng)程序設(shè)計_第3頁
停車場管理系統(tǒng)程序設(shè)計_第4頁
停車場管理系統(tǒng)程序設(shè)計_第5頁
已閱讀5頁,還剩19頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、停車場管理系統(tǒng)1.1 設(shè)計要求1.1.1 問題描述設(shè)計一個停車場管理系統(tǒng),模擬停車場的運(yùn)作,此程序具有以下功能: 汽車到達(dá),則顯示汽車在停車場內(nèi)或便道上的停車位置。 若車離去,則顯示汽車在停車場內(nèi)停留的時間和應(yīng)繳納的費(fèi)用(在便道上停留的時間不收費(fèi)) 。1.1.2 基本要求要求以棧模擬停車場,以隊列模擬車場外地便道,按照從終端讀入的輸入數(shù)據(jù)序列進(jìn)行模擬管理。 求處理的數(shù)據(jù)元素包括三個數(shù)據(jù)項:汽車“到達(dá)”或“離去”信息。汽車牌照號碼以及離去的時刻。 要求棧以順序結(jié)構(gòu)實現(xiàn),隊列以鏈表實現(xiàn)。1.1.3 測試數(shù)據(jù)自行設(shè)計一組在停車場上停車的數(shù)據(jù)和便道上停車的數(shù)據(jù)。1.1.4 實現(xiàn)提示該停車場能容納車輛的

2、數(shù)量,便道上的停車數(shù)量。車輛到達(dá)對應(yīng)棧的入棧操作,車輛離開對應(yīng)棧的出棧操作。1.2 設(shè)計代碼及注釋#include<iostream>#include<time.h>#include<ctime>#include<dos.h>#include<windows.h> using namespace std; #define PASS 20#define POT 20 struct passLot/ 便道隊列數(shù)據(jù)結(jié)構(gòu) int num;/ 車位號time_t timep;/ 停車時間 int carNum;/ 停車的車牌號碼;struct

3、potLot/ 停車場棧數(shù)據(jù)結(jié)構(gòu) int num;time_t timep;int carNum;void printLine()/ 打印下劃線(作為主界面圖表的框架) cout<<"ttt"<<endl;return;void printStar()/ 打印星號cout<<endl<<"tt*"<<endl;class erroFull/ 停車位滿時異常類public:erroFull()system("color 3c");void ex()cout<<end

4、l<<"ttt! 停車場位已滿!"<<endl;_sleep(2000);erroFull();class erroEmp/ 停車位空時異常類public:erroEmp()system("color 3c");void ex() cout<<"! 停車場位為空!"<<endl;_sleep(2000);erroEmp() ;class parkingLot/ 停車場類 public:parkingLot() passLot* pa;/ 便道停車位指針potLot* po;/ 停車場停車

5、位指針flag=0;/ 用來記憶隊列(便道)中停車的數(shù)量rear=front=0;/ 初始化隊列頭尾base=0;top=base;/ 初始化棧頭尾int i=0;/ 初始化停車場和便道空間以及車位號 for(;i<POT;i+) pa=(passLot*)malloc(sizeof(passLot); ai=pa;ai->num=i+1;ai->carNum=0;po=(potLot*)malloc(sizeof(potLot); bi=po;bi->num=i+1;bi->carNum=0; parkingLot() cout<<"tt

6、停車場數(shù)據(jù)已清空。"<<endl;void passLG()/ 便道管理函數(shù) tryif(flag=20) throw erroFull();/ system("cls");printStar();如果停車位已滿,則拋出車位慢得異常情況cout<<"tttt 您進(jìn)入了便道停車界面"<<endl;cout<<endl<<"ttt 便 道 停 車 場 共 有 20 個 車 位 , 現(xiàn) 共 停 "<<flag<<" 個 車 位 。 &qu

7、ot;<<endl<<endl;cout<<"ttt請輸入將要停車的號碼:"cin>>arear->carNum;arear->timep=time(NULL);cout<<endl<<"ttt ! !汽車停放在"<<arear->num<<" 車位成功,系統(tǒng)將在一秒后返回上層界面! "<<endl;rear=(rear+1)%PASS;flag+;_sleep(1000);catch(erroFull &am

8、p;err)err.ex();void potLG()/ 停車場管理函數(shù)tryif(top=20) throw erroFull();system("cls");printStar();cout<<"tttt 您進(jìn)入了停車場停車界面"<<endl;cout<<endl<<"ttt 停車場共有20 個車位,現(xiàn)共停"<<top<<" 個車位。"<<endl<<endl;cout<<"ttt請輸入將要停車

9、的號碼:"cin>>btop->carNum;btop->timep=time(NULL);cout<<endl<<"ttt ! ! 汽車停放在"<<btop->num<<" 車位成功,系統(tǒng)將在一秒后返回上層界面! ! "<<endl;top+;_sleep(1000);catch(erroFull &err)err.ex();void arrive()/ 汽車到達(dá) int choice=-1;if(top=20&&flag=20)

10、 throw erroFull();for(;)system("cls");printStar();cout<<"tttt歡迎進(jìn)入停車場"<<endl<<endl;printLine();cout<<"ttt|1.停車場停車ttt |"<<endl;/*打印兩個空格*/printLine();cout<<"ttt|2. printLine();便道停車ttt |"<<endl;cout<<"ttt|3.返回 t

11、tt |"<<endl;printLine();printStar();cout<<"tt請輸入你的選項:cin>>choice;switch(choice)case 1:potLG();break;case 2:passLG();break;case 3:break;default:system("color 3c");cout<<endl<<"tttt輸入格式不正確!"<<endl;_sleep(1000);break;if(choice=3)break;re

12、turn;int feep(time_t* tmp)/費(fèi)用計算int gap=0,m=0,hour=0,min=0,sec=0;/設(shè)置數(shù)據(jù)用來計算時間間隔,停車時、分、秒。local=localtime(tmp);/將存儲的時間轉(zhuǎn)化為當(dāng)?shù)貢r間日歷cout<<local->tmhour<<":"<<local->tmmin<<":"<<local->tm_sec<<endl;/ 顯示停車時刻hour=local->tm_hour;/保存停車時刻min=local

13、->tm_min;sec=local->tm_sec;now=time(NULL);nowp=localtime(&now);cout<<"t 當(dāng)前時間為:"<<nowp->tm_hour<<":"<<nowp->tm_min<<":"<<nowp->tm_sec<<endl;hour = nowp->tm_hour-hour;/求出停車的時間間隔min= nowp->tm_min-min;sec= n

14、owp->tm_sec-sec;if(sec<0)min-;sec=60+sec;/進(jìn)行秒、分鐘、秒時間轉(zhuǎn)換if(min<0) hour-;min=60+min;cout<<"t汽車共停了"<< hour<<" 小時 "<< min<<" 分 "<< sec<<" 秒 "<<endl;if(0!=min)|(0!=sec) m=1;gap= hour+m;/ 停車應(yīng)收費(fèi)的時間(單位:小時) return

15、 gap;void passOut()/ 便道離開 tryif(flag=0) throw erroEmp();int fee=0;system("cls");printStar();cout<<"tttt 您進(jìn)入了便道離開界面"<<endl;cout<<endl<<"ttt 便道停車場共有20 個車位,現(xiàn)共停"<<flag-1<<" 個車位。<<endl<<endl;cout<<"ttt 將要離開車的信息為

16、:"<<endl;cout<<"t車牌號碼:"<<afront->carNum<<"t 車位:便道"<<afront->num<<"號 tt 停車時間:"fee=feep(&afront->timep)*0;cout<<"t 該車應(yīng)繳納停車費(fèi)為:"<<fee<<"元(便車道停車免費(fèi))"<<endl;afront->carNum=0;fr

17、ont=(front+1)%PASS; flag-;cout<<endl<<"ttt ! !汽車離開成功,按任意鍵返回! "<<endl;system("pause"); catch(erroEmp &err) err.ex();void potOut()/ 停車場離開 tryif(top=0) throw erroEmp();int fee=0;top-;system("cls");printStar();cout<<"tttt 您進(jìn)入了停車場離開界面"&l

18、t;<endl;cout<<endl<<"ttt 停車場共有20 個車位,現(xiàn)共停"<<top<<" 個車位。"<<endl<<endl;cout<<"ttt將要離開車的信息為:"<<endl;cout<<"t車牌號碼:"<<btop->carNum<<"t 車位:停車場"<<btop->num<<"號 tt 停車時

19、間:"fee=feep(&btop->timep)*8;/ 計費(fèi)公式,每小時8 元cout<<"t 該車應(yīng)繳納停車費(fèi)為:"<<fee<<"元(每小時8 元,不足一小時按一小時計算)"<<endl;btop->carNum=0;cout<<endl<<"ttt ! !汽車離開成功,按任意鍵返回! "<<endl;system("pause");catch(erroEmp &err)err.ex()

20、;void depart()/ 汽車離開int choice=-1;if(top=0&&flag=0) throw erroEmp();for(;)system("cls");system("color 3a");printStar();cout<<"tttt 歡迎下次光臨停車場"<<endl<<endl;停車場離開ttt |"<<endl;/*打印兩個空格*/printLine();cout<<"ttt|1.便道離開ttt |"

21、<<endl;printLine();cout<<"ttt|2.printLine();cout<<"ttt|3. 返回 ttt |"<<endl;printLine();printStar();cout<<"tt 請輸入你的選項:"cin>>choice;switch(choice)case 1:potOut();break;case 2:passOut();break;case 3:break;default:system("color 3c");c

22、out<<endl<<"tttt輸入格式不正確!"<<endl;_sleep(1000);break;if(choice=3)break;return;void searchNum()/ 查詢車牌號碼int numCar,i=0,flag=1;cout<<"ttt 請輸入車牌號碼:"cin>>numCar;for(;i<PASS;i+)if(ai->carNum=numCar) cout<<endl<<"ttt 車牌號為"<<n

23、umCar<<"的車子停在便車道"<<ai->num<<" 位 "<<endl;flag=0; if(flag)for(i=0;i<POT;i+)if(bi->carNum=numCar) cout<<endl<<"ttt 車牌號為"<<numCar<<"的車子停在停車道"<<bi->num<<" 位 "<<endl;flag=0;if(fl

24、ag) cout<<endl<<" 該汽車未停在本停車場!"<<endl;system("pause");void searchPot()int potCar,nn;cout<<"tt 操作說明:按照停車類型加位置來輸入所要查找的車位信息ntt 如:停車場10 號位,即輸入 110。停車場三號位,103。便道場5 號位, 205"<<endl;cout<<"tt 請輸入需要操作的序數(shù):"cin>>potCar;if(potCar&l

25、t;121&&potCar>100)|(potCar<221&&potCar>200)if(potCar/100=1)nn=potCar%100-1;if(bnn->carNum=0) cout<<"tt 你說查詢的車位沒有停車"<<endl;else cout<<" 停車場 "<<nn<<" 車位停車的車牌號是:"<<bnn->carNum<<endl;if(potCar/100=2)nn

26、=potCar%100-1;if(ann->carNum=0) cout<<"tt 你說查詢的車位沒有停車"<<endl;else cout<<" 便車道 "<<nn<<" 車位停車的車牌號是:"<<ann->carNum<<endl;else cout<<"tt 您所輸入的數(shù)字不正確!"<<endl;system("pause");void search()/ 號碼查詢int

27、 choice=-1;if(top=0&&flag=0) throw erroEmp();for(;)system("cls");system("color 3a");printStar();cout<<"tttt 您進(jìn)入了號碼查詢界面"<<endl<<endl;printLine();cout<<"ttt|1.根據(jù)車牌號碼查詢tt |"<<endl;/*打印兩個空格*/printLine();cout<<"ttt|2

28、.直接查詢指定車位tt |"<<endl;printLine();cout<<"ttt|3. 返回 ttt |"<<endl;printLine();printStar();cout<<"tt請輸入你的選項:cin>>choice;switch(choice)case 1:searchNum();break;case 2:searchPot();break;case 3:break;default:system("color 3c");cout<<endl<

29、<"tttt輸入格式不正確!"<<endl;_sleep(1000);break;if(choice=3)break;return;private:int flag,front,rear,top,base;/設(shè)置訪問棧和隊列passLot* aPASS;/ 以順序方式存儲棧和隊列,并且都設(shè)為20 個車位potLot* bPOT;tm* local,*nowp;time_t now; / 設(shè)置時間型變量;/ 停車場類結(jié)束void main()/ 程序運(yùn)行主函數(shù)parkingLot a;int choice=-1;for(;)/ 使主界面能夠自動初始化和重復(fù)使

30、用 system("cls");system("color 3a");/ 設(shè)為主背景為湖藍(lán)色printStar();cout<<"tttt 歡迎進(jìn)入停車場管理系統(tǒng)"<<endl<<endl;time_t t;/時間結(jié)構(gòu)或者對象t=time(NULL);/獲取當(dāng)前系統(tǒng)的日歷時間cout<<"tttttt"<<ctime(&t); /顯示當(dāng)前時間printLine();cout<<"ttt|1.汽車到達(dá)ttt |"<<endl;/*打印兩個空格*/printLine();cout<<"ttt|2.汽車離去ttt |"<<endl;printLine();cout<<"ttt|3.汽車牌號查詢ttt |"<<endl;printLine();cout<<"ttt|4.退出管理系統(tǒng)ttt |"<<endl;printLine();printStar();cout<<"tt 請輸入你的選項:"cin>>choice;s

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論