

下載本文檔
版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(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)查詢(xún),根據(jù)輸入的時(shí)間,輸出機(jī)位信息.(2)機(jī)位預(yù)定,根據(jù)輸入的日期和時(shí)間段查詢(xún)是否有空機(jī)位,若有則預(yù)約,若無(wú)則提供最近空機(jī)時(shí)間段.另:若用戶(hù)要求在非空時(shí)間上機(jī),則將用戶(hù)信息插入該 時(shí)間段的等待列表.(3)退出預(yù)定,根據(jù)輸入的時(shí)間,撤消該時(shí)間的預(yù)定.(4)查詢(xún)是否有等待信息,若有則按順序顯示聯(lián)系方式,若無(wú)則顯示提示信息.二.需求分析根據(jù)題目要求,在程序中應(yīng)實(shí)現(xiàn)查詢(xún),機(jī)位預(yù)定,插入等待列表,退出預(yù)定,查 詢(xún)等待信息等功能。還應(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)查詢(xún)模(A預(yù)訂模塊取消預(yù)訂模查詢(xún)等待信#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è)某天某人查詢(xún)時(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); /*查詢(xún)某時(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);/*查詢(xún)等待信息 */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)查詢(xún)函數(shù)流程圖調(diào)用 detail 函數(shù)返回主菜單puts(tt*n);/*查詢(xún)模塊*/*查詢(xú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 查詢(xún)等待信息模塊返回主菜單/* 查詢(xún)等待信息模塊 */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)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年廣西中考地理試題(含答案)
- ××中學(xué)法律合規(guī)制度
- 2025年新型皮革加脂劑項(xiàng)目提案報(bào)告模板
- 2025年水處理阻垢緩蝕劑HEDP項(xiàng)目提案報(bào)告模板
- 培訓(xùn)服務(wù)協(xié)議合同
- 2025年離子敏傳感器項(xiàng)目申請(qǐng)報(bào)告模板
- 品牌合作授權(quán)經(jīng)營(yíng)合同協(xié)議
- 2025年雅思考試口語(yǔ)全真模擬試卷:環(huán)保公益活動(dòng)策劃與實(shí)施案例分析提升試題
- 2025年茶藝師中級(jí)茶葉加工與儲(chǔ)藏技能鑒定理論試卷
- 2025年保育員實(shí)操技能試卷:幼兒教育心理學(xué)研究方法
- 產(chǎn)業(yè)命題賽道命題解決對(duì)策參考模板
- 985、211和雙一流大學(xué)名單
- 云南省昆明市官渡區(qū)2022-2023學(xué)年七年級(jí)下學(xué)期期末語(yǔ)文試題(含答案)
- 三人合伙經(jīng)營(yíng)協(xié)議書(shū)電子版(2篇)
- 汽車(chē)產(chǎn)品認(rèn)證
- 管道護(hù)理業(yè)務(wù)學(xué)習(xí)課件
- 新求精德語(yǔ)強(qiáng)化教程初級(jí)1(第四版)
- 蛇類(lèi)解剖生理特征(特種寵物疾病防治)
- 高中日語(yǔ)學(xué)習(xí)宣講+課件
- 年產(chǎn)10噸功能益生菌凍干粉的工廠(chǎng)設(shè)計(jì)改
- 國(guó)家開(kāi)放大學(xué)《高等數(shù)學(xué)基礎(chǔ)》形考任務(wù)1-4參考答案
評(píng)論
0/150
提交評(píng)論