机房机位预约模拟系统C语言课程设计报告Word文件下载.docx
《机房机位预约模拟系统C语言课程设计报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《机房机位预约模拟系统C语言课程设计报告Word文件下载.docx(20页珍藏版)》请在冰点文库上搜索。
![机房机位预约模拟系统C语言课程设计报告Word文件下载.docx](https://file1.bingdoc.com/fileroot1/2023-4/29/629fb2c2-06d2-4add-bd8d-2865893945c4/629fb2c2-06d2-4add-bd8d-2865893945c41.gif)
intsum[6]={0};
intcomputer[6][20]={{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,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}};
/*该数组表示假设某天某人查询时机房各个时间段机位数情况*/
voidMenu();
voidSituation();
voidBook();
voidCancel();
voidSearchWaiting();
voidExit();
voiddetail(inttime);
voidprintf_one(inti);
structwaitlist
{
charnumber[3];
chartelephonenumber[12];
}wait[N];
2.主函数
主函数一般设计得比较简洁,只提供输入,处理和输出部分的函数调用。
其中各功能模块用菜单方式选择。
其流程图如图所示:
2./*主函数*/
voidmain()
Menu();
/*当前状态函数*/
}
voidMenu()/*主界面*/
intn,w;
do
{
puts("
\t\t****************COMPUTERBOOKSYSTERM*******************\n"
);
\t\t*************************MENU***************************\n"
\t\t\t1.Searchthecurrentsituation"
/*查询某时间段机位状态*/
\t\t\t2.Bookthevacantcomputer"
/*预定空机位*/
\t\t\t3.Cancelbooking"
/*取消预订*/
\t\t\t4.Searchwaiting"
/*查询等待信息*/
\t\t\t5.Exit"
/*退出*/
\t\t********************************************************\n"
printf("
Chooseyournumber(1-5):
[]\b\b"
scanf("
%d"
&
n);
if(n<
1||n>
5)
{w=1;
getchar();
else
w=0;
}while(w==1);
switch(n)
case1:
Situation();
break;
case2:
Book();
case3:
Cancel();
case4:
SearchWaiting();
case5:
Exit(0);
}
3.状态查询函数
流程图
/*查询模块*/
/*查询当前状态*/
voidSituation()
inttime;
Inputtimebetween(8-20):
"
time);
if(time<
8||time>
20)
{printf("
\tWrongtime!
\n"
Pleaseinputtimebetween(8-20):
detail(time);
/*函数调用*/
getchar();
4.预定模块函数
程序:
/*预定模块*/
voidBook()
{inttime,i=0,x,y;
FILE*fp;
charc;
Inputtimeyouwanttobookbetween(8-20):
\tInputtimeyouwanttobookbetween(8-20):
if(sum[T]>
0)
{if((fp=fopen("
waitlist.txt"
"
a"
))==NULL)
{
printf("
\nCannotopenfile!
exit(0);
}
\n\tPleaseInputthenumberyouwanttobookandleaveyourtelephonenumber!
:
%s%s"
wait[i].number,wait[i].telephonenumber);
for(i=0;
i<
1;
i++)
fwrite(&
wait[i],sizeof(structwaitlist),1,fp);
fclose(fp);
/*向文本文档添加一个结构体单元*/
\tInputthenumberyouwanttobookagain!
x);
sum[T]--;
/*预定后该时间段空机位数减1*/
computer[T][x]=1;
/*预定后该机状态变为1*/
\tBooksucceed!
else
Thereisnovacantcomputeratthattime!
for(i=T+1;
6;
{time=9+2*i;
detail(time);
if(sum[T]>
\tThelatestfreetimeis%d,%d\n"
2*i+8,2*i+10);
\tDoyouwanttowait?
y/n?
scanf("
%s"
c);
getchar();
if(c=='
Y'
||c=='
y'
)
if((fp=fopen("
r"
exit(0);
else
{printf("
waitlist:
numbertelephonenumber\n"
for(i=0;
!
feof(fp);
{
fscanf(fp,"
wait[i].number,&
wait[i].telephonenumber);
}
10;
{printf_one(i);
if((fp=fopen("
/*若等待,就用文件的方式列出当时的等待列表并提示输入你的等待序号和联系方式*/
Inputthenumberofthecomputeragain!
y);
sum[T]--;
computer[T][y]=1;
\tOk,pleasewaitourphone!
elseMenu();
5,取消预订模块函数
/*取消预订模块*/
voidCancel()
inttime,number;
Inputtimeyouhavebookedbetween(8-20):
\tInputtimeyouhavebookedbetween(8-20):
\tInputnumberyouhavebooked:
number);
sum[T]++;
/*预定后该时间段空机位数加1*/
computer[T][number]=0;
/*预定后该机状态变为0*/
\tCancelsucceed!
6查询等待信息模块
/*查询等待信息模块*/
voidSearchWaiting()
inttime,i;
FILE*fp;
\tInputtimeyouwanttosearchbetween(8-20):
;
{printf("
{printf_one(i);
7.公共函数
程序
voiddetail(inttime)/*此函数功能是实现查找每个时间段空机位总数和空机位号*/
{
inti,j=0,k,s=0;
intv[30];
20;
{if(computer[T][i]==0)
{s++;
v[j++]=i;
sum[T]=s;
\tCurrentvacantcomputers:
%d\n"
sum[T]);
for(k=0;
k<
j;
k++)
\tThevacantcomputersare:
v[k]);
voidprintf_one(inti)/*此函数功能是实现输出等待列表到屏幕*/
\t\t%s%s\n"
8运行界面
1,选1.,进入查询当前状态
2选2,进入预定函数
3.选4.进入查询当前状态函数
4.选3.取消预订
5.选2.当某时间段没有空机位时,进入下一个时间段的查询和预定
6.选5.退出界面