

下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、機(jī)房機(jī)位預(yù)約模擬一.題目要求20 臺(tái)機(jī)器,從早八點(diǎn)到晚八點(diǎn),每兩個(gè)小時(shí)一個(gè)時(shí)間段.需要實(shí)現(xiàn)的功能:(1)查詢,根據(jù)輸入的時(shí)間,輸出機(jī)位信息.(2)機(jī)位預(yù)定,根據(jù)輸入的日期和時(shí)間段查詢是否有空機(jī)位,若有則預(yù)約,若無則提供最近空機(jī)時(shí)間段.另:若用戶要求在非空時(shí)間上機(jī),則將用戶信息插入該 時(shí)間段的等待列表.(3)退出預(yù)定,根據(jù)輸入的時(shí)間,撤消該時(shí)間的預(yù)定.(4)查詢是否有等待信息,若有則按順序顯示聯(lián)系方式,若無則顯示提示信息.二.需求分析根據(jù)題目要求,在程序中應(yīng)實(shí)現(xiàn)查詢,機(jī)位預(yù)定,插入等待列表,退出預(yù)定,查 詢等待信息等功能。還應(yīng)提供鍵盤式選擇菜單實(shí)現(xiàn)功能選擇。而等待信息放在文 件里,所以在相關(guān)的模
2、塊應(yīng)提供文件的輸入、輸出操作。二.總體設(shè)計(jì)根據(jù)上面的需求分析,將這個(gè)系統(tǒng)的設(shè)計(jì)分為下面 4 個(gè)模塊:機(jī)房機(jī)位預(yù)約模擬系統(tǒng)息模塊4.詳細(xì)設(shè)計(jì)1.預(yù)處理命令及函數(shù)聲明#include狀態(tài)查詢模(A預(yù)訂模塊取消預(yù)訂模查詢等待信#include #include#define N 20#define T (time-8)/2 int sum6=0;int computer620=1,1,1,1,1,1,0,0,0,0,0,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,
3、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í)機(jī)房各 個(gè)時(shí)間段機(jī)位數(shù)情況 */void Menu();void Situation();void Book();void Cancel();void SearchWaiting();void Exit();void detail(int time);void printf_one(int i) ; stru
4、ct waitlistchar number3;char telephonenumber12; waitN;2主函數(shù)主函數(shù)一般設(shè)計(jì)得比較簡潔, 只提供輸入, 處理和輸出部分的函數(shù)調(diào)用。其中各功能模塊用菜單方式選擇。其流程圖如圖所示:2./*主函數(shù)*/void mai n()Menu();/*當(dāng)前狀態(tài)函數(shù)*/void Men u()/* 主界面 */int n,w;doputs(tt*COMPUTERSYSTERM*n)puts(tt*MENU*n)puts(ttt 1.Search the current situation); /*查詢某時(shí)間段機(jī)位狀態(tài)BOOK*/puts(ttt 2.Boo
5、k the vacant computer);/*預(yù)定空機(jī)位 */puts(ttt 3.Cancel booking);/*取消預(yù)訂 */puts(ttt 4.Search waiting);/*查詢等待信息 */puts(ttt 5.Exit);/* 退出 */prin tf(Choose your number(1-5): bb); sca nf(%d,&n);if(n 5)w=1;getchar(); elsew=0;while(w=1); switch( n)case 1:Situati on( );break;case 2:Book();break;case 3:Ca nce
6、l();break;case 4:SearchWaiti ng();break;case 5:Exit(0);break;3.狀態(tài)查詢函數(shù)流程圖調(diào)用 detail 函數(shù)返回主菜單puts(tt*n);/*查詢模塊*/*查詢當(dāng)前狀態(tài)*/void Situati on()int time;prin tf(I nput time between (8-20):);sea nf(%d,& time);if(time20)pri ntf(tWro ng time!n);prin tf(Please in put time between (8-20):); sea nf(%d,&time
7、);detail(time);/* 函數(shù)調(diào)用 */getehar();Me nu();4.預(yù)定模塊函數(shù)流程圖調(diào)用 detail 函數(shù),sumT的值改變執(zhí)行一個(gè)循環(huán),進(jìn)入后面的時(shí)間段程序:/*預(yù)定模塊*/void Book()int time,i=0,x,y;FILE *fp;char c;prin tf(I nput time you want to book betwee n( 8-20):);sea nf(%d,& time);if(time20)prin tf(tWro ng time!n);prin tf(t In put time you want to book betwe
8、e n( 8-20):); scan f(%d, &time);detail(time);/* 函數(shù)調(diào)用 */if(sumT0)if(fp=fope n( waitlist.txt,a)=NULL)prin tf(nCannot ope n file!n);exit(0);prin tf(ntPlease In put the nu mber you want to book and leave yourtelephonenumber!:n);scanf(%s %s,waiti.number,waiti.telephonenumber); for(i=0;i1;i+)fwrite(&a
9、mp;waiti,sizeof(struct waitlist),1,fp); fclose(fp);/* 向文本文檔添加一個(gè)結(jié)構(gòu)體單元 */ printf(tInput the number you want to book again!n);scanf(%d,&x);sumT-; / * 預(yù)定后該時(shí)間段空機(jī)位數(shù)減 1*/ computerTx=1; / * 預(yù)定后該機(jī)狀態(tài)變?yōu)?1*/ printf(tBook succeed!n);getchar();Menu();elseprintf(There is no vacant computer at that time!n); for
10、(i=T+1;i0)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();if(c=Y|c=y)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,&am
11、p;waiti.number,&waiti.telephonenumber);fclose(fp);for(i=0;i10;i+) printf_one(i);printf(ntPlease Input the number you want to book and leave yourtelephonenumber!: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;i1;i+)
12、fwrite(&waiti,sizeof(struct waitlist),1,fp);fclose(fp); /* 若等待,就用文件的方式列出當(dāng)時(shí)的等 待列表并提示輸入你的等待序號(hào)和聯(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(); 5,取消預(yù)訂模塊函數(shù)流程圖/*取消預(yù)訂模塊*/void Can cel()int time ,nu mber;
13、prin tf(I nput time you have booked betwee n( 8-20):); sca nf(%d,& time);if(time20)prin tf(tWro ng time!n);prin tf(t In put time you have booked betwee n( 8-20):); scan f(%d, &time);elsepri ntf(tln put nu mber you have booked :); sca nf(%d,&n umber);detail(time);sumT+;/ *預(yù)定后該時(shí)間段空機(jī)位數(shù)加 1*/
14、computerTnumber=0;/ *預(yù)定后該機(jī)狀態(tài)變?yōu)?0*/prin tf(tCa ncel succeed!n);getchar();Me nu();6 查詢等待信息模塊返回主菜單/* 查詢等待信息模塊 */void SearchWaiting()int time,i;FILE *fp;printf(tInput time you want to search between(8-20):); scanf(%d,&time);if(time20)printf(tWrong time!n);printf(tInput time you want to search betwee
15、n(8-20):); scanf(%d,&time);elseJif(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;i10;i+) printf_one(i);Menu();7.公共函數(shù)程序void detail(int time) 和空機(jī)位號(hào)*/int i,j=0,k,s=0; int v30; for(i=0;i20;i+)if(computerTi=0) s+; vj+=i;sumT=s;printf(tCurrent vacant computers:%dn,sumT);for(k=0;kj;k+)printf(tThe vacant computers are:%dn,vk
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 人教版九年級(jí)數(shù)學(xué)上冊《21.3 實(shí)際問題與一元二次方程》同步測試題及答案
- 2025屆西藏拉薩市北京實(shí)驗(yàn)中學(xué)七年級(jí)數(shù)學(xué)第二學(xué)期期末綜合測試試題含解析
- 2025屆泰安市重點(diǎn)中學(xué)七下數(shù)學(xué)期末達(dá)標(biāo)檢測模擬試題含解析
- 客戶關(guān)系維護(hù)與拓展計(jì)劃
- 財(cái)務(wù)共享服務(wù)中心的建設(shè)與運(yùn)作計(jì)劃
- 大型演出的安保方案實(shí)施計(jì)劃
- 浙江省杭州西湖區(qū)杭州市公益中學(xué)2025年八年級(jí)數(shù)學(xué)第二學(xué)期期末檢測試題含解析
- 軟件設(shè)計(jì)師考試復(fù)習(xí)資料試題及答案
- 企業(yè)戰(zhàn)略目標(biāo)與風(fēng)險(xiǎn)承受能力評(píng)估試題及答案
- 開拓新思維的工作計(jì)劃
- 體育賽事經(jīng)濟(jì)影響評(píng)估模型-深度研究
- 2025年上海奉賢區(qū)社區(qū)工作者及事業(yè)單位招聘177人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 專題24-圖像題-中考化學(xué)重難點(diǎn)復(fù)習(xí)精講精練(上海專用)(原卷版)
- 小學(xué)一年級(jí)奧數(shù)經(jīng)典100試題(五篇)
- 2025年中國消防救援學(xué)院第二批面向應(yīng)屆畢業(yè)生招聘28人歷年管理單位筆試遴選500模擬題附帶答案詳解
- T-CIRA 46-2023 核電廠液態(tài)流出物中鍶89和鍶90分析 液體閃爍法
- 介入手術(shù)室感染控制管理
- 1學(xué)會(huì)尊重-尊重自己(說課稿 )-2023-2024學(xué)年道德與法治六年級(jí)下冊統(tǒng)編版
- 會(huì)計(jì)案例分析-終結(jié)性考核-國開(SC)-參考資料
- 中國近代史綱要北京航空航天大學(xué)練習(xí)題復(fù)習(xí)資料
- 裝飾材料供應(yīng)合同模板
評(píng)論
0/150
提交評(píng)論