1、机房机位预约模拟系统C语言程序设计编程实践是学习C语言程序设计的一重要环节,为提高学生程序设计能力,通过课堂和上机实践练习使学生的程序设计能力上一台阶。通过前四单元温顾而知新、庖丁解牛、举一反三、熟能生巧等过程的练习设计下面一个完整的程序1.题目要求设计“机房机位预约模拟系统要求:20台机器,从早8点到晚8点,每两个小时一个时间段。 需要实现功能: 1,查询,根据输入时间,输出机位信息。 2,即为预定,根据输入的日期和时间段查询是否有空机位,假设有那么预约,假设无那么提供最近空机时间段。另:假设用户要求在非空时间上机,那么将用户信息插入该时间段的等待列表. 3,退出预定,根据输入的时间,撤销该
2、时间的预定。 4,查询是否有等待的信息,假设有那么按顺序显示联系方式,假设无那么显示提示信息。 2需求分析根据题目要求在程序中需实现查询,预定,排队等功能的操作,所以需要建立相应的模块来实现;另外还需提供键盘式选择菜单实现功能,在运行时到达所要目的。 3总体设计整个系统可分为3个模块 查询模块 预定模块 取消模块 详细设计 主函数比拟简洁,只提供输入、功能处理和输出局部的函数调用。 main() int i; for(i=0;i=8&nnext!=NULL;Rem=Rem-next) if(strcmp(Rem-data,Infor)=0)break; if(Rem-locat!=0) pri
3、ntf(The computer number is %dn,Rem-locat); else printf(对不起.你依旧在等待列表中或者没有预定); else printf(错误,请再次输入.n); void inquir() int n; printf(输入想要查询的时间(24 hours 820oclock,include 8 oclock)n); scanf(%d,&n); if(n=8&n20) n=S(n); if(TimeQueuen.CNum=8&n20) n=S(n); if(TimeQueuen.CNumlocat=1; strcpy(Rem-data,Infor); R
4、em-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=TimeQueuen.last; Rem-locat=TimeQueuen.CNum+1; printf(%d,Rem-locat); TimeQueuen.last=Rem; p-next=Rem; TimeQueuen.CNum+
5、; 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=MAX) printf(请输入你的学号n); scanf(%s,Infor); if(TimeQueuen.CNum)=MAX) Rem=(struct node *)malloc(sizeof(struct node); strcpy(Rem
6、-data,Infor); Rem-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.last=Rem; p-next
7、=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(n=8&nnext,i+) if(strcmp(Rem-data,Infor)=0)break; if(iMAX) if(Rem-next=NULL) q-
8、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); else if(TimeQueuen.CNumMAX) TimeQueuen.middle-locat=Rem-locat; TimeQueuen.middle=TimeQueuen.middle-next; if(i=1) TimeQ
9、ueuen.first=Rem-next; else q-next=Rem-next; free(Rem); TimeQueuen.CNum-; printf(成功取消预定!n);附录源代码:#include #include #include #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
10、 *first; struct node *middle; struct node *last; TimeQueueLENGTH; void Inquir() int n; char Infor10; struct node *Rem; printf(输入查询时间(24 hours 820 oclock,include 8oclock)n); scanf(%d,&n); if(n=8&nnext!=NULL;Rem=Rem-next) if(strcmp(Rem-data,Infor)=0)break; if(Rem-locat!=0) printf(The computer number i
11、s %dn,Rem-locat); else printf(对不起.你依旧在等待列表中或者没有预定); else printf(错误,请再次输入.n); void inquir() int n; printf(输入想要查询的时间(24 hours 820oclock,include 8 oclock)n); scanf(%d,&n); if(n=8&n20) n=S(n); if(TimeQueuen.CNum=8&n20) n=S(n); if(TimeQueuen.CNumlocat=1; strcpy(Rem-data,Infor); Rem-next=NULL; TimeQueuen.
12、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=Rem; TimeQueuen.CNum+; printf(成功预定n); else pri
13、ntf(没有空余机位!); else printf(错误.请再次输入.n); void waiting() int n; char Infor10; struct node *Rem; struct node *p; printf(请输入想要排队的时间n); scanf(%d,&n); if(n=8&n=MAX) printf(请输入你的学号n); scanf(%s,Infor); if(TimeQueuen.CNum)=MAX) Rem=(struct node *)malloc(sizeof(struct node); strcpy(Rem-data,Infor); Rem-next=NU
14、LL; 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.last=Rem; p-next=Rem; TimeQueuen.CNum+; p
15、rintf(成功排队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(n=8&nnext,i+) if(strcmp(Rem-data,Infor)=0)break; if(iMAX) if(Rem-next=NULL) q-next=NULL; TimeQueuen.last=q;
16、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); else if(TimeQueuen.CNumMAX) TimeQueuen.middle-locat=Rem-locat; TimeQueuen.middle=TimeQueuen.middle-next; if(i=1) TimeQueuen.first=Rem-next; else q-n
17、ext=Rem-next; free(Rem); TimeQueuen.CNum-; printf(成功取消预定!n); else printf(错误,请再次输入.n); void inquir_waiting() int n; struct node *q; printf(查询其他等待者的预定时间n); scanf(%d,&n); if(n=8&nMAX) printf(等待列表 are:n); q=TimeQueuen.middle; for(;q-next!=NULL;q=q-next) printf(%sn,q-data); printf(%sn,TimeQueuen.last-dat
18、a); else printf(这个时间段没有预定者n); else printf(错误。请再次输入.n); main() int i; for(i=0;iLENGTH;i+) TimeQueuei.CNum=0; TimeQueuei.first=NULL; TimeQueuei.middle=NULL; TimeQueuei.last=NULL; while(1) printf(请输入序号!:n); printf(1. 查询预定的机位 n2.查询空机位n 3.预定 n4. 取消预定 n5.等待列表 n6.查询等待者时间列表 0.退出n); scanf(%d,&i); switch(i) case 1:Inquir();break; case 2:inquir();break; case 3:booking();break; case 4:cancel();break; case 5:waiting();break; case 6:inquir_waiting();break; case 0:exit(0); default:printf(errorn);
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2