


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、C語言課程設(shè)計(jì)院系:資源學(xué)院姓名:學(xué)號(hào):班號(hào): 指導(dǎo)教師:日期:機(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ù)約,若無則提供最近空機(jī)時(shí)間段.另:若用戶要求在非空時(shí)間上機(jī),則將用戶信息插入該 時(shí)間段的等待列表.(3) 退出預(yù)定,根據(jù)輸入的時(shí)間,撤消該時(shí)間的餓預(yù)定.(4) 查詢是否有等待信息,若有則按順序顯示聯(lián)系方式,若無則顯示提示信息.二.需求分析根據(jù)題目要求,需要提供機(jī)位信息和預(yù)約信息,應(yīng)該用鏈表來存儲(chǔ),應(yīng)提供指 針的操作:在程序中,需
2、要查詢是否有空機(jī)位和等待者和處理預(yù)約和取消預(yù)約問題 應(yīng)提供查詢,顯示,預(yù)定,刪除,修改等操作;另外還要提供鍵盤式選擇菜單實(shí)現(xiàn)功能 選擇.二.總體設(shè)計(jì)現(xiàn)在分析整個(gè)一下整個(gè)系統(tǒng),根據(jù)上面的需求分析,可以將這個(gè)系統(tǒng)的設(shè)計(jì)分 為如下六大模塊:查詢我的預(yù)約狀態(tài),查詢空位,預(yù)約,取消預(yù)約,排隊(duì),查詢等待信四詳細(xì)設(shè)計(jì)1宏定義【分析】由題可知,結(jié)構(gòu)函數(shù)包含學(xué)生信息:機(jī)位,學(xué)號(hào),還有下名學(xué)生信息;學(xué)生時(shí) 間(LENGTH段順序:人數(shù),第一名學(xué)生,排隊(duì)的學(xué)生,最后一名學(xué)生。 需要建立能存儲(chǔ)多種變量的結(jié)構(gòu)體#i nclude<stdio.h>#i nclude<stdlib.h>訪問動(dòng)態(tài)內(nèi)存
3、的頭文件#i ncludevstri ng.h>初始化頭文件#define LENGTH 6/* 總時(shí)段數(shù) */#defi ne MAX 2#define S(r) (r-8)/2/*計(jì)算在哪個(gè)時(shí)段數(shù)*/#defi ne NULL 0struct xinxi int jiwei;char xuehao10;/*學(xué)號(hào),假設(shè)為聯(lián)系方式*/struct xinxi *n ext;struct xinxi *head;struct cellint CNum;/*連接在該時(shí)段頭結(jié)點(diǎn)的總機(jī)器數(shù)目*/struct xinxi *first;/*struct xinxi *middle;/* struc
4、t xinxi *last;/* TimeQueueLENGTH;指向整個(gè)隊(duì)列的開頭*/ 指向等待預(yù)約隊(duì)列*/ 指向整個(gè)隊(duì)列的結(jié)尾*/,只提供輸入,處理和輸出部分的函數(shù)調(diào)用其中個(gè)功Y2.主函數(shù)主函數(shù)一般設(shè)計(jì)的比較簡(jiǎn)潔 能模塊用菜單方式選擇。根據(jù)n的值調(diào)用各功能模塊函數(shù)【程序】imai n()/*int i;for(i=0;i<LENGTH;i+)/* TimeQueuei.CNum=O; TimeQueuei.first=NULL;.主函*初始化*/(定義)TimeQueuei.middle=NULL;TimeQueuei.last=NULL;while(1)prin tf("
5、Please choice your nu mber!:n");prin tf("1.Search my book ing state 2.Search empty place 3.Book4.Ca ncel book ing 5.Wait ing 6.Search wait ingn ”);sca nf("%d",&i);/*選擇功能*/switch(i)case 1:1 nqu ir_book in g();break; /*case 2:i nquir_exist in g();break; /*case 3:book in g();bre
6、ak; /*case 4:ca ncel();break; /*case 5:wait in g();break; /*case 6:i nquir_waiti ng();break;/*default:pri ntf("errorin");3.各功能模塊設(shè)計(jì)查詢我的狀態(tài)模塊*/ 查詢空位模塊*/ 預(yù)約模塊*/ 取消預(yù)約模塊*/排隊(duì)模塊*/查詢等待信息模塊*/(1)查詢我的狀態(tài)模塊數(shù)據(jù)結(jié)構(gòu)我的原始數(shù)據(jù)是預(yù)約者預(yù)約的信息,將它儲(chǔ)存在用指針處理的鏈表中?!痉治觥扛鶕?jù)輸入的時(shí)間來判斷應(yīng)該查詢的結(jié)構(gòu)體,把其首地址賦給Rem,然后通過指針的移動(dòng),比較輸入的學(xué)號(hào)和存儲(chǔ)在該結(jié)構(gòu)體中的Re
7、m->data,來判斷我的預(yù)約狀態(tài)流程圖【程序】void Inq uir_book in g() 一int n;int i;char In for10;( 學(xué)號(hào))struct xi nxi *q;struct xi nxi *Rem;prin tf("Please in put the time you want to search!(24 xiao shi zhi between8 and 20 o ' clock,include 8o' clock)n");scan f("%d",&n);if(n >=8&
8、&n< 20)n=S( n);prin tf("Please in put your school-nu mber!n");scan f("%s",xuehao);Rem=TimeQueue n.first;q=Rem;for(i=1;q=Rem,Rem=Rem->n ext,i+)if(strcmp(Rem->xuehao,l nfor)=0)break;if(Rem->jiwei!=0)prin tf("The computer nu mber you have duri ng this period per
9、iod is %dn",Rem->jiwei);else printf("Sorry,you are still in the waiting queue!");else prin tf("Error.Please in put aga in.n")(2)查詢空機(jī)位模塊分析根據(jù)輸入的時(shí)間確定n值,然后根據(jù)結(jié)構(gòu)體中TimeQueue中的 TimeQueue n->C num的值,求出最大值與該值的差即為空機(jī)位數(shù)。流程圖【程序】void inqui r_exist in g() _int n;prin tf("Please i
10、n put the time you want to search.(24 hours 824o' clock,include 8 scan f("%d",&n); clock)n");if(n >=8&&n< 20)n=S( n);if(TimeQueue n.CNum<MAX)prin tf("Thereare %demoty computer.n",MAX-TimeQueue n.CNum);else prin tf("Sorry!There is no empty comput
11、er!' n");else prin tf("Error.Please in put aga in.n ”);(3)預(yù)約模塊數(shù)據(jù)結(jié)構(gòu)定義兩個(gè)指向結(jié)構(gòu)體的指針,用強(qiáng)制類型轉(zhuǎn)換使他們指向動(dòng)態(tài)分配的存儲(chǔ) 空間的首地址,把預(yù)約者的信息儲(chǔ)存在其中一個(gè)結(jié)構(gòu)體中。分析在該模塊的設(shè)計(jì)中,要讓預(yù)約者按預(yù)約的順序儲(chǔ)存在結(jié)構(gòu)體中。當(dāng)預(yù)約者的 總數(shù)小于最大值時(shí),就要用到通過指針的移動(dòng)來把預(yù)約者的信息按順序儲(chǔ)存起 來,用兩個(gè)不同的指針分別指向鏈表的開始,鏈表的結(jié)尾處。流程圖把預(yù)約者信息儲(chǔ)存在鏈表的第把預(yù)約者的信息插入到鏈表的表 尾void book in g()/*/int n;char I
12、n for10;struct xi nxi *Rem;struct xi nxi *p;prin tf("Please in put the time you want to book!n");scan f("%d",&n);if(n >=8&&n< 20)n=S( n);if(TimeQueue n.CNum<MAX)prin tf("Please in put your No.!n");scan f("%s",l nfor);if(TimeQueue n.first=N
13、ULL)Rem=(struct xinxi *)malloc(sizeof(struct xin xi);(malloc:“動(dòng)態(tài)內(nèi)存分配,當(dāng)無法知道內(nèi)存具體位置的時(shí)候, 想要綁定真正的內(nèi)存空間,就需 要用到動(dòng)態(tài)的分配內(nèi)存” )(sizeof(類型說明符,數(shù)組名或表達(dá)式);)Rem->jiwei=1;strcpy(Rem->xuehao,l nfor);Rem-> next=NULL;TimeQueue n.first=Rem;TimeQueue n.last=Rem;TimeQueue n.CNum+;prin tf("Succeed to book!n"
14、);elseRem=(struct xinxi *)malloc(sizeof(struct xin xi);strcpy(Rem->xuehao,I nfor);Rem-> next=NULL;p=TimeQueue n.last;Rem->jiwei=TimeQueue n.CNum+1;prin tf("%d",Rem->jiwei);TimeQueue n.last=Rem;p->n ext=Rem;TimeQueue n.CNum+;prin tf("Succeed to book!n");else prin tf
15、("There is no empty computer!' n");else prin tf("Error.Please in put aga in.n ”);排隊(duì)模塊分析該模塊主要是針對(duì)是否要排隊(duì)和如何排隊(duì)設(shè)計(jì)的。當(dāng)預(yù)約者總數(shù)小于最 大值時(shí)提示不用排隊(duì)。當(dāng)預(yù)約者的總數(shù)大于最大值時(shí)就需要排隊(duì)。把排隊(duì)者的 信息儲(chǔ)存在由指向結(jié)構(gòu)體的指針指向的動(dòng)態(tài)分配的存儲(chǔ)區(qū)域,然后連接到 TimeQueue n的表尾。用指向等待隊(duì)列的指針指向排隊(duì)的第一人,通過指針的 移動(dòng),用指向表尾的指針指向真?zhèn)€鏈表的結(jié)尾。流程圖【程序】void waiti ng()/*/int n;ch
16、ar In for10; struct xinxi *Rem;struct xinxi *p;printf("Please input the time you want to wait!n"); scanf("%d",&n);if(n>=8&&n<20)n=S(n);if(TimeQueuen.CNum>=MAX)printf("Please input your No!n"); scanf("%s",Infor);if(TimeQueuen.CNum)=MAX)Rem=
17、(struct xinxi *)malloc(sizeof(struct xinxi); strcpy(Rem->xuehao,Infor);Rem->next=NULL;Rem->jiwei=0;p=TimeQueuen.last;TimeQueuen.last=Rem; p->next=Rem;TimeQueuen.middle=Rem;TimeQueuen.CNum+; printf("Succeed to in the queue。 n");elseRem=(struct xixni *)malloc(sizeof(struct xinxi)
18、; strcpy(Rem->xuehao,Infor);Rem->next=NULL;Rem->jiwei=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
19、");(5)取消預(yù)約模塊 分析 要取消預(yù)約,有兩種情況,第一是從有機(jī)位的人要取消預(yù)約,在該種情況 下,排隊(duì)的第一人的位置就插入到該取消者的位置。而指向等待隊(duì)列首地址的 指針就指向原來排隊(duì)的第二人。第二種情況就是取消預(yù)約的人本來就在等待隊(duì) 列中,只需要直接刪除該結(jié)點(diǎn)即可。流程圖【程序】void can cel()int n;int i;/*記載刪除點(diǎn)的隊(duì)列位置*/char In for10;struct xi nxi *Rem;struct xi nxi *q;struct xi nxi *p;prin tf("Please in put the time you have
20、booked.' n);scan f("%d",&n);if(n >=8&&n< 20)prin tf("Please in put your No.!n");scan f("%s",l nfor);n=S( n);Rem=TimeQueue n.first;q=Rem;for(i=1;q=Rem,Rem=Rem->n ext,i+)if(strcmp(Rem->xuehao,l nfor)=0)break;if(i>MAX)/*注意退出預(yù)定的情況包括退出在等待隊(duì)列中預(yù)定的
21、情況!*/if(Rem-> next=NULL)q-> next=NULL;TimeQueue n.last=q;free(Rem);TimeQueue n.CNum-;printf( “ Succeed to out the queue!' n");elseq->n ext=Rem->n ext;free(Rem);TimeQueue n.CNum-;prin tf("Succeed to out the queue!' n");elseif(TimeQueue n.CNum>MAX)TimeQueue n.midd
22、le->jiwei=Rem->jiwei;TimeQueue n.middle=TimeQueue n.middle->n ext; if(i=1) TimeQueue n.first=Rem->n ext; else q->n ext=Rem->n ext; free(Rem);TimeQueue n.CNum-;prin tf("Succeed to out the queue!' n");else prin tf("Error.Please in put aga in.'n ”);(6)查詢等待信息模塊分析
23、通過輸入的時(shí)間,判斷儲(chǔ)存該時(shí)間段的結(jié)構(gòu)體鏈表,通過比較TimeQueuen 中Cnum勺值與最大值的大小關(guān)系就可以得到是否有等待者的信息。流程圖根據(jù)n的值判斷TimeQueuen->Cnum的值 是否小于最大值MAX Y【程序】void inqui r_wait in g() _int n;struct xi nxi *q;prin tf("Please in put the time you want to search the waiter.'n"); scan f("%d",&n);if(n >=8&&n
24、< 20)n=S( n);if(TimeQueue n.CNum>MAX)prin tf("The waiter are:n");q=TimeQueue n.middle;for(;q->n ext!=NULL;q=q->n ext) prin tf("%sn",q->xuehao); prin tf("%sn",TimeQueue n.last->xuehao);else prin tf("There is no waiter duri ng this period!n");e
25、lse prin tf("Error.Please in put aga in.n ”);五.上機(jī)操作:(1)主菜單如下:(2)選3,進(jìn)入預(yù)約模塊:千:厚習(xí)責(zé)斜1專業(yè)竇料1程序直言血TOD«bug2KANGMA.ex9TIHleass input the niunherf:1, seArch my hooking state 2 searcJi «mpt compute* J,boating 5,qmeae 6.search uainting M-exit3P丄uAse input the tine 如a want tc book?12ELease input y
26、our No.!lZldb22bSfmcceed to book?Hlease inpuJt the numberT -1 - seai*Cli my boDingf State 2 -searcii cmpti computei' 3 .baoMmsf5.queue b.searcli uainting B-exit4. cancel booking4. cancel booking(3)選1,進(jìn)入“查詢我的預(yù)約狀態(tài)”模塊:(4)選2,進(jìn)入查詢空機(jī)位模塊:(5)選4,進(jìn)入取消預(yù)約模塊:C::岸H符料專+密料群序說言lc TCUlebuaHANGHAxe"(6)選5,進(jìn)入排隊(duì)
27、等待模塊:c:洋習(xí)嗇S每序謹(jǐn)肓TC41*hin'7HAmgjw.4捫2Please inputLilis time you want to<24 li-uureBolwck, include 8 u* gluck12TKe氓 are 19 Please inmit 1- search my0祈衛(wèi)1:* c>afiputei>* the number?: hooking 呂tat e 2 .scarelh empty0.exitcomputer3.booking4.cancel bookiny5 .queue 6 .seai'cli aimting4Please
28、 input the time12Please input youp No.T121Hb22bSucceed to exit booking?Please inpu Che numbteL甲:yL - seeurch rn* booking state 2 .searelh cm pt: y5 s<uicue G .scareli5Pleaeo input: tliEime you haue booked?waint; ingr 0 .exit;ine jiqu vant to queue!There ha)ue envtvPleaise input the1. search my bo
29、oking state 2 searcti empty5 .queue 6 *searcli wa in ting1 Oexitconputerfho waiting! nunher!:(7)選6,進(jìn)入查詢等待信息模塊:camputiBi*computer3 « booking3.booking4,4.cancel booking按任意鍵,則結(jié)束運(yùn)行,返回源程序六.總結(jié)通過這一周的C語言實(shí)習(xí),我在上機(jī)操作這一方面有了很大的進(jìn)步,對(duì) C 的理論知識(shí)的掌握也更加牢固。學(xué)會(huì)了把所學(xué)的知識(shí)用于實(shí)踐。七.源代碼#i nclude<stdio.h>#i nclude<stdli
30、b.h>#i nclude<stri ng.h>#defi ne LENGTH 6#defi ne MAX 20#defi ne S(r) (r-8)/2#defi ne NULL 0struct no dein t locat;char data10; struct node *n ext; ;struct node *head;struct cellint CNum;struct node *first;struct node *middle;struct node *last; TimeQueueLENGTH;void Inquir()int n;char Infor1
31、0;struct node *Rem;printf("Please input the time you want to search!(24 hours 820 o'clock,include 8o'clock)n");scanf("%d",&n);if(n>=8&&n<20)n=S(n);printf("Please input your No.!n");scanf("%s",Infor);Rem=TimeQueuen.first; for(;Rem->
32、next!=NULL;Rem=Rem->next) if(strcmp(Rem->data,Infor)=0)break;if(Rem->locat!=0)printf("The computer number is %dn",Rem->locat);else printf("Sorry,you are still in the queue or you haven't booked!");else printf("Error!Please input again.n");void inquir()in
33、t n;printf("Please input the time you want to search!(24 hours 820o'clock,include 8 o'clock)n");scanf("%d",&n);if(n>=8&&n<20)n=S(n);if(TimeQueuen.CNum<MAX)printf("There are %d empty computer!n",MAX-TimeQueuen.CNum); else printf("Sorry,t
34、here is no empty computer!n");else printf("Error!Please input again.n");void booking()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&&n<20)n=S(n);if(TimeQueuen.CNum<
35、MAX)printf("Please input your No.!n");scanf("%s",Infor);if(TimeQueuen.first=NULL)Rem=(struct node *)malloc(sizeof(struct node);Rem->locat=1;strcpy(Rem->data,Infor);Rem->next=NULL;TimeQueuen.first=Rem;TimeQueuen.last=Rem;TimeQueuen.CNum+;printf("Succeed to book!n&quo
36、t;);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
37、e in no empty computer!");else printf("Error!Please input again.n");void waiting()int n;char Infor10;struct node *Rem;struct node *p;printf("Please input the time you want to queue!n");scanf("%d",&n);if(n>=8&&n<20)n=S(n);if(TimeQueuen.CNum>=MAX
38、)printf("Please input your No.!n");scanf("%s",Infor);if(TimeQueuen.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+;pr
39、intf("Succeed to in the queue!n");elseRem=(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.CNum+;printf("Succeed to in the queue!n");else printf("There have
40、 empty computer!No waiting!n");else printf("Error!Please input again.n");void cancel()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&&n<20)printf(&q
41、uot;Please input your No.!n"); scanf("%s",Infor);n=S(n);Rem=TimeQueuen.first;q=Rem; for(i=1;q=Rem,Rem=Rem->next,i+) if(strcmp(Rem->data,Infor)=0)break;if(i>MAX)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"
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- c11h10o4的六元環(huán)化合物
- 深圳學(xué)??臻g施工方案
- 臺(tái)州混凝土破碎施工方案
- 2025年江蘇旅游職業(yè)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫含答案
- 2025年河北科技學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫匯編
- 2025年重慶財(cái)經(jīng)職業(yè)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫完整
- 2024新教材高中化學(xué) 第1章 第1節(jié) 走進(jìn)化學(xué)科學(xué)教學(xué)實(shí)錄 魯科版必修第一冊(cè)
- 在線教育平臺(tái)課程制作規(guī)范
- 農(nóng)業(yè)智慧農(nóng)場(chǎng)建設(shè)與管理方案
- 游戲行業(yè)產(chǎn)品測(cè)試與發(fā)布流程指南
- 中考物理復(fù)習(xí)歐姆定律復(fù)習(xí)講解學(xué)習(xí)
- 2025年春新外研版(三起)英語三年級(jí)下冊(cè)課件 Unit5第1課時(shí)Startup
- 優(yōu)生五項(xiàng)臨床意義
- 2024年池州職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫標(biāo)準(zhǔn)卷
- 事故隱患內(nèi)部報(bào)告獎(jiǎng)勵(lì)機(jī)制實(shí)施細(xì)則
- 小學(xué)六年級(jí)數(shù)學(xué)學(xué)情分析及提升方案
- 事業(yè)單位考試(公共基礎(chǔ)知識(shí))3000題每日練習(xí)
- 新會(huì)計(jì)法下加強(qiáng)企業(yè)財(cái)會(huì)監(jiān)督策略研究
- 人力資源社會(huì)保障宣傳工作計(jì)劃及打算
- 2024年秋兒童發(fā)展問題的咨詢與輔導(dǎo)終考期末大作業(yè)案例分析1-5答案
- 廣東省廣州市2021年中考道德與法治試卷(含答案)
評(píng)論
0/150
提交評(píng)論