版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C语言课程设计院系:资源学院姓名:学号:班号: 指导教师:日期:机房机位预约模拟一.题目要求20台机器,从早八点到晚八点,每两个小时一个时间段.需要实现的功能:(1) 查询,根据输入的时间,输出机位信息.(2) 机位预定,根据输入的日期和时间段查询是否有空机位,若有则预约,若无则提供最近空机时间段.另:若用户要求在非空时间上机,则将用户信息插入该 时间段的等待列表.(3) 退出预定,根据输入的时间,撤消该时间的饿预定.(4) 查询是否有等待信息,若有则按顺序显示联系方式,若无则显示提示信息.二.需求分析根据题目要求,需要提供机位信息和预约信息,应该用链表来存储,应提供指 针的操作:在程序中,需
2、要查询是否有空机位和等待者和处理预约和取消预约问题 应提供查询,显示,预定,删除,修改等操作;另外还要提供键盘式选择菜单实现功能 选择.二.总体设计现在分析整个一下整个系统,根据上面的需求分析,可以将这个系统的设计分 为如下六大模块:查询我的预约状态,查询空位,预约,取消预约,排队,查询等待信四详细设计1宏定义【分析】由题可知,结构函数包含学生信息:机位,学号,还有下名学生信息;学生时 间(LENGTH段顺序:人数,第一名学生,排队的学生,最后一名学生。 需要建立能存储多种变量的结构体#i nclude<stdio.h>#i nclude<stdlib.h>访问动态内存
3、的头文件#i ncludevstri ng.h>初始化头文件#define LENGTH 6/* 总时段数 */#defi ne MAX 2#define S(r) (r-8)/2/*计算在哪个时段数*/#defi ne NULL 0struct xinxi int jiwei;char xuehao10;/*学号,假设为联系方式*/struct xinxi *n ext;struct xinxi *head;struct cellint CNum;/*连接在该时段头结点的总机器数目*/struct xinxi *first;/*struct xinxi *middle;/* struc
4、t xinxi *last;/* TimeQueueLENGTH;指向整个队列的开头*/ 指向等待预约队列*/ 指向整个队列的结尾*/,只提供输入,处理和输出部分的函数调用其中个功Y2.主函数主函数一般设计的比较简洁 能模块用菜单方式选择。根据n的值调用各功能模块函数【程序】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.各功能模块设计查询我的状态模块*/ 查询空位模块*/ 预约模块*/ 取消预约模块*/排队模块*/查询等待信息模块*/(1)查询我的状态模块数据结构我的原始数据是预约者预约的信息,将它储存在用指针处理的链表中。【分析】根据输入的时间来判断应该查询的结构体,把其首地址赋给Rem,然后通过指针的移动,比较输入的学号和存储在该结构体中的Re
7、m->data,来判断我的预约状态流程图【程序】void Inq uir_book in g() 一int n;int i;char In for10;( 学号)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)查询空机位模块分析根据输入的时间确定n值,然后根据结构体中TimeQueue中的 TimeQueue n->C num的值,求出最大值与该值的差即为空机位数。流程图【程序】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)预约模块数据结构定义两个指向结构体的指针,用强制类型转换使他们指向动态分配的存储 空间的首地址,把预约者的信息储存在其中一个结构体中。分析在该模块的设计中,要让预约者按预约的顺序储存在结构体中。当预约者的 总数小于最大值时,就要用到通过指针的移动来把预约者的信息按顺序储存起 来,用两个不同的指针分别指向链表的开始,链表的结尾处。流程图把预约者信息储存在链表的第把预约者的信息插入到链表的表 尾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:“动态内存分配,当无法知道内存具体位置的时候, 想要绑定真正的内存空间,就需 要用到动态的分配内存” )(sizeof(类型说明符,数组名或表达式);)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 ”);排队模块分析该模块主要是针对是否要排队和如何排队设计的。当预约者总数小于最 大值时提示不用排队。当预约者的总数大于最大值时就需要排队。把排队者的 信息储存在由指向结构体的指针指向的动态分配的存储区域,然后连接到 TimeQueue n的表尾。用指向等待队列的指针指向排队的第一人,通过指针的 移动,用指向表尾的指针指向真个链表的结尾。流程图【程序】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)取消预约模块 分析 要取消预约,有两种情况,第一是从有机位的人要取消预约,在该种情况 下,排队的第一人的位置就插入到该取消者的位置。而指向等待队列首地址的 指针就指向原来排队的第二人。第二种情况就是取消预约的人本来就在等待队 列中,只需要直接删除该结点即可。流程图【程序】void can cel()int n;int i;/*记载删除点的队列位置*/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)/*注意退出预定的情况包括退出在等待队列中预定的
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、通过输入的时间,判断储存该时间段的结构体链表,通过比较TimeQueuen 中Cnum勺值与最大值的大小关系就可以得到是否有等待者的信息。流程图根据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 ”);五.上机操作:(1)主菜单如下:(2)选3,进入预约模块:flease input the number?:L” eAFch ny hooking state 'i. .seai*clicomputer J hooking 4. cancel bookintji.qmeue b.seaich uainting 0rexitJF丄eASe input the tine you want to took?12Please inpuJt your No . !Li!iab22b>mcce
26、ed ta bookTPlease input the numbeF!:L亠 search my booking state 2-search Empty computei' 3.hoDhing 4. cancel booking i-queue 6.search uainting 0_exit(3)选1,进入“查询我的预约状态”模块:(4)选2,进入查询空机位模块:(5)选4,进入取消预约模块:(6)选5,进入排队等待模块:(7)选6,进入查询等待信息模块:4. cancel hooking勺.canceJ bookingM p孝时資料I专业竇斜程序更言血ITC迪归bug) ZHAn
27、GIJA-exeThere are no waiter during Please input the numbei*!: 1. seArch ny booking state 5.queie b.search uintingthis period2.seaj*ch empty computer 3. booking M.exit4. cancel bookingrioa3e in put the t inc you Iwivo boo Jicd! 12input inur Nn.*tL search oi屮booking state2.seai'cli enpty coinpuiti
28、ei'3 booking4.cancel booking.queue G .sedLi*cliwainting.exitPlease in putthet iime youuant to queue?12rlheve haue emptycompiuiteF?NoLjalc LngifPlease input.thenumberT:tL.mybookxnt'Sr st;at;c2.scaimgIi enphy compuLtzcir*3 boojtj-n4.icancc 1 bookingsK . qiLLe%Le G .aeLi*c>kIng0-oxif;Pl Rase
29、 inputthetIms nuwant; tn 兴科界iif tluRi*R ai*fi12Thevenowaitep duringthis periodtFlease inputthenunberf:1, search 啊booking state2.search enptcompuitet*3.boohing4cancel booking111K225Succeed to exit bucking* Please input the number?5,queue 6,seeit*cJi tainting 0.exit 0euiyto rontfrm总按任意键,则结束运行,返回源程序六.总
30、结通过这一周的C语言实习,我在上机操作这一方面有了很大的进步,对 C 的理论知识的掌握也更加牢固。学会了把所学的知识用于实践。七.源代码#i nclude<stdio.h>#i nclude<stdlib.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
31、 CNum;struct node *first;struct node *middle;struct node *last; TimeQueueLENGTH;void Inquir()int n;char Infor10;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(
32、n);printf("Please input your No.!n");scanf("%s",Infor);Rem=TimeQueuen.first; for(;Rem->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 t
33、he queue or you haven't booked!");else printf("Error!Please input again.n");void inquir()int 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(TimeQueue
34、n.CNum<MAX)printf("There are %d empty computer!n",MAX-TimeQueuen.CNum); else printf("Sorry,there 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
35、 want to book!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.first=NULL)Rem=(struct node *)malloc(sizeof(struct node);Rem->locat=1;strcpy(Rem->data,Infor);
36、Rem->next=NULL;TimeQueuen.first=Rem;TimeQueuen.last=Rem;TimeQueuen.CNum+;printf("Succeed to book!n");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);Ti
37、meQueuen.last=Rem;p->next=Rem;TimeQueuen.CNum+;printf("Succeed to book!n");else printf("There 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 wan
38、t to queue!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=(struct node *)malloc(sizeof(struct node); strcpy(Rem->data,Infor);Rem->next=NULL;R
39、em->locat=0;p=TimeQueuen.last;TimeQueuen.last=Rem; p->next=Rem;TimeQueuen.middle=Rem;TimeQueuen.CNum+;printf("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=
40、Rem;p->next=Rem;TimeQueuen.CNum+;printf("Succeed to in the queue!n");else printf("There have 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("Plea
41、se input the time you have booked!n"); scanf("%d",&n);if(n>=8&&n<20)printf("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
42、->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");elseif(TimeQueuen.CNum>MAX) TimeQueuen.middle->locat=Rem->l
43、ocat; TimeQueuen.middle=TimeQueuen.middle->next;if(i=1) TimeQueuen.first=Rem->next;else q->next=Rem->next; free(Rem);TimeQueuen.CNum-; printf("Succeed to exit booking!n"); else printf("Error!Please input again.n");void inquir_waiting()int n;struct node *q; printf("Please input the time you want to search if there are waiter!n");scanf("%
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届新高考物理冲刺热点复习抛体运动
- 业余无线电A类操作证考试全题库及答案解析
- 工程发承包法律制度核心条款解析与实务
- 物联网控制反馈系统深度剖析
- 2025-2030家电品牌售后服务体系构建成本优化效率提升研究
- 2025-2030家用清洁机器人技术产业技术突破市场空间投资方向规划设计研究
- 2025-2030家居零售行业市场深度研究及品牌发展策略与资本运作研究报告
- 六复习与关联数量关系(课件)-数学人教版二年级上册
- 银行网银业务操作指南
- 早教家长交流会发言稿
- 咨询服务风险管理策略-洞察及研究
- 船舶阀件基础知识培训课件
- 户外电源技术讲解
- 立体停车设备质量控制管理文件范例
- 教学能力大赛备赛讲解
- 六年级语文阅读理解之托物言志(知识梳理技法点拨例文分析)(含答案)
- DB31∕T 1564-2025 企业实验室危险化学品安全管理规范
- 维修基金管理办法新疆
- 企业安全生产培训档案
- 工程机械安全操作规程
- 《移动通信技术》考试题库
评论
0/150
提交评论