數(shù)據(jù)結構停車場實驗報告_第1頁
數(shù)據(jù)結構停車場實驗報告_第2頁
數(shù)據(jù)結構停車場實驗報告_第3頁
數(shù)據(jù)結構停車場實驗報告_第4頁
數(shù)據(jù)結構停車場實驗報告_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

工商學院數(shù)據(jù)結構實驗報告年級2012學號2012007554姓名劉怡然成績專業(yè)電氣實驗地點B3-401指導教師許文強實驗項目模擬停車場管理程序的設計與實現(xiàn)實驗日期2013.11.7一、實驗目的本實驗的目的是進一步理解棧和隊列的邏輯結構和存儲結構,進一步提高使用理論知識指導解決實際問題的能力。二、實驗問題描述設停車廠只有一個可停放幾輛汽車的狹長通道,且只有一個大門可供汽車進出。汽車在停車場內按車輛到達的先后順序依次排列,若車場內已停滿幾輛汽車,則后來的汽車只能在門外的便道上等候,一旦停車場內有車開走,則排在便道上的第一輛車即可進入;當停車場內某輛車要離開時,由于停車場是狹長的通道,在它之后開入的車輛必須先退出車場為它讓路,待該車輛開出大門,為它讓路的車輛再按原次序進入車場。在這里假設汽車不能從便道上開走,試設計這樣一個停車廠模擬管理程序。為了以下描述的方便,停車廠的停車場用“停車位”進行敘述,停車廠的便道用“便道”進行敘述。三、實驗步驟1、實驗問題分析使用兩個棧和一個隊列。分別為停車棧和輔助棧,隊列為便道,當有車來時先進入停車場,沒有空位時不能進入,停入便道。當停車場有車要開出時,判斷它的后面有沒有車,沒有直接開出,否則將后面的車挪入輔助棧將目標車開出。再將輔助棧車按次序挪回停車棧。此時判斷便道上是否有車等待,有就將便道上的車按先到先出的次序停入停車場。功能(函數(shù))設計VoidMain();菜單stopping*init_stopping();初始化停車棧buffer*init_buff();初始化輔助棧pavement*init_pavement();初始化便道intcar_come(stopping*s,pavement*q);有來車intcar_leave(intpos,stopping*s,buffer*b,pavement*q);有車開走intstop_to_buff(intpos,stopping*s,buffer*b);停車棧挪向輔助棧intbuff_to_stop(stopping*s,buffer*b);輔助棧挪向停車棧intpave_to_stop(stopping*s,pavement*q);便道隊列挪向停車棧intcar_disp(stopping*s,pavement*q);顯示停車情況voidNow(stopping*s,pavement*q);實時統(tǒng)計停車數(shù)量實驗結果(程序)及分析實驗主要代碼car.h#pragmaoncetypedefstruct{ charlicense_plate[10];//車牌號 charstate;//狀態(tài)}car;Buffer.h#include"car.h"#include"stopping.h"typedefstruct{ carbufferx[MAX_STOP];/*各汽車信息的存儲空間*/ inttop;/*用來指示棧頂位置的靜態(tài)指針*/}buffer;Pavement.h#include"car.h"#defineMAX_PAVE100/*便道不限制停放車輛的數(shù)目,設為足夠大*/typedefstruct{ carpave[MAX_PAVE];/*各汽車信息的存儲空間*/ intfront,rear;/*用來指示隊頭和隊尾位置的靜態(tài)指針*/}pavement;Stopping.h#pragmaonce#include"car.h"#defineMAX_STOP5typedefstruct{ carstop[MAX_STOP];/*各汽車信息的存儲空間*/ inttop;/*用來指示棧頂位置的靜態(tài)指針*/}stopping;Main.cpp#include"buffer.h"#include"car.h"#include"pavement.h"#include"stopping.h"#include"iostream.h"#include"conio.h"#include"stdio.h"#include<stdlib.h>stopping*init_stopping();buffer*init_buff();pavement*init_pavement();intcar_come(stopping*s,pavement*q);intcar_leave(intpos,stopping*s,buffer*b,pavement*q);intstop_to_buff(intpos,stopping*s,buffer*b);intbuff_to_stop(stopping*s,buffer*b);intpave_to_stop(stopping*s,pavement*q);intcar_disp(stopping*s,pavement*q);voidNow(stopping*s,pavement*q);voidmain(){ intpos; stoppings;bufferb;pavementq; s=*init_stopping(); b=*init_buff(); q=*init_pavement(); charc; for(;;) { system("cls"); printf("\n________________"); printf("\n---------------------------|停車場管理系統(tǒng)|------------------------"); printf("\n^^^^^^^^^^^^^^^^\n\n"); cout<<"||--------------------------按0鍵結束程序----------------------||"<<endl; cout<<"||--------------------------按1鍵有車進入----------------------||"<<endl; cout<<"||--------------------------按2鍵有車離開----------------------||"<<endl; cout<<"||--------------------------按3鍵顯示情況----------------------||"<<endl; Now(&s,&q); c=getch(); if(c=='0') break; switch(c) { case'1': car_come(&s,&q); getch(); break; case'2': cout<<"請輸入開出車輛位置:"; cin>>pos; car_leave(pos,&s,&b,&q); getch(); break; case'3': car_disp(&s,&q); getch(); break; } }}voidNow(stopping*s,pavement*q){ printf("當前實時車輛統(tǒng)計:停車場----%d輛便道----%d輛\n",s->top+1,q->rear-q->front);}stopping*init_stopping(){ stopping*s; s=newstopping; if(!s) returnNULL; else { s->top=-1; returns; }}buffer*init_buff(){ buffer*b; b=newbuffer; if(!b) returnNULL; else { b->top=-1; returnb; }}pavement*init_pavement(){ pavement*q; q=newpavement; q->front=q->rear=-1; returnq;}intcar_come(stopping*s,pavement*q){ car*c; c=newcar; cout<<"請輸入汽車牌照號:"; cin>>c->license_plate; c->state='i'; if(s->top==MAX_STOP-1) { c->state='s'; q->rear++; q->pave[q->rear]=*c; cout<<"停車位滿!汽車"<<c->license_plate<<"停入便道。"<<endl; return1; } else { c->state='p'; s->top++; s->stop[s->top]=*c; cout<<"汽車"<<c->license_plate<<"停入停車場。停車位置"<<s->top+1<<"。"<<endl; return1; } return0;}intcar_leave(intpos,stopping*s,buffer*b,pavement*q){ car*c; c=newcar;if(pos-(s->top+1)>0) return0; elseif(pos-(s->top+1)==0) { *c=s->stop[s->top]; s->top--; cout<<"汽車"<<c->license_plate<<"已開出停車場。"<<endl; if(q->front==q->rear) return0; else pave_to_stop(s,q); } elseif(pos-(s->top+1)<0) { stop_to_buff(pos,s,b); *c=s->stop[s->top]; s->top--; cout<<"汽車"<<c->license_plate<<"已開出停車場。"<<endl; buff_to_stop(s,b); if(q->front==q->rear) return0; else pave_to_stop(s,q); } return1;}intstop_to_buff(intpos,stopping*s,buffer*b){ inti=s->top+1-pos; while(i) { if(b->top==MAX_STOP-1) return0; else { b->top++; b->bufferx[b->top]=s->stop[s->top]; cout<<"汽車"<<b->bufferx[b->top].license_plate<<"進入輔助停車位。"<<endl; s->top--;i--; } } return1;}intbuff_to_stop(stopping*s,buffer*b){ while(b->top!=-1) { s->top++; s->stop[s->top]=b->bufferx[b->top]; cout<<"汽車"<<b->bufferx[b->top].license_plate<<"由輔助停車位進入停車位"<<s->top+1<<"。"<<endl; b->top--; } return1;}intpave_to_stop(stopping*s,pavement*q){ if(q->front==q->rear&&s->top==-1) return0; else { q->front++; s->top++; s->stop[s->top]=q->pave[q->front]; cout<<"汽車"<<s->stop[s->top].license_plate<<"由便道進入停車位"<<s->top+1<<"。"<<endl; return1; }}intcar_disp(stopping*s,pavement*q){ cout<<"停車位的情況:"<<endl; for(inti=1;i<=s->top+1;i++) { cout<<i<<"車位----"<<s->stop[i-1].

溫馨提示

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

評論

0/150

提交評論