0% found this document useful (0 votes)
38 views

Elevatorsetup: Class Public

The document defines an Elevator class to model an elevator system. The Elevator class tracks the elevator's sensors, properties like current floor, and methods to control the elevator's movement and doors. It includes a constructor to initialize an elevator object based on total floors and number of basements. The main function initializes an elevator, gets input from the user to set up the elevator properties, and then enters a loop to alternately display a summon menu and floor selection menu while moving and controlling the elevator doors.

Uploaded by

Rakhmeen Gul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Elevatorsetup: Class Public

The document defines an Elevator class to model an elevator system. The Elevator class tracks the elevator's sensors, properties like current floor, and methods to control the elevator's movement and doors. It includes a constructor to initialize an elevator object based on total floors and number of basements. The main function initializes an elevator, gets input from the user to set up the elevator properties, and then enters a loop to alternately display a summon menu and floor selection menu while moving and controlling the elevator doors.

Uploaded by

Rakhmeen Gul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#ifndef ElevatorSetup

#define ElevatorSetup

class Elevator
{
public:

//Sensors of elevator
bool door_closed;
bool elevator_moving;
bool elevator_at_floor;
bool elevator_between_floors;

//Elevator Properties
int total_floors;
int current_floor;
int no_basement;

public:
//Control signals
time_t change_door_status(bool);
void move_elevator(int);
void stop_elevator();

//Buttons
void summon_elevator();
void go_to_floor();

//Action to close door


void check_door(time_t, time_t);
bool check_floor(int);

//Constructor to make elevator object


Elevator(int floors, int basements);

};

#endif

#include <iostream>
#include "ElevatorSetup.h"
#include <time.h>
#include <windows.h>

using namespace std;

Elevator::Elevator(int floors, int basements)


{
total_floors = floors;
no_basement = basements;
door_closed = true;
elevator_moving = false;
elevator_at_floor = true;
elevator_between_floors = false;
current_floor = 0;
}

time_t Elevator::change_door_status(bool new_status)


{
if (new_status)
{
door_closed = new_status;
cout << "\n\tClosing doors . . ." << endl;
}
else
{
door_closed = new_status;
cout << "\n\tOpening doors . . ." << endl;
}

return time(0);
}

void Elevator::move_elevator(int floor)


{
change_door_status(true);

cout << "\n\tElevator is moving";


if (floor < current_floor)
{
while (floor != current_floor)
{
cout << "\n\n\tCurrent Floor: " << current_floor;
current_floor--;
Sleep(1000);
}
}
else if (floor > current_floor)
{
while (floor != current_floor)
{
cout << "\n\n\tCurrent Floor: " << current_floor;
current_floor++;
Sleep(1000);
}
}
current_floor = floor;
}

void Elevator::summon_elevator()
{
cout << "\n\t-----------------------------------";
cout << "\n\t| Summon Elevator |";
cout << "\n\t-----------------------------------";

int floor;
do
{
cout << "\n\tEnter your current floor (0 for ground and - for basement): ";
cin >> floor;
} while (check_floor(floor));

move_elevator(floor);

void Elevator::go_to_floor()
{

cout << "\n\t-----------------------------------";


cout << "\n\t| Welcome! Please Enter |";
cout << "\n\t-----------------------------------";

int floor;
do
{
cout << "\n\tWhich floor do you want to go to (0 for ground and - for
basement): ";
cin >> floor;
} while (check_floor(floor));

move_elevator(floor);

void Elevator::check_door(time_t start_time, time_t current_time)


{
if ((current_time - start_time) > 3 && !door_closed)
{
change_door_status(true);
}
}

bool Elevator::check_floor(int floor)


{
if ((floor < -no_basement) || (floor > total_floors))
{
return true;
}
return false;
}

#include <iostream>
#include <time.h>
#include "ElevatorSetup.h"
#include <windows.h>

using namespace std;


//Global variable to keep track of whether menu is displayed
bool menu = true;

int main(void)
{
//Taking input the elevator properties first time elevator is setup
int password;
cout << "\n\tEnter Admin Password to setup Elevator: ";
cin >> password;

while (password != 12345)


{
cout << "\n\tPlease try again: ";
cin >> password;
}

cout << "\n\t-----------------------------------";


cout << "\n\t| Welcome to Buddies Elevator |";
cout << "\n\t-----------------------------------";

int highest_floor;
cout << "\n\tEnter the highest floor: ";
cin >> highest_floor;

while (highest_floor < 0 || highest_floor > 200)


{
cout << "\n\tInvalid Entry. Try again: ";
cin >> highest_floor;
}

int no_of_basements;
cout << "\tEnter the number of basements: ";
cin >> no_of_basements;

while (no_of_basements < 0 || no_of_basements > 10)


{
cout << "\n\tInvalid Entry. Try again: ";
cin >> no_of_basements;
}

Elevator BuddiesElevator(highest_floor, no_of_basements);

cout << "\n\tSetup Complete! You are ready to go ... ";

time_t start_time = time(0);


while (1)
{
BuddiesElevator.check_door(start_time, time(0));

if (menu)
{
BuddiesElevator.summon_elevator();

start_time = BuddiesElevator.change_door_status(false);

menu = false;
}
if (!menu)
{
BuddiesElevator.go_to_floor();
start_time = BuddiesElevator.change_door_status(false);
menu = true;

return 0;
}

You might also like