《电梯程序源代码.docx》由会员分享,可在线阅读,更多相关《电梯程序源代码.docx(10页珍藏版)》请在第一文库网上搜索。
1、#ifndefCE1EVATOR_HdefineCE1EVATOR_HconstintMost1ayers=100;c1assCEIevator(pub1ic:CE1eVatOr();构造函数CEIevatorfintU1ayerS,intI1ayers);构造函数CE1evatorICEIevatorSimyEIevatoij;拷贝构造函数voidPressOuterButton(intdirection,intf1oor);电梯外部各楼层操作按钮voidPreSS1nnerDigita1BUttOn(intf1oor);电梯内部数字按钮voidPressOpen_C1oseButton(i
2、ntOPerate);电梯内部开合限制按钮voidPreSSAIert();电梯内部报警按钮voidrun();电梯运行CEIevator();析构函数protected:voidOPenEIeVator();打开电梯voidC1OSeEIeVatOr();关闭电梯voidUSerOPerate();由于程序单线程运行,因此将用户的全部操作集中在每一层停止的时候完成。constintUpper1ayers;电梯最高能到达的楼层constint1OWer1ayers;电梯最低能到达的楼层intStates5;电梯当前状态,StateS表示运行或停止,0停止,1运行,初值0;States1表示当前
3、所在楼层,初值1;StateS表示运行方向,向上0,向下1初值0;StateS3表示开合,。开,。合,初值1;StateS表示是否故障,0正常,1故障,初值1intDigita1BUttOnMost1ayers;整形数组,i为楼层且i!=0,i0时下标I1ower1ayers表示电梯内地下i楼层按钮是否被按下,AOJ-1ower1ayers-I表示电梯内地上i楼层按钮是否被按下,C)未按,1按下intC)UterDOWnBUttonMost1ayers;整形数组,i为楼层且i!=0,i0i-1ower1ayers-I表示电梯外i层向下按钮是否被按下,0未按,1按下intOUterUPBUttO
4、nMost1ayers;整形数组,i为楼层且i!=0,i0,i1ower1ayers-I表示电梯外i层向上按钮是否被按下,0未按,1按下);#endif二:CEIeVator.cpp文件内容inc1ude#inc1udeCEIevator.husingnamespacestd;CE1eVatOr:CE1eVatOr():UPPer1ayerS(10),1oWer1ayerS(StatesO=0;初始状态为停止States1=1;初始楼层在楼StateS=0;初始方向为向上States3=1;初始电梯为合States4=0;初始电梯正常for(inti=0;iMost1ayersJ+)(Digi
5、ta1Buttoni=0;OuterDownButtoni=0;OuterUpButtoni=0;)CE1eVato匚:CE1eVator(intu1ayers,intI1ayers):Upper1ayers(u1ayers),1ower1ayers(11ayers)(StatesO=0;初始状态为停止States1=1;初始楼层在楼States2=0;初始方向为向上States3=1;初始电梯为合States4=0;初始电梯正常for(inti=0;iMost1ayers;1+)(Digita1Buttoni=0;OuterDownButtoni=0;OuterUpButtoni=0;)CE
6、1eVatO匚:CE1eVatOr(CE1eVator8tmyE1evator)pper1ayers(myE1evator.Upper1ayers),1ower1ayers(myE1evator.1ower1ayers)(StatesO=myE1evator.States0;States1=myE1evator.States1;States2=0;初始方向为向上States3=1;初始电梯为合States4=0;初始电梯正常for(inti=0;iMost1ayersJ+)(Digita1Buttoni=0;OuterDownButtoni=0;OuterUpButtoni=0;)C日evat
7、or:C日evator(intu1ayers,intI1ayers):Upper1ayers(u1ayersJz1ower1ayers(I1ayers)(StatesO=0;初始状态为停止States1=1;初始楼层在楼States2=0;初始方向为向上States3=1;初始电梯为合States4=0;初始电梯正常for(inti=0;iMost1ayersJ+)DigitaIButtonfi=0;OuterDownButtoni=0;OuterUpButtoni=0;)StmyE1evator):CE1eVatO匚:CE1eVatOr(CE1eVatorUpper1ayers(myE1ev
8、ator.Upper1ayers),1ower1ayers(myE1evator.1ower1ayers)(StatesO=myE1evator.States0;States1=myE1evator.States1;States2=myE1evator.States2;States3=myE1evator.States3;States4=myE1evator.States5;for(inti=0;iMost1ayersJ+)(Digita1Buttoni=myE1evator.Digita1Buttoni;OuterDownButtoni=my曰evator.Digita1Buttoni;Ou
9、terUpButtoni=myE1evator.Digita1Buttoni;)CEIevatorCEIevator()voidCEIevator:PressOuterButton(intdirection,intf1oor)if(direction=0)OuterUpButtonf1oor-1ower1ayers-1=1;e1seOuterDownButtonf1oor-1ower1ayers-1=1;)voidCE1eVatOr:PreSSInnerDigitaIBUttOn(intf1oor)Digita1Buttonf1oor-1ower1ayers-1=1;)voidCEIevato
10、r:PressOpen_C1oseButton(intoperate)if(operate=0)打开电梯OpenEIevatorI);)e1se关闭电梯CIoseEevatorO;)voidCE1evatoriiOpenEIevatorO(if(States3=O)(COUt电梯已打开,请先出后进!end1end1;)e1se(COUt电梯正在打开电梯已打开,请先出后进!end1end1;States3=0;)voidCE1evator=CIoseEevatorO(if(States3=1)cout电梯已关闭,请保持宁静!end1end1;)e1se(COUt电梯正在关闭电梯已关闭,请保持宁静
11、!end1end1;States3=1;)voidCEIevator:PressA1ert()(cout”电梯内部有人报警,请救济!end1;States4=1;)voidCE1evatoriiUserOperateO(按报警按钮inta1m=0;CoUta1m;coutend1;if(a1m=1)(States4=1;whi1e(States4=1)8Uta1m;coutend1;if(a1m=011a1m=1)(States4=a1m;)e1se(CoUt修理数据不正确!end1;)OpenEIevatorO;电梯内部输入到达楼层COUt”请电梯内乘客输入所要到达的楼层!f1oor;if(
12、f1oor=0)(break;)if(f1oor=1ower1ayers)&(f1oor=Upper1ayers)&(f1oor!=States1)(if(f1oor0)T(Digita1Buttonf1oor-1ower1ayers=1;)e1se地上(Digita1Buttonf1oor-1ower1ayers-1=1;没有楼)coutend1;电梯外部各楼层输入上楼信号COUt请电梯外部乘客输入上楼信号!f1oor;if(f1oor=0)(break;)e1se(if(f1oor=1ower1ayers)&(f1oorUpper1ayers)&(f1oor!=States1)(if(f1
13、oor0)T(OuterUpButtonfIoor-1ower1ayers=1;)e1se地上(OuterUpButtonf1oor-1ower1ayers-1=1;没有楼)coutend1;电梯外部各楼层输入下楼信号CoUt”请电梯外部乘客输入下楼信号,end1;coutf1oor;if(f1oor=0)(break;)e1se(if(f1oor1ower1ayers)&(f1oor=Upper1ayers)&(f1oor!=States1)(if(f1oor0)T(OuterDownButtonf1oor-1ower1ayers=1;)e1se地上(OuterDownButtonf1oor-1o