停車場管理程序_第1頁
停車場管理程序_第2頁
停車場管理程序_第3頁
停車場管理程序_第4頁
停車場管理程序_第5頁
已閱讀5頁,還剩1頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、#include #include #include #define max 2 /*車庫容量 */ #define price 0.05 /* 每車每分鐘費用*/ typedef struct time int hour; int min; time; /* 時間結(jié)點 */ typedef struct node char num10; time reach; time leave; carnode; /* 車輛信息結(jié)點 */ typedef struct node carnode *stackmax+1; int top; seqstackcar; /* 模擬車站 */ typedef s

2、truct car carnode *data; struct car *next; queuenode; typedef struct node queuenode *head; queuenode *rear; linkqueuecar; /* 模擬通道 */ /*-*/ void initstack(seqstackcar *); /*初始化棧 */ int initqueue(linkqueuecar *); /*初始化便道 */ int arrival(seqstackcar *,linkqueuecar *); /*車輛到達(dá) */ void leave(seqstackcar *,

3、seqstackcar *,linkqueuecar *); /*車輛離開 */ void list(seqstackcar,linkqueuecar); /*顯示存車信息*/ /*-*/ void main() seqstackcar enter,temp; linkqueuecar wait; int ch; initstack(&enter); /*初始化車站 */ initstack(&temp); /*初始化讓路的臨時棧*/ initqueue(&wait); /*初始化通道 */ while(1) printf(n1. the car arrive); pr

4、intf( 2. the car leave); printf( 3. the schedule ); printf( 4. outn); while(1) scanf(%d,&ch); if(ch=1&chtop=0; for(i=0;istacks-top=null; int initqueue(linkqueuecar *q) /*初始化便道 */ q-head=(queuenode *)malloc(sizeof(queuenode); if(q-head!=null) q-head-next=null; q-rear=q-head; return(1); else r

5、eturn(-1); void print(carnode *p,int room) /*打印出站車的信息*/ int a1,a2,b1,b2; printf(nplease input thedepart time:/*:*/); scanf(%d:%d,&(p-leave.hour),&(p-leave.min); printf(nthe number of the car:); puts(p-num); printf(nthe time the car arrive: %d:%d,p-reach.hour,p-reach.min); printf(the depart t

6、ime: %d:%d,p-leave.hour,p-leave.min); a1=p-reach.hour; a2=p-reach.min; b1=p-leave.hour; b2=p-leave.min; printf(nthe fee: %2.1f元 ,(b1-a1)*60+(b2-a2)*price); free(p); int arrival(seqstackcar *enter,linkqueuecar *w) /*車輛到達(dá) */ carnode *p; queuenode *t; p=(carnode *)malloc(sizeof(carnode); flushall(); pr

7、intf(ninput the number of the car(例:陜 a1234):); gets(p-num); if(enter-toptop+; printf(nthe place of the car.,enter-top); printf(nthe time thecar arrive:/*:*/); scanf(%d:%d,&(p-reach.hour),&(p-reach.min); enter-stackenter-top=p; return(1); else /*車場已滿,車進(jìn)便道*/ printf(n 該車須在便道等待!); t=(queuenode

8、*)malloc(sizeof(queuenode); t-data=p; t-next=null; w-rear-next=t; w-rear=t; return(1); void leave(seqstackcar *enter,seqstackcar *temp,linkqueuecar *w) /* 車輛離開 */ int i, room; carnode *p,*t; queuenode *q; /*判斷車場內(nèi)是否有車*/ if(enter-top0) /* 有車 */ while(1) /* 輸入離開車輛的信息*/ printf(n 請輸入車在車場的位置/1-%d/ :,enter

9、-top); scanf(%d,&room); if(room=1&roomtop) break; while(enter-toproom) /*車輛離開 */ temp-top+; temp-stacktemp-top=enter-stackenter-top; enter-stackenter-top=null; enter-top-; p=enter-stackenter-top; enter-stackenter-top=null; enter-top-; while(temp-top=1) enter-top+; enter-stackenter-top=temp-s

10、tacktemp-top; temp-stacktemp-top=null; temp-top-; print(p,room); /*判斷通道上是否有車及車站是否已滿*/ if(w-head!=w-rear)&enter-tophead-next; t=q-data; enter-top+; printf(n 便道的 %s 號車進(jìn)入車場第%d 位置.,t-num,enter-top); printf(n 請輸入現(xiàn)在的時間/*:*/:); scanf(%d:%d,&(t-reach.hour),&(t-reach.min); w-head-next=q-next; if(

11、q=w-rear) w-rear=w-head; enter-stackenter-top=t; free(q); else printf(n 便道里沒有車.n); else printf(n 車場里沒有車.); /* 沒車 */ void list1(seqstackcar *s) /* 列表顯示車場信息*/ int i; if(s-top0) /* 判斷車站內(nèi)是否有車*/ printf(n 車場 :); printf(n 位置到達(dá)時間車牌號 n); for(i=1;itop;i+) printf( %d ,i); printf(%d:%d ,s-stacki-reach.hour,s-st

12、acki-reach.min); puts(s-stacki-num); else printf(n 車場里沒有車); void list2(linkqueuecar *w) /*列表顯示便道信息*/ queuenode *p; p=w-head-next; if(w-head!=w-rear) /*判斷通道上是否有車*/ printf(n 等待車輛的號碼為:); while(p!=null) puts(p-data-num); p=p-next; else printf(n 便道里沒有車.); void list(seqstackcar s,linkqueuecar w) int flag,tag; flag=1; while(flag) printf(n 請選擇1|2|3:); printf(n1. 車場 n2.便道 n3.返回 n); while(1) scanf(%

溫馨提示

  • 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

提交評論