[C++]课题设计:电梯问题(第三版,本人最终版)

//Bell.h#ifndef BELL_H#define BELL_Hclass Bell{public: void Ring() {  cout  }};#endif //BELL_H //Building.h#ifndef BUILDING_H#define BUILDING_H#include "Elevator.h"#include "Floor.h"#inc
摘要由CSDN通过智能技术生成

//Bell.h

#ifndef BELL_H
#define BELL_H

class Bell{
public:
 void Ring()
 {
  cout << "电梯铃发出:叮!" << endl;
 }
};

#endif //BELL_H

 

//Building.h

#ifndef BUILDING_H
#define BUILDING_H

#include "Elevator.h"
#include "Floor.h"
#include "ElevatorDoor.h"

class Building {
public:
 void PressOutsideButton1(vector<Person>::iterator);
 void PressOutsideButton2(vector<Person>::iterator);
protected:
 Floor F1;
 Floor F2;
 Elevator Ele;
 ElevatorDoor EleDoor1;
 ElevatorDoor EleDoor2;
 Button OutsideButton1;
 Button OutsideButton2;
 void CheckElevatorOutsideButton();
};

inline void Building::PressOutsideButton1(vector<Person>::iterator iter)
{
 (*iter).PrintPersonNum();
 cout << "按下大楼第1层的电梯外开关,";
 if (Ele.State==1) EleDoor1.Open();
 else if (Ele.State==2)
 {
  Ele.Down2to1();
  OutsideButton1.LightOn();
 }
 else OutsideButton1.LightOn();
}

inline void Building::PressOutsideButton2(vector<Person>::iterator iter)
{
 (*iter).PrintPersonNum();
 cout << "按下大楼第2层的电梯外开关,";
 if (Ele.State==2) EleDoor2.Open();
 else if (Ele.State==1)
 {
  Ele.Up1to2();
  OutsideButton2.LightOn();
 }
 else OutsideButton2.LightOn();
}

inline void Building::CheckElevatorOutsideButton()
{
 EleDoor1.Close(); //执行电梯关门造作。
 EleDoor2.Close();
 if (Ele.State==1 ||Ele.State==2)//电梯状态静止
 {
  if (OutsideButton1.LightState()) //如果1层外的灯还亮着
   Ele.Down2to1(); //让电梯从2层去1层
  if (OutsideButton2.LightState()) //如果2层外的灯还亮着
   Ele.Up1to2(); //让电梯从1层去2层
 }
}

#endif // BUILDING_H

 

//Button.h

#ifndef BUTTON_H
#define BUTTON_H

#include <iostream>
using namespace std;

class Button{
public:
 Button():State(0){}
 void LightOn();
 void LightOff();
 bool LightState() {return State;}
private:
 bool State;     // 0:灭  1:亮
};

inline void Button::LightOn()
{
 if (!State)
 {
  State = 1;
  cout << "开关的灯亮了。"<<endl;
 }
}

inline void Button::LightOff()
{
 if (State)
 {
  State = 0;
  cout << "开关的灯灭了。"<<endl;
 }
}

#endif //BUTTON_H

 

//Elevator.cpp

#include "Elevator.h"

void Elevator::Next()
{
 if (LeftTime==0)
 {
  if (State==12)  //到达了2层
  {
   State=2;
   Stop();
   if (InsideButton2.LightState())
   {
    cout << "电梯内";
    InsideButton2.LightOff();
   }
   ElevatorBell.Ring();
  }
  if (State==21)  //到达

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值