C realizes the elevator scheduling process
C++ object implementation class diagram
Comparative analysis
C
In C, various functions are mainly used for data processing of variables.
Each function may have high complexity, and a function can obtain data similar to the final result after performing multiple operations.
Each function constitutes a core algorithm, and there is no other tangible structure other than the algorithm.
The flow of data is relatively random, with only a relative flow direction, and there is no relatively strict affiliation structure level.
C++
C++ is mainly an idea of simulating things, and the main features of the elevator are bundled and constructed as classes inside the program.
In a class, the direction of data flow is fixed, private data cannot be tampered with at will, and it has high concealment.
Classes can have member functions to share and implement some small functions, so the core algorithm can be simplified.
In the main function, various parameters can be obtained by calling the public methods of the elevator class to operate the data more conveniently.
Data naming conventions, with distinct affiliation levels, are less prone to errors in the face of big data.
relatively simple elevator
#include<queue>
class Elevator
{
private:
int CurrentTime; //当前时间
int CurrentFloor; //当前楼层
queue<int> Destination; //目标队列
int CurrentDirection; //当前方向,<0下,>0上
public:
Elevator(); //构造
~Elevator(); //析构
int GetCurrentFloor(); //当前楼层
void SetNextDestination(int); //接受下一层指令
}
Elevator::~Elevator()
{
cout<<"Elevator has been uninstalled!"<<endl;
}
Elevator::int GetCurrentFloor()
{
return CurrentFloor;
}
Elevator::void SetNextDestination(int Next)
{
Destination.push(Next);
CurrentDirection=Next-CurrentFloor;
}