版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上C语言程序设计编程实践是学习C语言程序设计的一重要环节,为提高学生程序设计能力,通过课堂和上机实践练习使学生的程序设计能力上一台阶。通过前四单元温顾而知新、庖丁解牛、举一反三、熟能生巧等过程的练习设计下面一个完整的程序1. 题目要求设计“机房机位预约模拟系统”要求:20台机器,从早8点到晚8点,每两个小时一个时间段。 需要实现功能: 1,查询,根据输入时间,输出机位信息。 2,即为预定,根据输入的日期和时间段查询是否有空机位,若有则预约,若无则提供最近空机时间段。另:若用户要求在非空时间上机,则将用户信息插入该时间段的等待列表. 3,退出预定,根据输入的时间,撤销该时
2、间的预定。 4,查询是否有等待的信息,若有则按顺序显示联系方式,若无则显示提示信息。 2需求分析根据题目要求在程序中需实现查询,预定,排队等功能的操作,所以需要建立相应的模块来实现;另外还需提供键盘式选择菜单实现功能,在运行时达到所要目的。 3总体设计整个系统可分为3个模块 查询模块 预定模块 取消模块机房机位预约模拟系统查询模块预定模块取消模块 详细设计 主函数比较简洁,只提供输入、功能处理和输出部分的函数调用。 显示一系列功能选择输入n,判断m 是否是0到6?根据n值调用各功能模块函数结束N开始main() int i; for(i=0;i<LENGTH;i+) TimeQueuei
3、.CNum=0; TimeQueuei.first=NULL; TimeQueuei.middle=NULL; TimeQueuei.last=NULL; while(1) printf("请输入序号!:n"); printf("1. 查询预定的机位 2.查询空机位 3.预定 4. 取消预定 5.等待列表 6.查询等待者列表 0.退出n"); scanf("%d",&i); switch(i) case 1:Inquir();break; case 2:inquir();break; case 3:booking();brea
4、k; case 4:cancel();break; case 5:waiting();break; case 6:inquir_waiting();break; case 0:exit(0); default:printf("errorn"); 开始输入查询序号或查询时间判断是否预定,是否有空余机位?显示数据结束Nvoid Inquir() int n; char Infor10; struct node *Rem; printf("输入查询时间(24 hours 820 o'clock,include 8o'clock)n"); sca
5、nf("%d",&n); if(n>=8&&n<20) n=S(n); printf("请输入学号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->l
6、ocat); else printf("对不起.你依旧在等待列表中或者没有预定"); else printf("错误,请再次输入.n"); void inquir() int n; printf("输入想要查询的时间(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("The
7、re are %d empty computer!n",MAX-TimeQueuen.CNum); else printf("对不起.没有空余机位n"); else printf("错误,再次输入.n"); 预定模块 void booking() 开始输入预定时间判断时间属于820 o'clock与空机位输入学号预定成功,排队成功结束iongyudinN选择排队 int n; char Infor10; struct node *Rem; struct node *p; printf("输入想要预定的时间n"); s
8、canf("%d",&n); if(n>=8&&n<20) n=S(n); if(TimeQueuen.CNum<MAX) printf("请输入你的学号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.
9、first=Rem; TimeQueuen.last=Rem; TimeQueuen.CNum+; printf("成功预定n"); else Rem=(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=Re
10、m; TimeQueuen.CNum+; printf("成功预定n"); else printf("没有空余机位!"); else printf("错误.请再次输入.n"); void waiting() int n; char Infor10; struct node *Rem; struct node *p; printf("请输入想要排队的时间n"); scanf("%d",&n); if(n>=8&&n<20) n=S(n); if(TimeQueu
11、en.CNum>=MAX) printf("请输入你的学号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; TimeQueue
12、n.CNum+; printf("成功排队n"); else 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.CNum+; printf("成功排队n"); else printf("有空余机位,无须等待n"); else prin
13、tf("错误.再次输入.n"); 取消模块 开始输入预定时间 判断是否预定与排队成功取消预定结束N void cancel() int n; int i; char Infor10; struct node *Rem; struct node *q; struct node *p; printf("请输入预定的时间n"); scanf("%d",&n); if(n>=8&&n<20) printf("Please input your No.!n"); scanf("%
14、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->n
15、ext; free(Rem); TimeQueuen.CNum-; printf("Succeed to out the queue!n"); else if(TimeQueuen.CNum>MAX) TimeQueuen.middle->locat=Rem->locat; TimeQueuen.middle=TimeQueuen.middle->next; if(i=1) TimeQueuen.first=Rem->next; else q->next=Rem->next; free(Rem); TimeQueuen.CNum-;
16、 printf("成功取消预定!n");附录源代码:#include<stdio.h> #include<stdlib.h> #include<string.h> #define LENGTH 6 #define MAX 20 #define S(r) (r-8)/2 #define NULL 0 struct node int locat; char data10; struct node *next; ; struct node *head; struct cell int CNum; struct node *first; stru
17、ct node *middle; struct node *last; TimeQueueLENGTH; void Inquir() int n; char Infor10; struct node *Rem; printf("输入查询时间(24 hours 820 o'clock,include 8o'clock)n"); scanf("%d",&n); if(n>=8&&n<20) n=S(n); printf("请输入学号n"); scanf("%s",In
18、for); 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("对不起.你依旧在等待列表中或者没有预定"); else printf("错误,请再次输入.n"); void inquir() int n; prin
19、tf("输入想要查询的时间(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("对不起.没有空余机位n"); else printf("错误,再
20、次输入.n"); void booking() int n; char Infor10; struct node *Rem; struct node *p; printf("输入想要预定的时间n"); scanf("%d",&n); if(n>=8&&n<20) n=S(n); if(TimeQueuen.CNum<MAX) printf("请输入你的学号n"); scanf("%s",Infor); if(TimeQueuen.first=NULL) Rem=(
21、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("成功预定n"); else Rem=(struct node *)malloc(sizeof(struct node); strcpy(Rem->data,Infor); Rem->next=NULL; p=TimeQ
22、ueuen.last; Rem->locat=TimeQueuen.CNum+1; printf("%d",Rem->locat); TimeQueuen.last=Rem; p->next=Rem; TimeQueuen.CNum+; printf("成功预定n"); else printf("没有空余机位!"); else printf("错误.请再次输入.n"); void waiting() int n; char Infor10; struct node *Rem; struct nod
23、e *p; printf("请输入想要排队的时间n"); scanf("%d",&n); if(n>=8&&n<20) n=S(n); if(TimeQueuen.CNum>=MAX) printf("请输入你的学号n"); scanf("%s",Infor); if(TimeQueuen.CNum)=MAX) Rem=(struct node *)malloc(sizeof(struct node); strcpy(Rem->data,Infor); Rem->
24、;next=NULL; Rem->locat=0; p=TimeQueuen.last; TimeQueuen.last=Rem; p->next=Rem; TimeQueuen.middle=Rem; TimeQueuen.CNum+; printf("成功排队n"); else Rem=(struct node *)malloc(sizeof(struct node); strcpy(Rem->data,Infor); Rem->next=NULL; Rem->locat=0; p=TimeQueuen.last; TimeQueuen.l
25、ast=Rem; p->next=Rem; TimeQueuen.CNum+; printf("成功排队n"); else printf("有空余机位,无须等待n"); else printf("错误.再次输入.n"); void cancel() int n; int i; char Infor10; struct node *Rem; struct node *q; struct node *p; printf("请输入预定的时间n"); scanf("%d",&n); if(
26、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->next=NULL) q->next=NULL; TimeQueuen.last=q; free(Rem); TimeQue
27、uen.CNum-; printf("Succeed to out the queue!n"); else q->next=Rem->next; free(Rem); TimeQueuen.CNum-; printf("Succeed to out the queue!n"); else if(TimeQueuen.CNum>MAX) TimeQueuen.middle->locat=Rem->locat; TimeQueuen.middle=TimeQueuen.middle->next; if(i=1) TimeQueuen.first=Rem->next; else q->next=Rem->next; free(Rem); TimeQueuen.CNum-; printf("成功取消预定!n"); else printf("错误,请再次输入.n"); voi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《柠条发酵蛋白饲料加工技术规程》编制说明
- 2025高考物理步步高同步练习选修3第四章原子结构和波粒二象性第5节 粒子的波动性和量子力学的建立含答案
- 现代设备管理与设备点检工程技术
- 中美石油天然气会计准则比较
- 高三化学一轮复习 巴黎奥运会中空气质量监测与污染防控- 巴黎奥运会热点链接化学考点
- 高三英语一轮复习人教版(2019)全七册单元写作主题汇 总目录清单
- 2024年幼儿教师个人研修计划(34篇)
- 教师升国旗演讲稿简短4篇
- 经济数学基础(第六版)(上册)课件 第12讲3.3函数的单调性
- 小学语文教师远程研修学习心得体会(3篇)
- 向世界最好的医院学管理读后感
- 小学三年级上册品德道德与法治-《做学习的主人》(21张)ppt课件
- 阀门阀体长度及重量表
- 护士急性胰腺炎护理查房
- 物控部管理程序
- 道路运输档案管理办法
- 城市商业中心等级划分
- 最新货车安全隐患排查表
- 电梯无脚手架安装工艺
- 桥梁工程施工重点难点及保证措施
- 2022年2022年沪教版四年级语文绿色指标模拟卷
评论
0/150
提交评论