版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上机房机位预约模拟一题目要求20台机器,从早八点到晚八点,每两个小时一个时间段.需要实现的功能:(1) 查询,根据输入的时间,输出机位信息.(2) 机位预定,根据输入的日期和时间段查询是否有空机位,若有则预约,若无则提供最近空机时间段.另:若用户要求在非空时间上机,则将用户信息插入该时间段的等待列表.(3) 退出预定,根据输入的时间,撤消该时间的预定.(4) 查询是否有等待信息,若有则按顺序显示联系方式,若无则显示提示信息.二需求分析根据题目要求,在程序中应实现查询,机位预定,插入等待列表,退出预定,查询等待信息等功能。还应提供键盘式选择菜单实现功能选择。而等待信息放在
2、文件里,所以在相关的模块应提供文件的输入、输出操作。三总体设计根据上面的需求分析,将这个系统的设计分为下面4个模块:机房机位预约模拟系统状态查询模块预订模块取消预订模块查询等待信息模块4详细设计 1.预处理命令及函数声明#include<stdio.h>#include<stdlib.h>#include<string.h>#define N 20#define T (time-8)/2int 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,
3、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,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;/*该数组表示假设某天某人查询时机房各个时间段机位数情况*/void Menu(); void Situation();void Book();void Cancel();void SearchWaiting();void Exit();v
4、oid detail(int time);void printf_one(int i); struct waitlist char number3; char telephonenumber12; waitN;2主函数主函数一般设计得比较简洁,只提供输入,处理和输出部分的函数调用。其中各功能模块用菜单方式选择。其流程图如图所示:开始显示一系列功能模块根据的值调用各功能模块函数YN输入n的值1-5结束 2./*主函数*/void main()Menu(); /*当前状态函数*/void Menu() /*主界面*/int n,w;do puts("tt*COMPUTER BOOK SY
5、STERM*n"); puts("tt*MENU*n"); puts("ttt 1.Search the current situation"); /*查询某时间段机位状态*/ puts("ttt 2.Book the vacant computer"); /*预定空机位*/ puts("ttt 3.Cancel booking"); /*取消预订*/ puts("ttt 4.Search waiting"); /*查询等待信息*/ puts("ttt 5.Exit"
6、;); /*退出*/ puts("tt*n"); printf("Choose your number(1-5): bb"); scanf("%d",&n); if(n<1|n>5) w=1;getchar(); else w=0;while(w=1);switch(n)case 1:Situation();break;case 2:Book();break; case 3:Cancel();break; case 4:SearchWaiting();break; case 5:Exit(0);break;3.状态
7、查询函数流程图调用detail函数返回主菜单输入1是否输入time的值8-20开始/*查询模块*/*查询当前状态*/void Situation()int time;printf("Input time between (8-20):");scanf("%d",&time);if(time<8|time>20)printf("tWrong time!n");printf("Please input time between (8-20):");scanf("%d",&
8、time); detail(time); /*函数调用*/getchar();Menu();4.预定模块函数流程图开始N执行一个循环,进入后面的时间段SumT>0输入时间8-20调用detail函数,sumT的值改变输出空机位数,是否等待NY打开文本文件waitlist.txt,输入预定机位号和联系方式,追加一个结构体成员。返回主菜单程序:/*预定模块*/void Book()int time,i=0,x,y;FILE *fp; char c; printf("Input time you want to book between(8-20):"); scanf(&q
9、uot;%d",&time); if(time<8|time>20) printf("tWrong time!n"); printf("tInput time you want to book between(8-20):"); scanf("%d",&time); detail(time); /*函数调用*/if(sumT>0) if(fp=fopen("waitlist.txt","a")=NULL) printf("nCannot op
10、en file!n"); exit(0); printf("ntPlease Input the number you want to book and leave your telephonenumber!:n"); scanf("%s %s",waiti.number,waiti.telephonenumber);for(i=0;i<1;i+) fwrite(&waiti,sizeof(struct waitlist),1,fp); fclose(fp);/*向文本文档添加一个结构体单元*/printf("tInpu
11、t the number you want to book again!n");scanf("%d",&x);sumT-; / *预定后该时间段空机位数减1*/computerTx=1; / *预定后该机状态变为1*/printf("tBook succeed!n");getchar();Menu();elseprintf("There is no vacant computer at that time!n");for(i=T+1;i<6;i+) time=9+2*i;detail(time); /*函数调用
12、*/if(sumT>0)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"
13、); 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;i<10;i+) printf_one(i); printf("ntPlease Input the number you want to book and leave your telephonenumb
14、er!: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;i<1;i+) fwrite(&waiti,sizeof(struct waitlist),1,fp); fclose(fp); /*若等待,就用文件的方式列出当时的等待列表并提示输入你的等待序号和联系方
15、式*/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,取消预订模块函数流程图调用detail函数输入机位号YN输入时间8-20开始该时间段空电脑数加1,所取消电脑号状态变为0主菜单/*取消预订模块*/void Cancel()int time,number;printf("
16、Input time you have booked between(8-20):");scanf("%d",&time); if(time<8|time>20) printf("tWrong time!n"); printf("tInput time you have booked between(8-20):"); scanf("%d",&time); elseprintf("tInput number you have booked :");scanf
17、("%d",&number);detail(time); sumT+; / *预定后该时间段空机位数加1*/computerTnumber=0; / *预定后该机状态变为0*/printf("tCancel succeed!n");getchar();Menu();6查询等待信息模块流程图开始输入时间8-20打开文本文件,将文本文件转化为二进制文件输出到屏幕上,显示等待信息YN返回主菜单/*查询等待信息模块*/void SearchWaiting()int time,i; FILE *fp;printf("tInput time you
18、 want to search between(8-20):");scanf("%d",&time);if(time<8|time>20) printf("tWrong time!n"); printf("tInput time you want to search between(8-20):"); scanf("%d",&time);else; if(fp=fopen("waitlist.txt","r")=NULL) printf("nCannot open file!n"); exit(0); else printf("waitlist: number telephonenumbern"); for(i=0;!feof
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年四川交通职业技术学院单招职业技能考试题库含答案详解(综合卷)
- 2026年四川托普信息技术职业学院单招综合素质考试题库附答案详解(达标题)
- 人工智能技术在医疗行业应用展望
- 东华理工大学食堂管理及从业人员培训讲义 课件
- 呼吸机使用与护理
- 《约分》教学课件
- 《认识扇形》课件
- 2025年阜阳职业技术学院单招职业技能考试题库及答案解析
- 2025年辽宁生态工程职业学院单招综合素质考试试题及答案解析
- 2026南平浦城县浦盛欣易财税管理有限公司招聘笔试备考题库及答案解析
- 2026校招:云南设计院集团笔试题及答案
- 部编版新教材道德与法治二年级下册《3.做个“开心果”》教案设计
- 2025母婴保健技术考试题库附答案
- 2026年春统编版小学道德与法治五年级下册教学计划及进度表
- 2026年及未来5年市场数据中国硫酸行业市场调研分析及投资战略咨询报告
- 人大知识竞赛试题及答案
- 2026年盐城工业职业技术学院高职单招职业适应性测试备考题库有答案解析
- 大型图书馆古籍文献修复材料管理细则
- DL-T 5190.1-2022 电力建设施工技术规范 第1部分:土建结构工程(附条文说明)
- 《普通物理学(第7版)》全套教学课件1434页
- DB41∕T 1960.3-2021 公共机构能耗定额 第3部分:教育机构
评论
0/150
提交评论