

下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、機(jī)房機(jī)位預(yù)約模擬一.題目要求20 臺(tái)機(jī)器,從早八點(diǎn)到晚八點(diǎn),每?jī)蓚€(gè)小時(shí)一個(gè)時(shí)間段.需要實(shí)現(xiàn)的功能:(1)查詢,根據(jù)輸入的時(shí)間,輸出機(jī)位信息.(2)機(jī)位預(yù)定,根據(jù)輸入的日期和時(shí)間段查詢是否有空機(jī)位,若有則預(yù)約,若無(wú)則提供最近空機(jī)時(shí)間段.另:若用戶要求在非空時(shí)間上機(jī),則將用戶信息插入該 時(shí)間段的等待列表.(3)退出預(yù)定,根據(jù)輸入的時(shí)間,撤消該時(shí)間的預(yù)定.(4)查詢是否有等待信息,若有則按順序顯示聯(lián)系方式,若無(wú)則顯示提示信息.二.需求分析根據(jù)題目要求,在程序中應(yīng)實(shí)現(xiàn)查詢,機(jī)位預(yù)定,插入等待列表,退出預(yù)定,查 詢等待信息等功能。還應(yīng)提供鍵盤(pán)式選擇菜單實(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ì)得比較簡(jiǎn)潔, 只提供輸入, 處理和輸出部分的函數(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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)級(jí)2025年大數(shù)據(jù)存儲(chǔ)與管理最佳實(shí)踐研究報(bào)告
- 山東威海市14中學(xué)2024-2025學(xué)年九年級(jí)化學(xué)第一學(xué)期期末達(dá)標(biāo)測(cè)試試題含解析
- 沈陽(yáng)職業(yè)技術(shù)學(xué)院《高等藥物分析》2023-2024學(xué)年第一學(xué)期期末試卷
- 河南鹿邑老君臺(tái)中學(xué)2024年數(shù)學(xué)七年級(jí)第一學(xué)期期末檢測(cè)試題含解析
- 武漢工程科技學(xué)院《預(yù)防醫(yī)學(xué)與公共衛(wèi)生規(guī)培》2023-2024學(xué)年第一學(xué)期期末試卷
- 哈爾濱市平房區(qū)2025屆八上數(shù)學(xué)期末綜合測(cè)試模擬試題含解析
- 北京培黎職業(yè)學(xué)院《書(shū)法鑒賞》2023-2024學(xué)年第一學(xué)期期末試卷
- 成都工業(yè)職業(yè)技術(shù)學(xué)院《學(xué)校體育》2023-2024學(xué)年第一學(xué)期期末試卷
- 清包合同范本
- 山東省泰安市岱岳區(qū)2025屆七年級(jí)數(shù)學(xué)第一學(xué)期期末學(xué)業(yè)質(zhì)量監(jiān)測(cè)試題含解析
- 廣州市藝術(shù)中學(xué)招聘教師考試真題2024
- 工業(yè)自動(dòng)化設(shè)備保修及維修管理措施
- 期末作文預(yù)測(cè)外研版七年級(jí)英語(yǔ)下冊(cè)
- 2025-2030中國(guó)兒童魚(yú)油行業(yè)銷售動(dòng)態(tài)及競(jìng)爭(zhēng)策略分析報(bào)告
- 統(tǒng)編版五年級(jí)升六年級(jí)語(yǔ)文暑期銜接《課外閱讀》專項(xiàng)測(cè)試卷及答案
- 護(hù)理事業(yè)十五五發(fā)展規(guī)劃(2026-2030)
- 中國(guó)教育學(xué)會(huì)會(huì)員申請(qǐng)表
- 黃大年式教師團(tuán)隊(duì)申報(bào)
- 新冀人版小學(xué)科學(xué)三年級(jí)下冊(cè)全冊(cè)教案(2022年春修訂)
- 工作場(chǎng)所空氣中有害物質(zhì)監(jiān)測(cè)的采樣規(guī)范
- 國(guó)家開(kāi)放大學(xué)電大《可編程控制器應(yīng)用》機(jī)考2套真題題庫(kù)及答案10
評(píng)論
0/150
提交評(píng)論