The second c fuck homework

1. C language implementation method: According to the elevator operation mode, change the value of the structure defined as a global variable.
c. Implementation method: use a class to store the attributes of the elevator, and the whole process is to operate on the class.
The two are different: C language is process-oriented, and the parameters of the elevator must be modified in the entire function; while C++ modifies the class representing the elevator state during program operation.

The code of the class is as follows
elevator.h

pragma once

class elevator
{
public:
int lift;//The floor where the elevator is located
int request;//The requested time
int from;//The requested floor
int to;//The destination floor
int time;//Total time
elevator();
~elevator ();
void move(int &lift, int from, int to, int &time, int request);
};

elevator.cpp

include"elevator.h"

include

include

include

using namespace std;
void elevator::move(int &lift, int from, int to, int &time, int request)
{
int ss,sss; ss = lift;
if (request > time)
time += request - time;
time += abs(from - lift);
lift = from;//去接乘客
if (ss != from)
{

    cout << time << " " << lift << endl;time++;
}
time += abs(to - lift);
lift = to;
cout << time <<" "<< lift << endl;
if (ss != to)time++;//送乘客

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325425280&siteId=291194637