18570281412 6 years ago
commit ea32747a26

@ -0,0 +1,220 @@
#include"stdio.h"
#include <windows.h>
#include"stdlib.h"
#include"string.h"
#define T (time-8)/2
int sum[6]={0};
int computer[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,0,0,1,1,1},
{1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1}};
int menu();
int cx();
int yd();
int qxyd();
int searchwaiting();
int detail(int time);
struct waitlist
{
char shijian[2];
char number[3];
char telephonenumber[11];
}wait[20];
int main()
{
printf("请输入密码!\n");
char MIMA[11]="123456";
char mima[11];
scanf("%s",mima);
if(strcmp(mima,MIMA)==0)
{menu();}
}
int menu()
{
int n,w;
do{
printf("\t\t***************机房机位预定系统***************\n");
printf("\t\t ******************菜单******************\n");
printf("\n\n\n");
printf("\t\t\t 1.查询某段时间机位状态\n");
printf("\t\t\t 2.预定空机位\n");
printf("\t\t\t 3.取消预定\n");
printf("\t\t\t 4.查询等待信息\n");
printf("\t\t\t 5.退出\n");
printf("请输入指令(1-5):");
scanf("%d",&n);
if(n<1||n>5)
w=1;
else
w=0;
}while(w==1);
switch(n)
{
case 1:cx(); break;
case 2:yd(); break;
case 3:qxyd();break;
case 4:searchwaiting();break;
case 5:exit(0);break;
}
}
int cx()
{
system("cls");
int time;
printf("输入时间(8-19):");
scanf("%d",&time);
if(time<8||time>20)
{
printf("\t时间输入错误\n");
printf("输入在8-19范围内的时间");
scanf("%d",&time);
}
detail(time);
menu();
}
int yd()
{
system("cls");
int time,i=0,x,y;
FILE *fp;
char c;
printf("8-19时间内输入你想要的预定时间");
scanf("%d",&time);
if(time<8||time>20)
{
printf("时间输入错误!\n");
printf("8-19时间内输入你想要的预定时间");
scanf("%d",&time);
}
detail(time);
if(sum[T]>0)
{
if((fp=fopen("waitlist.txt","a"))==NULL)
{
printf("\n无法打开文件!\n");
exit(0);
}
printf("请输入你想要预定的时间,机号并留下你的电话号码!:");
scanf("%s %s %s",wait[i].shijian,wait[i].number,wait[i].telephonenumber);
fprintf(fp,"%s %s %s\n",wait[i].shijian,wait[i].number,wait[i].telephonenumber);
fclose(fp);
printf("再次输入你想要预定的机号!\n");
scanf("%d",&x);
sum[T]--;
computer[T][x]=1;
printf("\n预定成功\n");
menu();
}
else
{
printf("这是在最近时间段内未预定的电脑!\n");
for(i=T+1;i<6;i++)
{
time=9+2*i;
detail(time);
if(sum[T]>0)
printf("最近的空闲时间段是%d-%d\n",2*i+8,2*i+10);break;
}
printf("你想要预定吗?:y/n?:");
scanf("%s",&c);
if(c=='Y'||c=='y')
{
printf("请输入您想预定的时间,机号并留下您的联系方式!:\n");
if((fp=fopen("waitlist.txt","a"))==NULL)
{
printf("\n无法打开文件!\n");
exit(0);
}
scanf("%s %s %s",wait[i].shijian,wait[i].number,wait[i].telephonenumber);
fwrite(&wait[i],sizeof(struct waitlist),1,fp);
fclose(fp);
printf("再次输入电脑的序号!\n");
scanf("%d",&y);
sum[T]--;
computer[T][y]=1;
printf("预定成功!\n");
menu();
}
else menu();
}
}
int qxyd()
{
system("cls");
int time,number;
printf("在(8-20)时间内输入你已经预定的时间:");
scanf("%d",&time);
if(time<8||time>20)
{
printf("输入时间错误!\n");
printf("在(8-20)时间范围内输入你已经预定的时间:");
scanf("%d",&time);
}
printf("输入你预定的时间和机号:");
printf("再次输入预定的机号!");
scanf("%d",&number);
sum[T]++;
computer[T][number]=0;
printf("取消成功!\n");
menu();
}
int searchwaiting()
{
int time,i;
FILE *fp;
printf("在(8-20)之间输入您想要搜索的时间:");
scanf("%d",&time);
if(time<8||time>20)
{
printf("时间输入错误!\n");
printf("在(8-20)之间输入您要搜索的时间:");
scanf("%d",&time);
}
else if((fp=fopen("waitlist.txt","r"))==NULL)
{
printf("\n无法打开文件!\n");
exit(0);
}
else
{
printf("waitlist:shijian number telephonenumber\n");
for(i=0;!feof(fp);i++)
{
fscanf(fp,"%s %s %s",&wait[i].shijian,&wait[i].number,&wait[i].telephonenumber);
}
fclose(fp);
}
for(i=0;i<10;i++)
{
printf("\t %s %s %s\n",wait[i].shijian,wait[i].number,wait[i].telephonenumber);
}
menu();
}
int detail(int time)
{
int i,s=0,j=0;
int v[20];
for( i=0;i<20;i++)
{
if(computer[T][i]==0)
{
s=s+1;
v[j]=i;
j++;
}
}
sum[T]=s;
printf("空置的电脑数为%d\n",sum[T]);
printf("空置的电脑是:\n");
for( i=0;i<j;i++)
{
printf("%d\n",v[i]);
}
}

Binary file not shown.
Loading…
Cancel
Save