機房機位預約模擬系統(tǒng)—C語言課程設(shè)計_第1頁
機房機位預約模擬系統(tǒng)—C語言課程設(shè)計_第2頁
機房機位預約模擬系統(tǒng)—C語言課程設(shè)計_第3頁
機房機位預約模擬系統(tǒng)—C語言課程設(shè)計_第4頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、精品文檔機房機位預約模擬一題目要求20 臺機器 , 從早八點到晚八點 , 每兩個小時一個時間段 .需要實現(xiàn)的功能 :(1) 查詢 , 根據(jù)輸入的時間 , 輸出機位信息 .(2) 機位預定 , 根據(jù)輸入的日期和時間段查詢是否有空機位 , 若有則預約 , 若無則提供最近空機時間段 . 另 : 若用戶要求在非空時間上機 , 則將用戶信息插入該時間段的等待列表 .(3) 退出預定 , 根據(jù)輸入的時間 , 撤消該時間的預定 .(4) 查詢是否有等待信息 , 若有則按順序顯示聯(lián)系方式 , 若無則顯示提示信息 .二需求分析根據(jù)題目要求,在程序中應實現(xiàn)查詢,機位預定,插入等待列表,退出預定,查詢等待信息等功能

2、。 還應提供鍵盤式選擇菜單實現(xiàn)功能選擇。 而等待信息放在文件里,所以在相關(guān)的模塊應提供文件的輸入、輸出操作。三總體設(shè)計根據(jù)上面的需求分析,將這個系統(tǒng)的設(shè)計分為下面4 個模塊:機房機位預約模擬系統(tǒng)狀態(tài)查詢模預訂模塊取消預訂模查詢等待信塊塊息模塊4詳細設(shè)計1. 預處理命令及函數(shù)聲明。1歡迎下載精品文檔#include<stdio.h>#include<stdlib.h>#include<string.h>#define N 20#define T (time-8)/2int sum6=0;int computer620=1,1,1,1,1,1,0,0,0,0,0

3、,0,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,1,1,1, 1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1;/*該數(shù)組表示假設(shè)某天某人查詢時機房各個時間段機位數(shù)情況*/void Menu();void Situation();void Book();void C

4、ancel();void SearchWaiting();void Exit();void detail(int time);void printf_one(int i);struct waitlistchar number3;char telephonenumber12; waitN;2主函數(shù)主函數(shù)一般設(shè)計得比較簡潔,只提供輸入, 處理和輸出部分的函數(shù)調(diào)用。其中各功能模塊用菜單方式選擇。其流程圖如圖所示:。2歡迎下載精品文檔開始顯示一系列功能模塊N輸入 n 的值 1-5Y根據(jù)的值調(diào)用各功能模塊函數(shù)結(jié)束2./* 主函數(shù) */void main()Menu();/*當前狀態(tài)函數(shù) */void M

