




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優質文檔-傾情為你奉上問題描述:設停車場內只有一個可停放n輛汽車的狹長通道,且只有一個大門可以供汽車進出。汽車在停車場內按照車輛到達的先后順序,依次由北向南排列,大門在最南段。若停車場內車位已經停滿,則后來的車位只能停在過道上等候。一旦停車場內有車離開,停靠在過道上的車輛就能開進停車場停放。根據每輛車在停車場的停靠時間計費。請設計一個停車場管理系統。實驗代碼如下:#include #include #include #include #include #include #include using namespace std;#define MAXNUM 5#define PRICE 2.
2、0struct carchar num10;struct tm intime;struct tm outime;double expense;int length;int position;/the stack of car/typedef structcar carlistMAXNUM;int top;Seqstack;void Stackinit(Seqstack * s)s-top=-1;int Isempty(Seqstack * s)if(s-top=-1)return 1;elsereturn 0;int Isfull(Seqstack *s)if(s-top=MAXNUM-1)r
3、eturn 1;elsereturn 0;void Stackpush(Seqstack *s,car car1)if(! Isfull(s)s-top+;s-carlists-top=car1;elsecoutits full nowcarlists-top;s-top-;return car1;car Stackgettop(Seqstack *s)car car1;if(! Isempty(s)car1=s-carlists-top;return car1;/the queue of car int tunnel/struct carnodecar data;struct carnode
4、 *next;struct carnodequeuecarnode *head;carnode *rear;void carnodequeueinit(carnodequeue *q)if(!(q-head = (carnode *)malloc(sizeof(carnode)coutfailed to malloc!rear=q-head;q-head-next=NULL;q-rear-next=NULL;int carnodequeueisempty(carnodequeue *q)if(q-rear=q-head)return 1;elsereturn 0;void carnodeque
5、uein(carnodequeue *q,car cc)carnode *p;if(!(p=(carnode *)malloc(sizeof(carnode)coutfailed to malloc!data=cc;p-next=NULL;q-rear-next=p;q-rear=p;car carnodequeueout(carnodequeue *q)carnode *p;car cc;if(q-head != q-rear)p=q-head-next;if(p-next=NULL)cc=p-data;q-rear=q-head;free(p);elseq-rear-next=p-next
6、;cc=p-data;free(p);return cc;/ the separator of cout /void separator(int n,char ch,char newline)for(int i=0;in;i+)coutch;if(newline = 1)coutendl;/ print the time struct /void printdata(struct tm gm_data)coutgm_data.tm_mon/gm_data.tm_mday gm_data.tm_hour+8:gm_data.tm_min:gm_data.tm_secendl;/ show par
7、k /void showpark(Seqstack *s)struct tm gm;coutthe park information is follow:endl;separator(40,-,1);if(Isempty(s)coutthe park is empty !endl;elsecoutposition number intime endl;for(int i=0;itop;i+)coutcarlisti.position ime);cout the total is top+1 cars.top = MAXNUM-1)coutand
8、the park is full now!endl;elsecoutand the park have top position is empty !head-next;cout the ailse information is follow: endl;separator(30,-,1);coutnumber the intime endl;while(p != NULL)ime);p=p-next;elsecoutthe ailse is empty !endl;separator(30,-,1);coutendl;/ show park and a
9、ilse /void showall(Seqstack *s,carnodequeue *q)showpark(s);showaisle(q);/ in park /void Inpark(Seqstack *s,carnodequeue *q)car cc;struct tm *gm_data;time_t seconds;time(&seconds); /get the timegm_data=gmtime(&seconds);coutthe number of car cc.num;ime=*gm_data;if(!Isfull(s) & carnodequeueisempt
10、y(q)cc.position=(s-top)+2;Stackpush(s,cc);showpark(s);else if(Isfull(s) | !carnodequeueisempty(q)coutthe park if full,the car can only park int the ailse .endl;cc.position=MAXNUM;carnodequeuein(q,cc);showall(s,q);/ the out park /void Outpark(Seqstack *s,carnodequeue *q)struct tm *gm_data;time_t seco
11、nds;Seqstack p;char nowtime10;int i,pos;car cc;Stackinit(&p);if(Isempty(s)coutthe park is empty,no car need to leave .endl;exit(0);elsecoutthe park information is follow.endl;showpark(s);coutwhich one need to leave ?pos;if(pos 0 & postop+1)for(i=s-top+1;ipos;i-)cc=Stackpop(s);cc.position=cc.position
12、-1;Stackpush(&p,cc);cc=Stackpop(s);time(&seconds);gm_data = gmtime(&seconds);cc.outime=*gm_data;cc.length=mktime(&cc.outime)-mktime(&ime);cc.expense=(cc.length/3600 + 1)*PRICE;coutthe information which car is to leave is follow.endl;coutcc.num cc.length cc.expenseendl;while(! Isempty(&p)cc=Sta
13、ckpop(&p);Stackpush(s,cc);while(!Isempty(s) & !carnodequeueisempty(q)cc=carnodequeueout(q);time(&seconds);gm_data=gmtime(&seconds);ime=*gm_data;Stackpush(s,cc);elsecoutthe car position is wrong!endl;主函數調用為:#include stdafx.h#include example34_car.hint main()Seqstack Park;carnodequeue Aisle;Stackinit(&Park);carnodequeueinit(&Aisle);char choice;do coutendlendl;separator(10,-,0);coutthe management of parkendl;separator(30,-,1);cout1. the car in endl;cout2. the car out endl;cout3. watch the park information endl;cout0. exitendl;separator(56,-,1);coutthe total is MAXNUM position and ca
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 六一玩具活動方案
- 六一糖果畫活動方案
- 六一藝術派對活動方案
- 六一節小學活動方案
- 六一贈圖書活動方案
- 六一音樂沙龍活動方案
- 六中垃圾分類活動方案
- 六公司招待所團購活動策劃方案
- 六年級數學小組活動方案
- 理財試題及答案
- 數學教師個人述職報告總結
- 森林防滅火應急處置課件
- 貢菜的栽培技術
- (高清版)DB51∕T 1292-2011 牧草種質資源田間鑒定與評價技術規程
- 2024年11月-礦山隱蔽致災因素普查
- 刷單合同范本
- CNAS-CL02-A001:2023 醫學實驗室質量和能力認可準則的應用要求
- 《造血干細胞移植護理》課件
- 2025年非法集資課件:制作與投資者教育新思路
- 北京昌平小升初數學試卷
- 新外研社高中英語選擇性必修一單詞表
評論
0/150
提交評論