C Project 1 Elevator Following the class diagram shown below
C++
Project 1: Elevator Following the class diagram shown below, create the class Elevator. An Elevator represents a moveable carriage that lifts passengers between floors. As an elevator operates, its sequence of operations are to open its doors, let off passengers, accept new passengers, handle a floor request, close its doors and move to another floor where this sequence repeats over and over while there are people onboard. A sample driver for this class is shown below. Each elevator request translates into just a single line of output shown below. You should probably make a more thorough driver to test your class better.
Following the class diagrams shown below, implement the Elevator class. Embed your class in a suitable test program that provides the sample dialogue shown below. You may choose to create any number of additional methods, but you are required to implement all of the public methods shown below. You are free to ignore the private parts of the class I suggest below.
Class Details
Sample Driver
Elevator
void openDoors( );
void closeDoors( );
void letOffPassengers( int amount );
void acceptPassengers( int amount );
void requestFloor( int floor );
bool isOnFloor( int floor );
int getFloor( );
int getPassengers( );
int main() {
// Let\'s use the Elevator
Elevator e;
e.openDoors();
e.acceptPassengers( 5 );
e.requestFloor( 3 );
e.closeDoors();
e.openDoors();
e.letOffPassengers( 1 );
e.acceptPassengers( 2 );
e.requestFloor( 4 );
e.openDoors();
e.letOffPassengers( 3 );
return( 0 );
}
SAMPLE DRIVER OUTPUT
Elevator on Floor 1 with 0 passengers
Elevator Door\'s Open
Elevator has 5 passengers
Passengers want floor 3
Elevator moving to floor 3
Elevator Door\'s Open
Elevator has 4 passengers
Elevator has 6 passengers
Passengers want floor 4
Elevator moving to floor 4
Elevator Door\'s Open
Elevator has 3 passengers
| Class Details | Sample Driver | |||
| #include #include \"Elevator.h\" using namespace std; int main() {
return( 0 ); } | |||
| SAMPLE DRIVER OUTPUT Elevator on Floor 1 with 0 passengers |
Solution
#include <iostream>
using namespace std;
int main()
{
//stores that button was pushed.
int pushed = 1;
//Up buttons outside the elevator
int Up1;
int Up2;
int Up3;
int Up4;
int Up5;
//Keep track of current floor
int CurrentFloor;
//to end all loops
int x;
//Simulate people calling elevator
//check floor 1
cout << \"If floor one has someone on it, press one. If not, press 0.\" << endl;
cin >> Up1;
if(Up1 == pushed){
cout << \"Floor one has been qued!\" << endl;
}
//check floor 2.
cout << \"If floor two has someone waiting, press one. If not, zero.\" << endl;
//did someone call on floor 2?
cin >> Up2;
// If so...
if(Up2 == pushed){
cout << \"Floor two has been qued.\" << endl;
}
//check F3
cout << \"If floor 3 has someone waiting press one. If not, press 0.\" << endl;
cin >> Up3;
if(Up3 == pushed){
cout << \"Floor three has been qued\" << endl;
}
//check F4
cout << \"If someone is on Floor 4 press one. If not press 0\" << endl;
cin >> Up4;
if(Up4 == pushed){
cout << \"Floor 4 has been qued!\" << endl;
}
//check F5
cout << \"If someone is on Floor 5, press one. If not press 0.\" << endl;
cin >> Up5;
if(Up5 == pushed){
cout << \"Floor 5 has been qued!\" << endl;
}
//Pick Up System
if(Up1 == pushed){
cout << \"Elevator has arrived on Floor One! Door opening!\" << endl;
while(x < 200000000) {
cout << \"Test\" << endl;
x++;
}
cout << \"Door has opened.\" << endl;
CurrentFloor = 1;
}
//elevator rising
cout << \"Elevator rising to next qued level.\" << endl;
while(x < 200000000){
cout << \"Test\" << endl;
x++;
}
if(Up2 == pushed){
cout << \"Elevator has arrived on Floor Two! Door opening!\" << endl;
while(x < 200000000){
cout << \"Test\" << endl;
x++;
}
cout << \"Door has opened.\" << endl;
CurrentFloor = 2;
}
cout << \"Elevator rising to next qued level.\" << endl;
while(x < 200000000){
cout << \"TEST\" << endl;
x++;
}
if(Up3 == pushed){
cout << \"Elevator has arrived on Floor Three! Door opening!\" << endl;
while(x < 200000000){
cout << \"TEST\" << endl;
x++;
}
cout << \"Door has opened.\" << endl;
CurrentFloor = 3;
}
}



