|
|
|
@ -0,0 +1,255 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
|
|
|
|
|
#define C 20 //电脑台数
|
|
|
|
|
#define T (time-8)/2 //预定的时间段分成按数组形式的六段
|
|
|
|
|
|
|
|
|
|
void JIEMIAN();
|
|
|
|
|
void XINXI();
|
|
|
|
|
void YUDING();
|
|
|
|
|
void QUXIAO();
|
|
|
|
|
void CHAXUN();
|
|
|
|
|
void slove(int time);
|
|
|
|
|
void dengdai(int i);
|
|
|
|
|
|
|
|
|
|
int x[6]={0};
|
|
|
|
|
int jiwei[6][20]={
|
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},
|
|
|
|
|
{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1},
|
|
|
|
|
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0},
|
|
|
|
|
{1,0,0,0,0,0,0,1,1,1,0,1,0,1,0,1,1,1,1,0},
|
|
|
|
|
{1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1},
|
|
|
|
|
{1,1,0,1,1,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0}};//假设0为空机位,1为有机位,此数组为假设某人某次查询系统时的机位数的情况。
|
|
|
|
|
|
|
|
|
|
struct wait{
|
|
|
|
|
char number[3];
|
|
|
|
|
char haoma[20];
|
|
|
|
|
}w[C];//等待的结构体
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
JIEMIAN();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
void JIEMIAN()
|
|
|
|
|
{
|
|
|
|
|
int n,a;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t—————————————机房机位预约系统—————————————\n");
|
|
|
|
|
puts("\t\t —————————————菜单—————————————");
|
|
|
|
|
puts("\t\t\t 1.查询某时间段机位信息.");
|
|
|
|
|
puts("\t\t\t 2.预定一个空机位.");
|
|
|
|
|
puts("\t\t\t 3.取消预订.");
|
|
|
|
|
puts("\t\t\t 4.查询等待的信息.");
|
|
|
|
|
puts("\t\t\t 5.退出系统.");
|
|
|
|
|
puts("\t\t—————————————————————————————————\n");
|
|
|
|
|
printf("\t请输入菜单内的1-5号选项进行服务:\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
if(n<1||n>5)
|
|
|
|
|
{
|
|
|
|
|
a=1;
|
|
|
|
|
printf("输入错误,请重新选择.");
|
|
|
|
|
getchar();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
a=0;
|
|
|
|
|
}while(a==1);
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:XINXI();break;
|
|
|
|
|
case 2:YUDING();break;
|
|
|
|
|
case 3:QUXIAO();break;
|
|
|
|
|
case 4:CHAXUN();break;
|
|
|
|
|
case 5:exit(0);break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void XINXI()
|
|
|
|
|
{
|
|
|
|
|
int time;
|
|
|
|
|
printf("请输入8-20点的时间段:");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
if(time<8||time>=20)
|
|
|
|
|
{
|
|
|
|
|
printf(" 输入错误!\n");
|
|
|
|
|
printf(" 请重新输入正确的时间!");
|
|
|
|
|
XINXI();
|
|
|
|
|
}
|
|
|
|
|
if(time>=8&&time<20)
|
|
|
|
|
{
|
|
|
|
|
slove (time);
|
|
|
|
|
JIEMIAN();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void YUDING()
|
|
|
|
|
{
|
|
|
|
|
int time,i,a,b;
|
|
|
|
|
char c;
|
|
|
|
|
FILE *fp; //用文件存数据。
|
|
|
|
|
printf("请输入8-20点时间段内,你想预定的时间:");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
if(time<8||time>=20)
|
|
|
|
|
{
|
|
|
|
|
printf(" 时间输入错误!\n");
|
|
|
|
|
printf(" 请重新输入正确的时间!\n");
|
|
|
|
|
printf("请输入8-20点时间段内,你想预定的时间:");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
}
|
|
|
|
|
slove(time);
|
|
|
|
|
i=0;
|
|
|
|
|
if(x[T]>0)
|
|
|
|
|
{
|
|
|
|
|
if((fp=fopen("学生信息.txt","a"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("-无法打开文件!-\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf(" 请输入你的想要预定的机位号和电话(输入机位号和电话之间请使用空格):");
|
|
|
|
|
scanf("%s %s",w[i].number,w[i].haoma);
|
|
|
|
|
for(i=0;i<1;i++)
|
|
|
|
|
fwrite(&w[i],sizeof(struct wait),1,fp);
|
|
|
|
|
fclose(fp); //把一个结构体单元加入文件中
|
|
|
|
|
printf("\t\t ——请再次输入你想要预定的机位!(两次时间请相同,不然可能导致预定失败!)——\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
getchar();
|
|
|
|
|
x[T]--;
|
|
|
|
|
jiwei[T][a-1]=1;
|
|
|
|
|
printf(" ——预订成功!——\n");
|
|
|
|
|
JIEMIAN();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t ——这是最近的时间段没有被预定的电脑!——\n");
|
|
|
|
|
for(i=T+1;i<6;i++)
|
|
|
|
|
{
|
|
|
|
|
time=9+2*i;
|
|
|
|
|
slove(time);
|
|
|
|
|
if(x[T]>0)
|
|
|
|
|
printf("\t 最近的空闲的时间是:%d\n",2*i+8);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
printf("\t 你想要预定吗?(请输入y/n表示是否预定)\n");
|
|
|
|
|
scanf("%s",&c);
|
|
|
|
|
getchar();
|
|
|
|
|
if(c=='Y'||c=='y')
|
|
|
|
|
{
|
|
|
|
|
if((fp=fopen("学生信息.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("-无法打开文件!-\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("以下是等待列表:机位号码 电话号码\n");
|
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s %s",&w[i].number,&w[i].haoma);
|
|
|
|
|
}
|
|
|
|
|
fclose;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<10;i++)
|
|
|
|
|
{
|
|
|
|
|
dengdai(i);
|
|
|
|
|
}
|
|
|
|
|
printf("\n\t\t ——请输入你想预定的机位号和你的联系方式。——\n");
|
|
|
|
|
if((fp=fopen("学生信息.txt","a"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("-无法打开文件!-\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
scanf("%s %s",w[i].number,w[i].haoma);
|
|
|
|
|
for(i=0;i<1;i++)
|
|
|
|
|
{
|
|
|
|
|
fwrite(&w[i],sizeof(struct wait),1,fp);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
printf("请再次输入你想要预定的机位号!\n");
|
|
|
|
|
scanf("%d",&b);
|
|
|
|
|
x[T]--;//电脑数减一
|
|
|
|
|
jiwei[T][b]=1;
|
|
|
|
|
printf("\t 恭喜你预订成功,你将进入等待列表,请等待我们联系你。\n");
|
|
|
|
|
JIEMIAN();
|
|
|
|
|
}
|
|
|
|
|
else JIEMIAN();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void QUXIAO()
|
|
|
|
|
{
|
|
|
|
|
int time,n;
|
|
|
|
|
printf("请输入你在8-20点时间内已经预定过的时间:\n");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
if(time<8||time>=20)
|
|
|
|
|
{
|
|
|
|
|
printf(" 时间输入错误!\n");
|
|
|
|
|
printf(" 请重新输入正确的时间!");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
}
|
|
|
|
|
if(time>=8&&time<20)
|
|
|
|
|
{
|
|
|
|
|
printf("\t 请输入你预定的机号:\n");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
}
|
|
|
|
|
x[T]++;
|
|
|
|
|
jiwei[T][n-1]=0;
|
|
|
|
|
slove(time);
|
|
|
|
|
printf("\t 取消成功!\n");
|
|
|
|
|
JIEMIAN();
|
|
|
|
|
}
|
|
|
|
|
void CHAXUN()
|
|
|
|
|
{
|
|
|
|
|
int time,i;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
printf(" ————请输入你要查找的时间(8-20点):\n");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
if(time<8||time>=20)
|
|
|
|
|
{
|
|
|
|
|
printf(" 时间输入错误!\n");
|
|
|
|
|
printf(" 请重新输入正确的时间!");
|
|
|
|
|
scanf("%d",&time);
|
|
|
|
|
}
|
|
|
|
|
if(time>=8&&time<20)
|
|
|
|
|
{
|
|
|
|
|
if((fp=fopen("学生信息.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("-无法打开文件!-\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s %s",&w[i].number,&w[i].haoma);
|
|
|
|
|
}
|
|
|
|
|
fclose;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<10;i++)
|
|
|
|
|
{
|
|
|
|
|
dengdai(i);
|
|
|
|
|
}
|
|
|
|
|
JIEMIAN();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void dengdai(int i)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t %s %s \n",w[i].number,w[i].haoma);
|
|
|
|
|
}
|
|
|
|
|
void slove(int time) //查找六个时间段中每个时间段的空机总数和位数
|
|
|
|
|
{
|
|
|
|
|
int i,j=0,k,l=0;
|
|
|
|
|
int a[50];
|
|
|
|
|
for(i=0;i<20;i++)
|
|
|
|
|
{
|
|
|
|
|
if(jiwei[T][i]==0)
|
|
|
|
|
{
|
|
|
|
|
l++;
|
|
|
|
|
a[j++]=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x[T]=l;
|
|
|
|
|
printf("\t 目前正处于空置的电脑台数为:%d\n",x[T]);
|
|
|
|
|
for(k=0;k<j;k++)
|
|
|
|
|
{
|
|
|
|
|
printf("\t 空置的电脑是:%d 号\n",a[k]+1);
|
|
|
|
|
}
|
|
|
|
|
}
|