#includeiostreamusingnamespacestd;constintMostLayers=100;classCElevator{public:CElevator();//构造函数CElevator(intuLayers,intlLayers);//构造函数CElevator(CElevator&myElevator);//拷贝构造函数voidPressOuterButton(intdirection,intfloor);//电梯外部各楼层操作按钮voidPressInnerDigitalButton(intfloor);//电梯内部数字按钮voidPressOpen_CloseButton(intoperate);//电梯内部开合控制按钮voidPressAlert();//电梯内部报警按钮voidrun();//电梯运行~CElevator();//析构函数protected:voidOpenElevator();//打开电梯voidCloseElevator();//关闭电梯voidUserOperate();//由于程序单线程运行,因此将用户的所有操作集中在每一层停止的时候完成。constintUpperLayers;//电梯最高能到达的楼层constintLowerLayers;//电梯最低能到达的楼层intStates[5];//电梯当前状态,States[0]表示运行或停止,0停止,1运行,初值0;States[1]表示当前所在楼层,初值1;States[2]表示运行方向,向上0,向下1,初值0;States[3]表示开合,0开,1合,初值1;States[4]表示是否故障,0正常,1故障,初值1intDigitalButton[MostLayers];//整形数组,i为楼层且i!=0,i0时下标i-LowerLayers表示电梯内地下i楼层按钮是否被按下,i0,i-LowerLayers-1表示电梯内地上i楼层按钮是否被按下,0未按,1按下intOuterDownButton[MostLayers];//整形数组,i为楼层且i!=0,i0时下标i-LowerLayers表示电梯外i层向下按钮是否被按下,i0,i-LowerLayers-1表示电梯外i层向下按钮是否被按下,0未按,1按下intOuterUpButton[MostLayers];//整形数组,i为楼层且i!=0,i0时下标i-LowerLayers表示电梯外i层向上按钮是否被按下,i0,i-LowerLayers-1表示电梯外i层向上按钮是否被按下,0未按,1按下};CElevator::CElevator():UpperLayers(10),LowerLayers(1){States[0]=0;//初始状态为停止States[1]=1;//初始楼层在楼States[2]=0;//初始方向为向上States[3]=1;//初始电梯为合States[4]=0;//初始电梯正常for(inti=0;iMostLayers;i++){DigitalButton[i]=0;OuterDownButton[i]=0;OuterUpButton[i]=0;}}CElevator::CElevator(intuLayers,intlLayers):UpperLayers(uLayers),LowerLayers(lLayers){States[0]=0;//初始状态为停止States[1]=1;//初始楼层在楼States[2]=0;//初始方向为向上States[3]=1;//初始电梯为合States[4]=0;//初始电梯正常for(inti=0;iMostLayers;i++){DigitalButton[i]=0;OuterDownButton[i]=0;OuterUpButton[i]=0;}}CElevator::CElevator(CElevator&myElevator):UpperLayers(myElevator.UpperLayers),LowerLayers(myElevator.LowerLayers){States[0]=myElevator.States[0];States[1]=myElevator.States[1];States[2]=myElevator.States[2];States[3]=myElevator.States[3];States[4]=myElevator.States[4];for(inti=0;iMostLayers;i++){DigitalButton[i]=myElevator.DigitalButton[i];OuterDownButton[i]=myElevator.DigitalButton[i];OuterUpButton[i]=myElevator.DigitalButton[i];}}CElevator::~CElevator(){}voidCElevator::PressOuterButton(intdirection,intfloor){if(direction==0)OuterUpButton[floor-LowerLayers-1]=1;elseOuterDownButton[floor-LowerLayers-1]=1;}voidCElevator::PressInnerDigitalButton(intfloor){DigitalButton[floor-LowerLayers-1]=1;}voidCElevator::PressOpen_CloseButton(intoperate){if(operate==0)//打开电梯{OpenElevator();}else//关闭电梯{CloseElevator();}}voidCElevator::OpenElevator(){if(States[3]==0){cout电梯已打开,请先出后进!endlendl;}else{cout电梯正在打开…电梯已打开,请先出后进!endlendl;States[3]=0;}}voidCElevator::CloseElevator(){if(States[3]==1){cout电梯已关闭,请保持安静!endlendl;}else{cout电梯正在关闭…电梯已关闭,请保持安静!endlendl;States[3]=1;}}voidCElevator::PressAlert(){cout电梯内部有人报警,请援助!endl;States[4]=1;}voidCElevator::UserOperate(){//按报警按钮intalm=0;cout按报警按钮吗?输入1表示按,0表示不按:;cinalm;coutendl;if(alm==1){States[4]=1;while(States[4]==1){cout电梯出现故障,请维修!endlendl;cout正在维修.......大家保持冷静endl;coutendl;coutendl;cout已修好;coutendl;coutendl;for(inti=0;i100;i++);break;}}OpenElevator();//电梯内部输入到达楼层intsel;cout请输入要上还是要下,0上1下:;cinsel;States[2]=sel;//初始方向为向上cout请电梯内乘客输入所要到达的楼层!多个楼层中间用空格隔开,结束输入0:endl;intfloor=1;while(true){cinfloor;if(floor==0){break;}if((floor=LowerLayers)&&(floor=UpperLayers)&&(floor!=States[1])){if(floor0)//地下{DigitalButton[floor-LowerLayers]=1;}else//地上{DigitalButton[floor-LowerLayers-1]=1;//没有楼}}}coutendl;//电梯外部各楼层输入上楼信号cout请电梯外部乘客输入上楼信号!多个楼层用空格隔开,结束输入0:endl;while(true){cinfloor;if(floor==0){break;}else{if((floor=LowerLayers)&&(floorUpperLayers)&&(floor!=States[1])){if(floor0)//地下{OuterUpButton[floor-LowerLayers]=1;}else//地上{OuterUpButton[floor-LowerLayers-1]=1;//没有楼}}}}coutendl;//电梯外部各楼层输入下楼信号cout请电梯外部乘客输入下楼信号,多个楼层用空格隔开,结束输入0:endl;while(true){cinfloor;if(floor==0){break;}else{if((floorLowerLayers)&&(floor=UpperLayers)&&(floor!=States[1])){if(floor0)//地下{OuterDownButton[floor-LowerLayers]=1;}else//地上{OuterDownButton[floor-LowerLayers-1]=1;//没有楼}}}}coutendl;//按开电梯按钮intdirection=0;cout电梯将要关闭,等人请按打开按钮!输入1表示按,0表示不按:endl;cindirection;coutendl;if(direction==1){OpenElevator();for(inti=0;i100;i++);//延时CloseElevator();}//按关电梯按钮cout按关电梯按钮吗?输入1表示按,0表示不按:;cindirection;coutendl;if(direction==0){for(inti=0;i100;i++);//延时CloseElevator();}else{CloseElevator();}}voidCElevator::run(){while(true){if(States[0]==0){cout电梯停在States[1]层!endl;if(States[2]==0)//向上{if(States[1]0)//地下{OuterUpButton[States[1]-LowerLayers]=0;//将记录电梯States[1]层有向上的标志取消DigitalButton[States[1]-LowerLayers]=0;//将记录电梯在States[1]层停靠的标志取消}else//地上{OuterUpButton[States[1]-LowerLayers-1]=0;//将记录电梯States[1]层有向上的标志取消DigitalButton[States[1]-LowerLayers-1]=0;//将记录电梯在States[1]层停靠的标志取消}}else//向下{if(States[1]0)//地下{OuterDownButton[States[1]-LowerLayers]=0;//将记录电梯States[1]层有向下的标志取消DigitalButton[States[1]-LowerLayers]=0;//将记录电梯在States[1]层停靠的标志取消}else//地上{OuterDownButton[States[1]-LowerLayers-1]=0;//将记录电梯States[1]层有向下的标志取消DigitalButton[States[1]-LowerLaye