語言實習報告機房機位預約模擬_第1頁
語言實習報告機房機位預約模擬_第2頁
語言實習報告機房機位預約模擬_第3頁
語言實習報告機房機位預約模擬_第4頁
語言實習報告機房機位預約模擬_第5頁
已閱讀5頁,還剩14頁未讀 繼續免費閱讀

下載本文檔

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

文檔簡介

1、C語言課程設計機房機位預約模擬一. 題目要求20 臺機器,從早八點到晚八點 ,每兩個小時一個時間段 .需要實現的功能 :(1) 查詢 ,根據輸入的時間 ,輸出機位信息 .(2) 機位預定 ,根據輸入的日期和時間段查詢是否有空機位 ,若有則預約 ,若無則 提供最近空機時間段 .另 :若用戶要求在非空時間上機 ,則將用戶信息插入該 時間段的等待列表 .(3) 退出預定 ,根據輸入的時間 ,撤消該時間的餓預定 .(4) 查詢是否有等待信息 ,若有則按順序顯示聯系方式 ,若無則顯示提示信息 .二. 需求分析根據題目要求 ,需要提供機位信息和預約信息 ,應該用鏈表來存儲 ,應提供指 針的操作 :在程序中

2、 ,需要查詢是否有空機位和等待者和處理預約和取消預約問題 應提供查詢 ,顯示,預定 ,刪除,修改等操作 ;另外還要提供鍵盤式選擇菜單實現功能 選擇.三. 總體設計現在分析整個一下整個系統 ,根據上面的需求分析 ,可以將這個系統的設計分 為如下六大模塊 :查詢我的預約狀態 ,查詢空位 ,預約,取消預約 ,排隊,查詢等待信機房機位 模擬系統查詢空位預約取消預約排隊查詢等帶信息四.詳細設計1宏定義#include#include#include#define LENGTH 6/* 總時段數 */#define MAX 2#define S(r) (r-8)/2/* struct nodeint lo

3、cat;char data10;/* struct node *next; ; struct node *head; struct cellint CNum;/*計算在哪個時段數 */學號,假設為聯系方式 */struct node *first;/* struct node *middle;/* struct node *last;/* TimeQueueLENGTH;連接在該時段頭結點的總機器數目 */ 指向整個隊列的開頭 */ 指向等待預約隊列 */ 指向整個隊列的結尾 */2.主函數主函數一般設計的比較簡潔 能模塊用菜單方式選擇。,只提供輸入 ,處理和輸出部分的函數調用 .其中個功顯示

4、一系列功能信息Y輸入 n,判斷 n 是否是 0-6我的預約 狀態程序】main()查詢我的狀態模塊 */ 查詢空位模塊 */ 預約模塊 */ 取消預約模塊 */ 排隊模塊 */ 查詢等待信息模塊 */將它儲存在用指針處理的鏈表中根據 n 的值調用各功能模塊函數*主函數 */int i;for(i=0;idata,來判斷我的 預約狀態。 流程圖 void Inquir()int n;int i;char Infor10;struct node *q;struct node *Rem;printf(Please input the time you want to search!(24 xiao

5、shi zhi between8 and 20 o clock,include 8o clock)n);scanf(%d,&n);if(n=8&nnext,i+) if(strcmp(Rem-data,Infor)=0)break;if(Rem-locat!=0) printf(The computer number you have during thisperiodperiodis %dn,Rem-locat);else printf(Sorry,you are still in the waiting queue!);else printf(Error.Please input agai

6、n.n)(2) 查詢空機位模塊 分析 根據輸入的時間確定 n 值,然后根據結構體中 TimeQueue中的 TimeQueuen-Cnum的值,求出最大值與該值的差即為空機位數。 流程圖 空機位數 =MAX【程序】 void inquir()TimeQ提ue示u:e輸n入 錯誤,請重輸新輸出入:沒有空-CNum機位int n;printf(Please input the time you want to search.(24 hours 824 oclock,include 8clock)n);scanf(%d,&n);if(n=8&n20)n=S(n);if(TimeQueuen.CNum

7、Cnum 的值XY提示:已經沒有空機位輸入預約者的學號把預約者的信息插入到鏈表的表尾信息儲存在鏈表的第vo一id個 b結o點oking()/*/int n;char Infor10;struct node *Rem;struct node *p;printf(Please input the time you want to book!n);scanf(%d,&n);if(n=8&n20)n=S(n);if(TimeQueuen.CNumlocat=1; strcpy(Rem-data,Infor); Rem-next=NULL;TimeQueuen.first=Rem;TimeQueuen.

8、last=Rem;TimeQueuen.CNum+; printf(Succeed to book!n);elseRem=(struct node *)malloc(sizeof(struct node); strcpy(Rem-data,Infor);Rem-next=NULL;p=TimeQueuen.last;Rem-locat=TimeQueuen.CNum+1; printf(%d,Rem-locat);TimeQueuen.last=Rem; p-next=Rem;TimeQueuen.CNum+;printf(Succeed to book!n);else printf(Ther

9、e is no empty computer!n);else printf(Error.Please input again.n);(4) 排隊模塊 分析 該模塊主要是針對是否要排隊和如何排隊設計的。當預約者總數小于最 大值時提示不用排隊。 當預約者的總數大于最大值時就需要排隊。 把排隊者的信息儲存在由指向結構體的指針指向的動態分配的存儲區域,然后連接到TimeQueuen 的表尾。用指向等待隊列的指針指向排隊的第一人, 通過指針的移 動,用指向表尾的指針指向真個鏈表的結尾。 流程圖 輸入要查詢的時間 n判斷 n是否 820Y n s( n)提示:輸入錯誤請重新輸入根據 n 的值判斷 Time

10、Queuen-Cnum 的值 是否小于最大值 MAX提示: 還有空機位, 不需要排隊。YNCnum 是否 MAX把排隊者的信息聯接到隊尾處。N【程序】void waiting()/*/ int n;char Infor10; struct node *Rem;把排隊者的信息連接到鏈表的結尾處,即排隊的第一個struct node *p;printf(Please input the time you want to wait!n);scanf(%d,&n); if(n=8&n=MAX)printf(Please input your No!n); scanf(%s,Infor); if(Tim

11、eQueuen.CNum)=MAX)Rem=(struct node *)malloc(sizeof(struct node); strcpy(Rem-data,Infor);Rem-next=NULL;Rem-locat=0; p=TimeQueuen.last; TimeQueuen.last=Rem; p-next=Rem; TimeQueuen.middle=Rem; TimeQueuen.CNum+; printf(Succeed to in the queuen);elseRem=(struct node *)malloc(sizeof(struct node);strcpy(Re

12、m-data,Infor);Rem-next=NULL;Rem-locat=0;p=TimeQueuen.last;TimeQueuen.last=Rem;p-next=Rem;TimeQueuen.CNum+;printf(Succeed to in the queue。 n);else printf(There is still have empty computer。 No wait ! );else printf(Error.Please input again.n);(5) 取消預約模塊 分析 要取消預約,有兩種情況, 第一是從有機位的人要取消預約, 在該種情況下, 排隊的第一人的位

13、置就插入到該取消者的位置。 而指向等待隊列首地址的指針就 指向原來排隊的第二人。 第二種情況就是取消預約的人本來就在等待隊列中, 只 需要直接刪除該結點即可。 流程圖 int n;int i;/* 記載刪除點的隊列位置 */char Infor10;struct node *Rem;struct node *q;struct node *p;printf(Please input the time you have booked.n); scanf(%d,&n); if(n=8&nnext,i+) if(strcmp(Rem-data,Infor)=0)break;if(iMAX)/* 注意退

14、出預定的情況包括退出在等待隊列中預定的情況! */ if(Rem-next=NULL)q-next=NULL; TimeQueuen.last=q; free(Rem);TimeQueuen.CNum-;printf( “ Succeed to out the queue!n); else q-next=Rem-next; free(Rem);TimeQueuen.CNum-; printf(Succeed to out the queue!n); else if(TimeQueuen.CNumMAX)TimeQueuen.middle-locat=Rem-locat; TimeQueuen.

15、middle=TimeQueuen.middle-next;if(i=1) TimeQueuen.first=Rem-next; else q-next=Rem-next; free(Rem);TimeQueuen.CNum-; printf(Succeed to out the queue!n);else printf(Error.Please input again.n);(6) 查詢等待信息模塊 分析 通過輸入的時間, 判斷儲存該時間段的結構體鏈表, 通過比較 TimeQueuen 中 Cnum的值與最大值的大小關系就可以得到是否有等待者的信息。 流程圖 輸入要查詢的時間 n判斷 n是否

16、 820Nns( n)提示:輸入錯誤請重新輸入根據 n 的值判斷 TimeQueuen-Cnum 的值Y 是否小于最大值 MAX Y N序】 沒有等待者 inquir waiting()有等待者int n;struct node *q;printf(Please input the time you want to search the waiter.n); scanf(%d,&n);if(n=8&nMAX)printf(The waiter are:n);q=TimeQueuen.middle; for(;q-next!=NULL;q=q-next) printf(%sn,q-data); printf(%sn,TimeQueuen.last-data);else printf(There is no waiter during this

溫馨提示

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

評論

0/150

提交評論