(精品論文)數(shù)據(jù)結構課程設計_第1頁
(精品論文)數(shù)據(jù)結構課程設計_第2頁
(精品論文)數(shù)據(jù)結構課程設計_第3頁
(精品論文)數(shù)據(jù)結構課程設計_第4頁
(精品論文)數(shù)據(jù)結構課程設計_第5頁
已閱讀5頁,還剩83頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

Harbin Institute of Technology at Weihai數(shù)據(jù)結構課程設計報告設計題目: 電梯模擬系統(tǒng) 院 系: 計算機科學與技術學院 班 級: 學 號: 設 計 者: 哈爾濱工業(yè)大學(威海)二零零七年七月I哈爾濱工業(yè)大學(威海)計算機學院數(shù)據(jù)結構課程設計驗收及成績評定表(項目組)項目名稱電梯模擬系統(tǒng)職責學 號姓 名主 要 分 工組長安文龍050410126全部成員成員成員設計開始日期2007-7-3項目完成日期2007-7-15文 檔 評 審 成 績 (共50分)評審項目評審內容成績標準評審成績項目名稱課題是否從實際出發(fā),是否具有創(chuàng)意等20文檔格式文檔格式是否規(guī)范;文字是否規(guī)范;圖表是否規(guī)范;術語是否準確等10分文檔質量程序設計思想與整體框架是否清晰等20分文檔總體評價總成績程 序 功 能 完 備 性 評 審 成 績 (共 50 分)評審項目評 審 內 容成績標準評審成績程序運行狀況程序是否能正常運行;是否出現(xiàn)死鎖;是否遇到錯誤而中止運行10分程序正確性對于給定的輸入數(shù)據(jù),是否能得到正確的輸出結果15分程序與文檔的一致性程序與各種文檔的內容是否一致5 分程序的代碼量程序代碼量的大小10分實現(xiàn)方法圖形界面或命令行界面,美觀程度5分實現(xiàn)語言面向過程或面向對象5分程序總體評價總成績哈爾濱工業(yè)大學(威海)課程設計任務書 姓 名: 安文龍 學 號:050410126院(系): 計算機科學與技術學院 專 業(yè):計算機科學與技術學院 任務起止日期:2007 年 7 月 3 日 至 2007年 7 月 15 日 課程設計題目:電梯模擬系統(tǒng) 問題闡述與分析: 電梯是我們日常生活中不可或缺的一種重要工具。電梯的運行是電梯與大樓及各個樓層的使用者互相交互的過程,而相應的電梯模擬就是對這一交互過程進行實際模擬,已達到運載客戶的功能。本程序運用時鐘控件解決對各個樓層請求的響應順序問題。本次程序的核心算法是處理電梯在某一時刻的狀態(tài)、動作以及對下一時刻的狀態(tài)和動作作出預測和判斷。程序的重點在于確定電梯的各個狀態(tài)以及運行方向,處理各種請求,對每一個動作和狀態(tài)的時間進行處理。其它的活動體如乘客則相對獨立,處理起來更為容易一些。 某7層高的樓,設有載客電梯1部。其具體功能如下:(1) 電梯的運行規(guī)則是:可到達每層。(2) 模擬開始時,電梯隨機地處于其符合運行規(guī)則的任意一層,為空梯。(3) 按下“外請求”按鈕,表示用戶的申請,電梯將根據(jù)申請情況運行。(4) 按下“內請求”按鈕,表示用戶在電梯內部的操作。(5) 當電梯響應完全部請求后,電梯將自動關門并在終止層等待。(6) 電梯可以隨時顯示其當前信息,如所在樓層,運動狀態(tài)等。 工作量:1. 設計可視化操作界面;2. 電梯時鐘設計3. 電梯門開關設計4. 乘客請求,電梯響應設計II哈爾濱工業(yè)大學(威海)課程設計報告(論文)數(shù)據(jù)結構課程設計報告軟硬件運行環(huán)境語言:Delphi運行環(huán)境:Delphi 7.0硬件:無要求 問題及難點所在本次程序的難點是處理電梯在某一時刻的狀態(tài)、動作以及對下一時刻的狀態(tài)和動作作出預測和判斷。程序的重點在于確定電梯的各個狀態(tài)以及運行方向,處理各種請求,對每一個動作和狀態(tài)的時間進行處理。其它的活動體如乘客則相對獨立,處理起來更為容易一些。由于電梯運行情況比較復雜,所以采用面向對象的編程語言,使程序實現(xiàn)起來比較簡單,并且界面也比較容易設計。 算法設計的思想1、初始化初始化電梯基本信息,如運動狀態(tài),所在層數(shù),是否收到請求等。 2、響應各請求 響應前先判斷電梯對應此時刻的運動狀態(tài),若此時處于停留在某一樓層,則先判斷目標運動方向是否相同,若相同,則采用就近原則,若目標運動方向不相同,則采用先請求先響應原則。若此時處于運動狀態(tài),則要考慮請求是內部請求還是外部請求。總的原則是若有內部請求,則先響應。只有內部請求時,采用最短路程原則。在內部響應進行時,若有外部請求,則要判斷其外部請求的運動方向是否與電梯運動方向相同,若相同,則響應外部請求。否則等內部請求響應完成后再響應外部請求。3、輸出信息 通過Delphi編譯出可視化界面,形象地輸出電梯基本信息,如運動狀態(tài),所在層數(shù),開關門狀態(tài)等。 算法的流程圖開 始先請求先響應響應最短路程請求判斷是內請求還是外請求響應結束判斷電梯是否正在運動判斷是否有請求電梯信息初始化并等待請求 N Y N Y 外請求判斷是否有與運動方向相同請求 內請求 N先請求先響應 Y圖一:算法流程圖 算法的設計與分析private mshowin:boolean; /判斷Groupboxin是否可見 mshowout:boolean; /判斷Groupboxout是否可見 canmove:boolean; /用來延遲一會循環(huán) whichclick:integer; /判斷是開門還是關門 imagel:integer; /門圖片的left imagew:integer; /門圖片的Width elet:integer; /eleshape的top doorready:boolean; /電梯門是否準備好 elemove:boolean; /電梯是否運動 movedrect:integer; /電梯運動方向 elelocatefloor:integer; /電梯所在樓層 nowcall:integer; /現(xiàn)在幾樓要求電梯運動 targetfloor:integer; /電梯運動的目標樓層 mincallup:integer; /電梯外部向下運動的最低樓層 maxcalldown:integer; /電梯外部向上運動的最高樓層 targetobject:integer; /電梯內部要求運動的樓層 nowtarget:integer; /現(xiàn)在電梯內部要求運動的樓層 downarray:array2.7 of boolean; /外部向下運動的按紐 uparray:array1.6 of boolean; /外部向上運動的按紐 targetarray:array1.7 of boolean; /內部運動的按紐 procedure waittwosecond(); /等待2秒,一等待過程,不一定是1秒 procedure waitonesecond(); /等待1秒,同上 procedure dooropenclose(); /開門關門動作 procedure eleincall(now:integer); /電梯里面要求運動 procedure eleoutcall(now:integer); /電梯外面要求運動 procedure lighton(nowstate:integer); /點亮所在樓層字體 procedure lightoff(nowstate:integer); /關掉所在樓層字體 procedure downoff(nowstate:integer); /關掉向下按紐 procedure upoff(nowstate:integer); /關掉向上按紐 procedure targetoff(nowstate:integer); /關掉內部按紐 procedure doorbitopen(); /實現(xiàn)開門動作 procedure doorbitclose(); /實現(xiàn)關門動作 procedure wait3sec(); /實現(xiàn)等待3秒 procedure waitformove(); /用來等待shape的運動 procedure showin(); /用來使groupboxin可見 procedure showout(); /用來使groupboxout可見 procedure lightofftarget(); /用來是關掉內部按紐顏色 Function moverequire():integer; /運動一回合后是否還要運動 Function getnowcallup():boolean; /是否還有向上的請求 Function getnowcalldown():boolean; /是否還有向下的請求 function getinman(sender:Tobject): integer;/計算進入電梯人數(shù) function getoutman(sender:Tobject):integer;/計算走出電梯人數(shù) 運行結果與分析(測試)運行成功后界面如下:圖二:初始化界面(2)圖三: 電梯運動界面(1)圖四: 電梯開門界面(3) 總結(收獲與體會)在兩周內就完成了數(shù)據(jù)結構課程設計。雖然課程設計已告一段落,但是還有好多東西需要去調試,學習。通過這次設計,我學到了許多書本上學不到的知識,增強了自己的動手能力,熟悉了Delphi語言。我十分珍惜這次鍛煉的機會,我如期的完成了自己的設計任務,但由于知識水平有限,仍然存在很多的不足之處。今后在學習其他專業(yè)課時,我會珍惜每一次上機機會,鍛煉自己的動手能力,加強專業(yè)知識,以適應畢業(yè)后從事計算機等方面的工作。 附:源代碼unit unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;type TForm1 = class(TForm) GroupBox1: TGroupBox; floor7: TLabel; floor2: TLabel; floor1: TLabel; floor5: TLabel; floor3: TLabel; floor4: TLabel; floor6: TLabel; GroupBox2: TGroupBox; eledoorstate: TLabel; eledown2: TBitBtn; eleup2: TBitBtn; eleup3: TBitBtn; eledown3: TBitBtn; eledown4: TBitBtn; eleup4: TBitBtn; eledown5: TBitBtn; eleup5: TBitBtn; eleup6: TBitBtn; eledown6: TBitBtn; eledown7: TBitBtn; target7: TBitBtn; target6: TBitBtn; target1: TBitBtn; target4: TBitBtn; target5: TBitBtn; target2: TBitBtn; target3: TBitBtn; doorclose: TBitBtn; eleup1: TBitBtn; doortimer: TTimer; eletimer: TTimer; dooropen: TBitBtn; about: TButton; exitdemo: TButton; GroupBox3: TGroupBox; elelocate1: TLabel; elestate2: TLabel; elemovedown1: TLabel; elemoveup1: TLabel; GroupBoxin: TGroupBox; manin1: TRadioButton; manin6: TRadioButton; GroupBoxout: TGroupBox; manout1: TRadioButton; manout6: TRadioButton; manin2: TRadioButton; manin7: TRadioButton; manin3: TRadioButton; manin8: TRadioButton; manin4: TRadioButton; manin9: TRadioButton; manin5: TRadioButton; manin10: TRadioButton; manout2: TRadioButton; manout3: TRadioButton; manout4: TRadioButton; manout5: TRadioButton; manout7: TRadioButton; manout8: TRadioButton; manout9: TRadioButton; manout10: TRadioButton; Panel1: TPanel; Panel2: TPanel; eleShape: TShape; doorimage: TImage; doorocTimer: TTimer; ElemoveTimer: TTimer; waitTimer: TTimer; GroupBox4: TGroupBox; elestate3: TLabel; elemoveup2: TLabel; elemovedown2: TLabel; elelocate2: TLabel; procedure doorcloseClick(Sender: TObject); procedure dooropenClick(Sender: TObject); procedure doortimerTimer(Sender: TObject); procedure target1Click(Sender: TObject); procedure target3Click(Sender: TObject); procedure target2Click(Sender: TObject); procedure target4Click(Sender: TObject); procedure target5Click(Sender: TObject); procedure target6Click(Sender: TObject); procedure target7Click(Sender: TObject); procedure eledown7Click(Sender: TObject); procedure eledown6Click(Sender: TObject); procedure eledown5Click(Sender: TObject); procedure eledown4Click(Sender: TObject); procedure eledown3Click(Sender: TObject); procedure eledown2Click(Sender: TObject); procedure eleup1Click(Sender: TObject); procedure eleup2Click(Sender: TObject); procedure eleup3Click(Sender: TObject); procedure eleup4Click(Sender: TObject); procedure eleup5Click(Sender: TObject); procedure eleup6Click(Sender: TObject); procedure eletimerTimer(Sender: TObject); procedure FormCreate(Sender: TObject); procedure aboutClick(Sender: TObject); procedure exitdemoClick(Sender: TObject); procedure doorocTimerTimer(Sender: TObject); procedure ElemoveTimerTimer(Sender: TObject); procedure waitTimerTimer(Sender: TObject); private Private declarations mshowin:boolean; /判斷Groupboxin是否可見 mshowout:boolean; /判斷Groupboxout是否可見 canmove:boolean; /用來延遲一會循環(huán) whichclick:integer; /判斷是開門還是關門 imagel:integer; /門圖片的left imagew:integer; /門圖片的Width elet:integer; /eleshape的top doorready:boolean; /電梯門是否準備好 elemove:boolean; /電梯是否運動 movedrect:integer; /電梯運動方向 elelocatefloor:integer; /電梯所在樓層 nowcall:integer; /現(xiàn)在幾樓要求電梯運動 targetfloor:integer; /電梯運動的目標樓層 mincallup:integer; /電梯外部向下運動的最低樓層 maxcalldown:integer; /電梯內部要求運動的樓層 nowtarget:integer; /電梯外部向上運動的最高樓層 targetobject:integer; /現(xiàn)在電梯內部要求運動的樓層 downarray:array2.7 of boolean; /外部向下運動的按紐 uparray:array1.6 of boolean; /外部向上運動的按紐 targetarray:array1.7 of boolean; /內部運動的按紐 procedure waittwosecond(); /等待2秒,一個等待過程,不一定是一秒 procedure waitonesecond(); /等待1秒,同上 procedure dooropenclose(); /開門關門動作 procedure eleincall(now:integer); /電梯里面要求運動 procedure eleoutcall(now:integer); /電梯外面要求運動 procedure lighton(nowstate:integer); /點亮所在樓層字體 procedure lightoff(nowstate:integer); /關掉所在樓層字體 procedure downoff(nowstate:integer); /關掉向下按紐 procedure upoff(nowstate:integer); /關掉向上按紐 procedure targetoff(nowstate:integer); /關掉內部按紐 procedure doorbitopen(); /實現(xiàn)開門動作 procedure doorbitclose(); /實現(xiàn)關門動作 procedure wait3sec(); /實現(xiàn)等待3秒 procedure waitformove(); /用來等待shape的運動 procedure showin(); /用來使groupboxin可見 procedure showout(); /用來使groupboxout可見 procedure lightofftarget(); /用來是關掉內部按紐顏色 Function moverequire():integer; /運動一回合后是否還要運動 Function getnowcallup():boolean; /是否還有向上的請求 Function getnowcalldown():boolean; /是否還有向下的請求 function getinman(sender:Tobject): integer; /計算進入電梯的人數(shù) function getoutman(sender:Tobject):integer; /計算走出電梯的人數(shù) public Public declarations end;var Form1: TForm1;implementation$R *.DFMprocedure TForm1.lightofftarget(); /以下過程為初始化電梯內部按鈕顏色var i:integer;begin case movedrect of 1:begin for i:=elelocatefloor downto 1 do /向下運動 begin targetoff(i); targetarrayi:=False;end;end; -1:begin for i:=elelocatefloor to 7 do /向上運動 begin targetoff(i); targetarrayi:=False; end;end; end;end;procedure TForm1.showin();beginif mshowin=true then groupboxin.Visible:=True; /電梯外部有人響應時if mshowout=True then groupboxout.Visible:=True; /電梯內部有人響應時end;procedure TForm1.showout();beginmshowin:=False;mshowout:=False;Groupboxin.Visible:=False;Groupboxout.Visible:=False;end;function TForm1.getinman(Sender:Tobject):integer;beginwith Groupboxin do case (Sender as TRadioButton).tag of /進入電梯人數(shù)的設置 1:getinman:=1; 2:getinman:=2; 3:getinman:=3; 4:getinman:=4; 5:getinman:=5; 6:getinman:=6; 7:getinman:=7; 8:getinman:=8; 9:getinman:=9; 10:getinman:=10; end;end;function TForm1.getoutman(Sender:Tobject):integer;beginwith Groupboxout do case (Sender as TRadioButton).tag of /走出電梯的人數(shù) 1:getoutman:=1; 2:getoutman:=2; 3:getoutman:=3; 4:getoutman:=4; 5:getoutman:=5; 6:getoutman:=6; 7:getoutman:=7; 8:getoutman:=8; 9:getoutman:=9; 10:getoutman:=10; end;end; procedure TForm1.waitformove();beginelemove:=true; /若電梯開始運動,則其動態(tài)效果在時鐘控件作用下實現(xiàn)elemovetimer.Enabled:=True;end;procedure TForm1.wait3sec();beginwaittimer.Enabled:=True;end;procedure TForm1.doorbitopen();begindooroctimer.Enabled:=True;whichclick:=1; /開門狀態(tài)end;procedure TForm1.doorbitclose();begindooroctimer.Enabled:=True;whichclick:=-1; /關門狀態(tài)end;-初始狀態(tài)-procedure TForm1.FormCreate(Sender: TObject);beginshape 336 48137 imagel:=68; /對圖片進行初始化imagew:=1;Doorimage.Left:=imagel;Doorimage.Width:=imagew;Eleshape.Brush.Color:=clblue;elet:=288;eleshape.top:=elet;canmove:=True;elelocatefloor:=1;floor1.Font.color:=clred;elelocate1.font.color:=clred;elelocate2.font.color:=clred;elelocate1.caption:=inttostr(elelocatefloor);elelocate2.caption:=inttostr(elelocatefloor);doorready:=true;elemove:=false;movedrect:=0;mshowin:=False;mshowout:=False;Targetfloor:=1;end;-以下是定時器,實現(xiàn)2和1秒等待!-procedure TForm1.waittwosecond();begindoortimer.enabled:=True;end;procedure TForm1.waitonesecond();begineletimer.enabled:=true;end;-以下是開門和關門過程-procedure TForm1.dooropenclose();begineletimer.Enabled:=False;doorready:=false;dooropen.Font.color:=clred;doorclose.Font.color:=clwindowtext;eledoorstate.font.color:=clred;eledoorstate.caption:=正在開門!; /開門過程的實現(xiàn)showin();doorbitopen();waittwosecond();end;-定時器doortimer- procedure TForm1.doortimerTimer(Sender: TObject);beginif waittimer.Enabled=True then exit;if (elemove=true) and (dooroctimer.Enabled=True) then exit;eledoorstate.caption:= ;if doorready=true then doorclose.font.color:=clWindowtext;doortimer.enabled:=false;if doorready=false then begin eledoorstate.Font.color:=clred; dooropen.font.color:=clWindowtext; doorclose.font.color:=clred; eledoorstate.caption:=正在關門!; /關門過程的實現(xiàn) showout(); doorbitclose(); waittwosecond(); doorready:=true; if elelocatefloor=Targetfloor then begin if moverequire()=-1 then begin /還有向上的請求 elemoveup1.font.color:=clwindowtext; elemoveup2.font.color:=clwindowtext; eleoutcall(nowcall);end else if moverequire()=1 then begin /還有向下的請求 elemovedown1.font.color:=clwindowtext; elemovedown2.font.color:=clwindowtext; eleoutcall(nowcall);end;end; end;if eledoorstate.caption= then doorready:=true;if elelocatefloortargetfloor then begin doortimer.Enabled:=False; eletimer.Enabled:=True; end;if moverequire()=0 then begin /到達了目標層并且沒有請求 if dooroctimer.enabled=False then begin elemoveup1.font.color:=clwindowtext; elemoveup2.font.color:=clwindowtext; elemovedown1.font.color:=clwindowtext; elemovedown2.font.color:=clwindowtext; end; elemove:=False;end;end;-以下是click 實現(xiàn)開門-procedure TForm1.dooropenClick(Sender: TObject);begin if imagel=4 then exit; if elet mod 48 0 then exit; if dooroctimer.Enabled=true then dooroctimer.Enabled:=False; eledoorstate.font.color:=clred; dooropen.font.color:=clred; doorclose.font.color:=clWindowtext; eledoorstate.caption:=正在開門!; showin(); doorbitopen(); waittwosecond(); doorready:=false;end;-以下是click |=68 then exit; if elet mod 48 0 then exit; if dooroctimer.Enabled=true then dooroctimer.Enabled:=False; eledoorstate.font.color:=clred; dooropen.font.color:=clwindowtext; doorclose.font.color:=clred; eledoorstate.caption:=正在關門!; showout(); doorbitclose(); waittwosecond();end;-是否還有向上的請求- Function Tform1.getnowcallup():boolean;var i:integer;begingetnowcallup:=False;for i:=elelocatefloor to 7 do begin if targetarrayi=true then / 內部按鈕的運動 begin nowcall:=i; targetobject:=i; if nowcalli then nowcall:=i; getnowcallup:=True; end; if ii then nowcall:=i; getnowcallup:=True; end; end; if i1 then begin if downarrayi=true then /外部按鈕向下的運動 begin nowcall:=i; maxcalldown:=i; if nowcalli then nowcall:=i; get

溫馨提示

  • 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

提交評論