Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(c++) make your own to simulate how an elevator handles and keeps track of reque

ID: 3725076 • Letter: #

Question

(c++) make your own to simulate how an elevator handles and keeps track of requests made by users. Here is how an elevator works: A user pushes either the up or down button to request the elevator. Once the elevator arrives, the user gets in and specifies his/her destination floor.Meanwhile, other users outside or inside the elevator make requests as well. The elevator story the requests and handles them efficiently.• A simple algorithm for handling requests works like this: all requests users make are stored. The elevator prioritizes the requests that are on the way where it’s going but also based on a first come first served principle. It is up to you how you design the algorithm. As a recommendation, observe how an elevator works (e.g. the elevator we have at FH) and simulate how it works. (c++)

Explanation / Answer

Since the question only asks for an algorithm and not a working program, I have written a class 'elevator' which has all the necessary functions for implementing this. From the driver function (main) make an object of the class or take/initialise to what ever case you want. The algorithm will work fine.

PROGRAM CODE:

using namespace std;

class elevator{

public:

int current, next, process,req;

//Constructor resets everything to 0. And asks the user to enter 1 to go up and -1 to go down

elevator(){

current=0;

next=0;

process=0;

cout<<" Enter 1 to go up andd -1 to go down ";

cin>>req;

checkprocess(req);

}

/*This checks if the lift is coming to the requested floor/direction

if the lift is not coming in the required direction, it requests the lift to come in that direction */

void checkprocess(int req){

if (req==process)

cout<<" The lift is coming to your floor ";

else

checkrequest(req);

}

/*this checks if the request can be directly executed.

if there is already a request pending, this will store it for later execution

if no request is pending, this will initiate the lift to start moving in the requested direction*/

void checkrequest(int req){

if (current!=0)

next = req;

else current = req;

while (current!=0){

initiateprocess(current);

current=next;

}

}

//commands the lift to start moving in the required direction

void initiateprocess(int current){

if(current==1){

cout<<" The lift has started going up";

process=1;}

else if (current == -1){

cout<<" The lift has started moving down";

process = -1;}

current=next;

next=0;

}

};