📄 电梯管理 程序.cpp
字号:
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
lift1.up=0;lift1.down=0;lift1.stay=1; //更新电梯的运动状态
}
else
{
lift1.all_persons=lift1.all_persons-lift1.out_persons[lift1.stay_in_floor+2]+floor[lift1.stay_in_floor+2].down_persons;//更新电梯1内的总人数
t_inperson=floor[lift1.stay_in_floor+2].down_persons;
floor[lift1.stay_in_floor+2].down_persons=0; //更新在该层楼等待进入电梯的人数
t_outperson=lift1.out_persons[lift1.stay_in_floor+2];
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
lift1.up=0;lift1.down=1;lift1.stay=0; //更新电梯的运动状态
floor[lift1.stay_in_floor+2].down=0; //更新电梯外的“上”按钮状态
}
}
}
else if (lift1.down)
{
if (lift1.stay_in_floor>-2)
lift1.stay_in_floor--; //更新电梯所在的楼层
floor[lift1.stay_in_floor+2].down=0; //更新电梯外的“上”按钮状态
lift1.inbutton_state[lift1.stay_in_floor+2]=0;//更新电梯内该层按钮状态
flag1=in_low;
flag2=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&out_low;
flag3=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&out_low&(lift2.up || lift2.stay);
flag4=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.up&between_down;
flag5=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.up&low;
flag6=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.stay&between_near;
flag7=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.down≬
flag8=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.down&low_up;
flag_down=flag1 || flag2 ||flag3 ||flag4 ||flag5 ||flag6 ||flag7 ||flag8;
if (flag_down)
{
lift1.all_persons=lift1.all_persons-lift1.out_persons[lift1.stay_in_floor+2]+floor[lift1.stay_in_floor+2].down_persons;//更新电梯1内的总人数
t_inperson=floor[lift1.stay_in_floor+2].down_persons;
floor[lift1.stay_in_floor+2].down_persons=0; //更新在该层楼等待进入电梯的人数
t_outperson=lift1.out_persons[lift1.stay_in_floor+2];
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
}
else if (!flag_down)
{
flag9=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.up&!out_high&!between_down;
flag10=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.stay&!out_high&!between_near;
flag11=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.down&!out_high&!between&!low_up;
flag12=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&lift2.up&!out_low;
flag13=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&lift2.stay&!out_low&!out_high;
flag14=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&lift2.down&!out_high;
flag15=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.up&!out_low&!between&!high_down;
flag16=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.stay&!out_low&!between_near&!high_down;
flag17=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.down&!out_low&!between_up&!high;
flag_stay=flag9 || flag10 || flag11 || flag12 || flag13 || flag14 || flag15 || flag16 || flag17;
if (flag_stay)
{
lift1.all_persons=lift1.all_persons-lift1.out_persons[lift1.stay_in_floor+2];//更新电梯1内的总人数
t_outperson=lift1.out_persons[lift1.stay_in_floor+2];
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
lift1.up=0;lift1.down=0;lift1.stay=1; //更新电梯的运动状态
}
else
{
lift1.all_persons=lift1.all_persons-lift1.out_persons[lift1.stay_in_floor+2]+floor[lift1.stay_in_floor+2].down_persons;//更新电梯1内的总人数
t_inperson=floor[lift1.stay_in_floor+2].up_persons;
floor[lift1.stay_in_floor+2].up_persons=0; //更新在该层楼等待进入电梯的人数
t_outperson=lift1.out_persons[lift1.stay_in_floor+2];
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
lift1.up=1;lift1.down=0;lift1.stay=0; //更新电梯的运动状态
floor[lift1.stay_in_floor+2].up=0; //更新电梯外的“上”按钮状态
}
}
}
else
{
lift1.inbutton_state[lift1.stay_in_floor+2]=0;//更新电梯内该层按钮状态
flag1=in_high;
flag2=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&out_high;
flag3=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&out_high&(lift2.down || lift2.stay);
flag4=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.up≬
flag5=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.up&high_down;
flag6=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.stay&between_near;
flag7=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.down&between_up;
flag8=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.down&high;
flag18=!flag1&floor[lift1.stay_in_floor+2].up;
flag_up=flag1 || flag2 ||flag3 ||flag4 ||flag5 ||flag6 ||flag7 ||flag8 || flag18;
if (flag_up)
{
lift1.all_persons=lift1.all_persons-lift1.out_persons[lift1.stay_in_floor+2]+floor[lift1.stay_in_floor+2].up_persons;//更新电梯1内的总人数
t_inperson=floor[lift1.stay_in_floor+2].up_persons;
floor[lift1.stay_in_floor+2].up_persons=0; //更新在该层楼等待进入电梯的人数
t_outperson=lift1.out_persons[lift1.stay_in_floor+2];
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
floor[lift1.stay_in_floor+2].up=0; //更新电梯外的“上”按钮的状态
lift1.up=1;lift1.down=0;lift1.stay=0; //更新电梯的运动状态
}
else if (!flag_up)
{
flag9=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.up&!out_high&!between_down;
flag10=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.stay&!out_high&!between_near;
flag11=!flag1&(lift1.stay_in_floor>lift2.stay_in_floor)&lift2.down&!out_high&!between&!low_up;
flag12=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&lift2.up&!out_low;
flag13=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&lift2.stay&!out_low&!out_high;
flag14=!flag1&(lift1.stay_in_floor==lift2.stay_in_floor)&lift2.down&!out_high;
flag15=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.up&!out_low&!between&!high_down;
flag16=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.stay&!out_low&!between_near&!high_down;
flag17=!flag1&(lift1.stay_in_floor<lift2.stay_in_floor)&lift2.down&!out_low&!between_up&!high;
flag_stay=flag9 || flag10 || flag11 || flag12 || flag13 || flag14 || flag15 || flag16 || flag17;
if (!flag_stay)
{
lift1.all_persons=lift1.all_persons-lift1.out_persons[lift1.stay_in_floor+2]+floor[lift1.stay_in_floor+2].down_persons;//更新电梯1内的总人数
t_inperson=floor[lift1.stay_in_floor+2].down_persons;
floor[lift1.stay_in_floor+2].down_persons=0; //更新在该层楼等待进入电梯的人数
t_outperson=lift1.out_persons[lift1.stay_in_floor+2];
lift1.out_persons[lift1.stay_in_floor+2]=0; //更新在该层楼出去电梯的人数
lift1.up=0;lift1.down=1;lift1.stay=0; //更新电梯的运动状态
floor[lift1.stay_in_floor+2].down=0; //更新电梯外的“上”按钮状态
}
}
}
//下面,输出电梯的状态
Sleep(500); //再让print线程睡眠0.5秒,在这段时间里电梯不能响应电梯内、外的按钮
//在此加入清屏
//cls;
//clrscr();
SuspendThread(hprint2); //挂起print2线程
cout<<"电梯1目前在"<<lift1.stay_in_floor<<"层"<<endl; //输出电梯所在的楼层
if (lift1.all_persons>max_persons)
{
lift1.all_persons=max_persons;
Beep(800,1000);
}
else if (lift1.all_persons<0)
lift1.all_persons=0;
cout<<"电梯1内有"<<lift1.all_persons<<"人"<<endl; //输出电梯内的总人数
/* if (t_outperson>lift1.all_persons)
t_outperson=lift1.all_persons;
else
if (t_outperson<0)
t_outperson=0;
if (t_inperson>(max_persons-lift1.all_persons))
t_inperson=max_persons-lift1.all_persons;
else
if (t_inperson<0)
t_inperson=0;*/
if (t_outperson!=0 || t_inperson!=0)
cout<<"电梯1在本层出去"<<t_outperson<<"人,进入"<<t_inperson<<"人"<<endl;//输出电梯进、出人数情况
t_inperson=0;
t_outperson=0;
if (lift1.up)
cout<<"电梯1目前运动状态:向上"<<endl;
else if (lift1.down)
cout<<"电梯1目前运动状态:向下"<<endl;
else
cout<<"电梯1目前运动状态:暂停"<<endl;
cout<<endl;
ResumeThread(hprint2); //恢复print2线程
}
return 0;
}
//用于输出电梯2状态的线程
DWORD WINAPI print2(PVOID PARAM3)
{int t_inperson=0,t_outperson=0; //用于临时存放电梯状态
bool flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8,flag9,flag10,flag11,flag12,flag13,flag14,flag15,flag16,flag17,flag18,flag_up,flag_stay,flag_down;
bool in_high=0,in_low=0,out_high=0,between=0,high_down=0,between_near=0,between_up=0,high=0,low=0,between_down=0,low_up=0,out_low=0;
int i,t_high_floor,t_low_floor;
while (operation_state) //用于输出电梯状态的死循环
{
Sleep(2500); //先让print线程睡眠2.5秒,这样在这段时间里电梯能响应电梯内、外的按钮
in_high=0;
out_high=0;
for (i=lift2.stay_in_floor+3;i<=11;i++)
{
in_high=in_high || lift2.inbutton_state[i];
out_high=out_high || floor[i].up || floor[i].down;
}
in_low=0;
for (i=lift2.stay_in_floor+1;i>=0;i--)
in_low=in_low || lift2.inbutton_state[i];
t_high_floor=(lift1.stay_in_floor>lift2.stay_in_floor)? lift1.stay_in_floor:lift2.stay_in_floor;
t_low_floor=(lift1.stay_in_floor<lift2.stay_in_floor)? lift1.stay_in_floor:lift2.stay_in_floor;
between=0;
for (i=t_low_floor+3;i<t_high_floor+2;i++)
between=between || floor[i].up || floor[i].down;
high_down=0;
for (i=lift2.stay_in_floor+3;i<=11;i++)
high_down=high_down || floor[i].down;
between_near=0;
for (i=t_low_floor+3;i<=t_low_floor+(t_high_floor-t_low_floor)/2+2;i++)
between_near=between_near || floor[i].up || floor[i].down;
between_up=0;
for (i=t_low_floor+3;i<t_high_floor+2;i++)
between_up=between_up || floor[i].up;
high=0;
for (i=lift2.stay_in_floor+3;i<=11;i++)
high=high || floor[i].up || floor[i].down;
between_down=0;
for (i=t_low_floor+3;i<=t_high_floor+2;i++)
between_down=between_down || floor[i].down;
low_up=0;
for (i=lift2.stay_in_floor+1;i>=0;i--)
low_up=low_up || floor[i].up;
out_low=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -