//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

这是一个C++编程项目,实现了电梯的控制系统,包括电梯门、按钮、楼层和状态管理。用户可以按下楼层按钮,电梯根据当前状态和外部按钮的灯是否亮着做出相应动作,如开门、关门、上行或下行。程序还包括了电梯事件的模拟,模拟了人在楼层等待、进入电梯和离开电梯的过程。
&spm=1001.2101.3001.5002&articleId=586433&d=1&t=3&u=9f275c237a354b81b59397bfcd6a6ebe)
5448

被折叠的 条评论
为什么被折叠?



