版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
..②查看某個停車位的停車狀況:在用戶選擇該功能并且輸入4后,應(yīng)顯示:4車位上停著車牌號為JF004的車此函數(shù)原型為voidshow_stopping(inti,stack&s);顯示菜單讓用戶選擇功能。2、以上四個總體功能模塊要用到的棧和隊列的基本操作所對應(yīng)的主要函數(shù)如下表所示:函數(shù)原型函數(shù)功能voidinit_stack(stack&c);通過參數(shù)c來選擇初始化“停車位?!被颉拜o助?!眝oidinit_queue(queue&c);初始化“便道隊列”intpush_stack(stack&s,CAR&c);將車輛c壓入停車位棧s中intpush_queue(queue&q,CAR&c);將車輛c壓入便道q中voidshow_parking(stack&s,queue&e);打印停車位s和便道q上的車輛信息voidshow_stopping(inti,stack&s);打印停車位上的i車位的車輛信息intcar_leave(stack&s1,stack&s2,queue&q,char*c);先通過c查找出要開走的車輛在停車位的位置,先將其后方的車輛開到輔助棧中,等該車輛開走后,再把輔助棧中的車輛開回停車位,如便道有車,便把1位置的車開到停車位上其他函數(shù)的定義和說明請參照源代碼。3、由于程序應(yīng)該能夠隨時處理用戶所提出的各種操作請求,所以在主函數(shù)中用一個DO_WHILE循環(huán)結(jié)構(gòu)隨時監(jiān)控鍵盤的按鍵操作,遇到相應(yīng)的按鍵就轉(zhuǎn)到對應(yīng)函數(shù)繼續(xù)運行,運行完該函數(shù)繼續(xù)監(jiān)控鍵盤按鍵,如此往復(fù),直到接到“退出”指令程序才能結(jié)束。部分編碼如下: do{ menu(); cout<<"請輸入選擇"<<endl; cin>>key; while(key>5||key<1) { cout<<"輸入有誤,請重新輸入:"<<endl; cin>>key; } switch(key) { case1: { CARc; cout<<"請輸入該車車牌號:"<<endl; c.license=newchar[10]; cin>>c.license; c.state='i'; if(stopping.top!=max_stopping-1) push_stack(stopping,c); else push_queue(pavement,c); break; } case2: { char*s; cout<<"請輸入您要出站的汽車的車牌號:"<<endl; s=newchar[10]; cin>>s; car_leave(stopping,temp,pavement,s); break; } case3: { intlocation; cout<<"請輸入車位:"<<endl; cin>>location; show_stopping(location,stopping); break; }case4: { show_parking(stopping,pavement); break; } case5: { exit(0); } }; }while(key!=5); return1;}四、【界面設(shè)計】本程序的界面力求簡潔、友好,每一步需要用戶操作的提示以及每一次用戶操作產(chǎn)生的調(diào)度結(jié)果都以中文的形式顯示在屏幕上,使用戶對要做什么和已經(jīng)做了什么一目了然。文字表述精練,準(zhǔn)確。具體設(shè)計可參閱功能設(shè)計中的相關(guān)部分,這里就不再贅述。五、【編碼實現(xiàn)】#include<iostream.h>#include"string.h"#definemax_stopping5//車庫容量,可以根據(jù)實際情況改變#definemax_pavement100#include<stdlib.h>typedefstruct{ char*license;//汽車牌照號碼,定義為一個字符指針類型 charstate;//汽車當(dāng)前狀態(tài),字符S表示停放在停車位上, //字符p表示停放在便道上,每輛車的初始狀態(tài)用字符i來表示}CAR;typedefstruct{ CARcar[max_stopping];//各汽車信息的存儲空間 inttop;//用來指示棧頂位置的靜態(tài)指針}stack;typedefstruct{ CARcar[max_pavement];//各汽車信息的存儲空間 intfront,rear;//用來指示隊頭和隊尾位置的靜態(tài)指針}queue;/*方法聲明*/voidinit_stack(stack&c);//初始化棧voidinit_queue(queue&c);//初始化便道intpush_stack(stack&s,CAR&c);intpush_queue(queue&q,CAR&c);voidshow_parking(stack&s,queue&c);voidshow_stopping(inti,stack&s);intcar_leave(stack&s1,stack&s2,queue&q,char*c);//車輛離開voidinit_stack(stack&c){ for(inti=0;i<max_stopping;i++) { c.car[i].license=NULL; c.car[i].state='i'; } c.top=-1;}voidinit_queue(queue&c){ for(inti=0;i<max_pavement;i++) { c.car[i].license=NULL; c.car[i].state='i'; } c.front=c.rear=-1;}intpush_stack(stack&s,CAR&c){ if(s.top!=max_stopping) { s.top++; s.car[s.top].license=newchar[strlen(c.license)+1]; strcpy(s.car[s.top].license,c.license); cout<<"車牌號為"<<c.license<<"的車進入停車位的"<<s.top+1<<"車位上"<<endl; s.car[s.top].state='s'; return1; } else return0;}intpush_queue(queue&q,CAR&c){ if(q.rear!=max_pavement) { q.rear++; q.car[q.rear].license=newchar[strlen(c.license)+1]; strcpy(q.car[q.rear].license,c.license); q.car[q.rear].state='q'; cout<<"車牌號為"<<c.license<<"的車進入便道"<<endl; return1; } return0;}voidshow_parking(stack&s,queue&q){ inti; if(s.top==-1) { cout<<"停車場上沒有車"<<endl; return; } for(i=0;i<=s.top;i++) cout<<s.car[i].license<<"停車位的"<<i+1<<"車位"<<endl; if(q.front==q.rear) { cout<<"便道上沒有車"<<endl; return; }for(i=q.front+1;i<=q.rear;i++) cout<<q.car[i].license<<"便道上的"<<i+1<<"位置"<<endl;return;}voidshow_stopping(inti,stack&s){ if(i>max_stopping||i<1) { cout<<"此停車場上沒有該車位"<<endl; return; }if(s.car[i-1].license==NULL)cout<<"該車位沒有汽車"<<endl;elsecout<<i<<"車位上停著車牌號為"<<s.car[i-1].license<<"的車"<<endl;}intcar_leave(stack&s1,stack&s2,queue&q,char*c){ intlocation; for(inti=0;i<=s1.top;i++) { if(strcmp(s1.car[i].license,c)==0) { location=i; break; } } if(i>s1.top) { cout<<"停車位上沒有該車"<<endl; return0; } else { while(s1.top>location) { s2.top++; s2.car[s2.top].license=newchar[strlen(s1.car[s1.top].license)+1]; strcpy(s2.car[s2.top].license,s1.car[s1.top].license);s1.car[s1.top].license=NULL; cout<<"車牌號為"<<s2.car[s2.top].license<<"的車由停車位開到了輔助棧上"<<endl;s1.top--; } cout<<"車牌號為"<<s1.car[location].license<<"的車開走了"<<endl; s1.car[location].license=NULL; s1.top--; while(s2.top>=0) { s1.top++; s1.car[s1.top].license=newchar[strlen(s2.car[s2.top].license)+1]; strcpy(s1.car[s1.top].license,s2.car[s2.top].license); cout<<"車牌號為"<<s1.car[s1.top].license<<"的車由輔助棧開到了停車位的"<<s1.top+1<<"的車位上"<<endl;s2.car[s2.top].license=NULL; s2.top--; } if(q.front!=q.rear) { q.front++; s1.top++; s1.car[s1.top].license=newchar[strlen(q.car[q.front].license)+1]; strcpy(s1.car[s1.top].license,q.car[q.front].license); q.car[q.front].license=NULL; cout<<"便道上的"<<s1.car[s1.top].license<<"的停在了"<<max_stopping<<"車位上"<<endl; } return1; }} voidmenu(){ cout<<"·歡迎使用本程序·"<<endl;cout<<"1車輛到達;"<<endl; cout<<"2車輛離開;"<<endl; cout<<"3顯示某停車位上的汽車;"<<endl; cout<<"4顯示該停車場的停車狀況;"<<endl; cout<<"5退出程序;"<<endl;}intmain(){ intkey; stackstopping,temp; queuepavement; init_stack(stopping); init_stack(temp); init_queue(pavement); do{ menu(); cout<<"請輸入選擇"<<endl; cin>>key; while(key>5||key<1) { cout<<"輸入有誤,請重新輸入:"<<endl; cin>>key; } switch(key) { case1: { CARc; cout<<"請輸入該車車牌號:"<<endl; c.license=newchar[10]; cin>>c.license; c.state='i'; if(stopping.top!=max_stopping-1) push_stack(stopping,c); else push_queue(pavement,c); break; } case2: { char*s; cout<<"請輸入您要出站的汽車的車牌號:"<<endl; s=newchar[10]; cin>>s; car_leave(stopping,temp,pavement,s); break; } case3: { intlocation; cout<<"請輸入車位:"<<endl; cin>>location; show_stopping(location
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年分期影視節(jié)目錄制合同
- 2025年度個人濕地保護與恢復(fù)承包合同4篇
- 二零二五年度美容師職業(yè)技能培訓(xùn)及聘用合同4篇
- 2025年個人產(chǎn)權(quán)車位買賣合同模板2篇
- 2025年度個人信用擔(dān)保協(xié)議書-創(chuàng)業(yè)投資擔(dān)保3篇
- 影棚使用合作協(xié)議
- 2025個人購房定金合同范本7篇
- 2025水面承包權(quán)租賃與合作開發(fā)合同3篇
- 2025版?zhèn)€人房產(chǎn)購置定金協(xié)議3篇
- 2025年度個人聯(lián)保借款合同金融科技試點版3篇
- 高中物理競賽真題分類匯編 4 光學(xué) (學(xué)生版+解析版50題)
- 西方經(jīng)濟學(xué)-高鴻業(yè)-筆記
- 幼兒園美術(shù)教育研究策略國內(nèi)外
- 高中英語選擇性必修一單詞表
- 物業(yè)公司介紹
- 2024屆河南省五市高三第一次聯(lián)考英語試題及答案
- 【永輝超市公司員工招聘問題及優(yōu)化(12000字論文)】
- 孕婦學(xué)校品管圈課件
- 《愿望的實現(xiàn)》交流ppt課件2
- 中國直銷發(fā)展四個階段解析
- 2024屆浙江省寧波市鎮(zhèn)海區(qū)鎮(zhèn)海中學(xué)高一物理第一學(xué)期期末質(zhì)量檢測試題含解析
評論
0/150
提交評論