Question: Write a C++ class to implement the elevator class defined below. Here is file e1.h: *Note: you can modify the e1.h in anyway and your

Write a C++ class to implement the elevator class defined below. Here is file e1.h:

*Note: you can modify the e1.h in anyway and your toString and reportAction routines should produce output exactly like the sample run below.

plz compile and test the c++ file before submit it, and attach a photo when compile.

class Details

elevator.h

#ifndef ELEVATOR_H

#define ELEVATOR_H

#define DEFAULT_FLOORS 5

#define TIME_BETWEEN_FLOORS 1000 /* in milliseconds, an integer */

namespace egre246 {

class Elevator {

public:

enum action { AT_FLOOR,STOPPED,MOVING_UP,MOVING_DOWN,DOOR_OPENING,DOOR_CLOSING };

Elevator(int timeBetween = TIME_BETWEEN_FLOORS); // default name: \"elevator #1\"

Elevator(std::string name,bool inServ,int totalFloors, int currentFloor,

int timeBetween = TIME_BETWEEN_FLOORS);

bool getInService() const; // returns if in service

void setInService(bool); // sets inService

std::string getName() const;

void setName(std::string);

int getNumFloors() const; // returns total # of floors; ground floor == 0

int getCurrFloor() const; // returns current floor

int getTimeBetweenFloors() const; // returns timeBetweenFloors

void setTimeBetweenFloors(int); // sets timeBetweenFloors;

// must be > 0, if not, does nothing

// door opening & closing requires TIME_BETWEEN_FLOORS / 2 amount of time

void openDoor(); // if elevator isnt moving, open the door & report action;

// otherwise do nothing

void closeDoor(); // if elevator isnt moving, close the door and report action;

// otherwise do nothing

void moveTo(int); // move to floor if argument is a legal floor, do nothing otherwise;

// report action if moving up or down (once, see sample run);

// report action when you pass each floor; report action when

// elevator stops; do nothing / report nothing if already at floor

bool isDoorOpen(); // returns true of door is open, false otherwise

bool isMoving(); // rturns true if elevator is moving, false otherwise

1

void reportAction(Elevator::action) const; // reports action to standard output

std::string toString() const; // returns string representation of Elevator

private:

std::string name; // name of the elevator

int numFloors, // total number of floors

currFloor, // current floor

timeBetweenFloors; // time between floor, in milliseconds

bool inService, // is elevator in service?

doorOpen, // is the door open?

moving; // is the elevator moving?

};

} #endif

SampleDriver:

Here is a sample driver program that can be used as the first step in testing your class:

#include using namespace std; #include \"Elevator.h\" using namespace egre246;

int main(void) {

Elevator e1;

cout

e1.setInService(true);

cout

e1.moveTo(5);

e1.moveTo(4);

cout

e1.moveTo(2);

e1.openDoor();

cout

e1.closeDoor();

cout

}

/*You should probably make a more thorough driver to test your class bette*/

SampleDriverOutput:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!