5、enu()/*主界面 */int n,w;doputs("tt*COMPUTER BOOK SYSTERM*n");puts("tt*MENU*n");。3歡迎下載精品文檔puts("ttt 1.Search the current situation"); /*查詢某時間段機位狀態(tài) */puts("ttt 2.Book the vacant computer");/*預定空機位 */puts("ttt 3.Cancel booking");/*取消預訂 */puts("ttt 4.S

6、earch waiting");/*查詢等待信息 */puts("ttt 5.Exit");/*退出 */puts("tt*n");printf("Choose your number(1-5): bb");scanf("%d",&n);if(n<1|n>5)w=1;getchar();elsew=0;while(w=1);switch(n)case 1:Situation();break;case 2:Book();break;case 3:Cancel();break;case 4

7、:SearchWaiting();break;case 5:Exit(0);break;3. 狀態(tài)查詢函數(shù)流程圖。4歡迎下載精品文檔開始輸入 1否輸入 time 的值 8-20是調(diào)用 detail 函數(shù)/* 查詢模塊 */* 查詢當前狀態(tài) */void Situation()返回主菜單int time;printf("Input time between (8-20):");scanf("%d",&time);if(time<8|time>20)printf("tWrong time!n");printf(&quo

8、t;Please input time between (8-20):");scanf("%d",&time);detail(time);/*函數(shù)調(diào)用 */getchar();Menu();4. 預定模塊函數(shù)流程圖開始。5歡迎下載精品文檔輸入時間 8-20調(diào)用 detail 函數(shù) ,sumT 的值改變執(zhí)行一個循環(huán),進輸出空機位數(shù),是否等待 SumT>0N入后面的時間段YN打開文本文件waitlist.txt ,輸入預定機位號和聯(lián)系方式,追加一個結(jié)構(gòu)體成員。返回主菜單程序:/* 預定模塊 */void Book()int time,i=0,x,y;。6

9、歡迎下載精品文檔FILE *fp;char c;printf("Input time you want to book between(8-20):");scanf("%d",&time);if(time<8|time>20)printf("tWrong time!n");printf("tInput time you want to book between(8-20):"); scanf("%d",&time);detail(time);/*函數(shù)調(diào)用 */if(s

10、umT>0) if(fp=fopen("waitlist.txt","a")=NULL)printf("nCannot open file!n"); exit(0);printf("ntPlease Input the number you want to book and leave your telephonenumber!:n");scanf("%s %s",waiti.number,waiti.telephonenumber); for(i=0;i<1;i+)fwrite(&

11、amp;waiti,sizeof(struct waitlist),1,fp);fclose(fp);/* 向文本文檔添加一個結(jié)構(gòu)體單元 */ printf("tInput the number you want to book again!n"); scanf("%d",&x);sumT-;/ *預定后該時間段空機位數(shù)減1*/computerTx=1;/ *預定后該機狀態(tài)變?yōu)?*/printf("tBook succeed!n");getchar();Menu();elseprintf("There is no v

12、acant computer at that time!n"); for(i=T+1;i<6;i+) time=9+2*i;detail(time); /*函數(shù)調(diào)用 */if(sumT>0)printf("tThe latest free time is %d,%dn",2*i+8,2*i+10);break;printf("tDo you want to wait?:y/n?");scanf("%s",&c);getchar();。7歡迎下載精品文檔if(c='Y'|c='y&#

13、39;)if(fp=fopen("waitlist.txt","r")=NULL)printf("nCannot open file!n");exit(0);else printf("waitlist : number telephonenumbern"); for(i=0;!feof(fp);i+)fscanf(fp,"%s %s",&waiti.number,&waiti.telephonenumber);fclose(fp);for(i=0;i<10;i+) prin

14、tf_one(i);printf("ntPlease Input the number you want to book and leave your telephonenumber!:n");if(fp=fopen("waitlist.txt","a")=NULL)printf("nCannot open file!n");exit(0);scanf("%s %s",waiti.number,waiti.telephonenumber);for(i=0;i<1;i+)fwrite(&am

15、p;waiti,sizeof(struct waitlist),1,fp);fclose(fp);/*若等待,就用文件的方式列出當時的等待列表并提示輸入你的等待序號和聯(lián)系方式*/printf("Input the number of the computer again!n");scanf("%d",&y);sumT-;computerTy=1;printf("tOk,please wait our phone!n");Menu();else Menu();。8歡迎下載精品文檔5,取消預訂模塊函數(shù)流程圖開始輸入時間8-20NY

16、輸入機位號調(diào)用 detail 函數(shù)該時間段空電腦數(shù)加1,所取消電腦號狀態(tài)變?yōu)?主菜單/* 取消預訂模塊 */void Cancel()int time,number;printf("Input time you have booked between(8-20):");scanf("%d",&time);if(time<8|time>20)。9歡迎下載精品文檔printf("tWrong time!n");printf("tInput time you have booked between(8-20):

17、"); scanf("%d",&time);elseprintf("tInput number you have booked :");scanf("%d",&number);detail(time);sumT+;/ *預定后該時間段空機位數(shù)加1*/computerTnumber=0;/ *預定后該機狀態(tài)變?yōu)?*/printf("tCancel succeed!n");getchar();Menu();6 查詢等待信息模塊開始流程圖N輸入時間 8-20Y打開文本文件,將文本文件轉(zhuǎn)化為二進制

18、文件輸出到屏幕上,顯示等待信息返回主菜單。10歡迎下載精品文檔/* 查詢等待信息模塊 */void SearchWaiting()int time,i;FILE *fp;printf("tInput time you want to search between(8-20):");scanf("%d",&time);if(time<8|time>20)printf("tWrong time!n");printf("tInput time you want to search between(8-20):&

19、quot;); scanf("%d",&time);else;if(fp=fopen("waitlist.txt","r")=NULL)printf("nCannot open file!n");exit(0);else printf("waitlist : number telephonenumbern"); for(i=0;!feof(fp);i+)fscanf(fp,"%s %s",&waiti.number,&waiti.telephonenumber);fclose(fp);fo

溫馨提示

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

最新文檔

評論

0/150

提交評論