Question

In: Computer Science

Elevator (C++) Following the diagram shown below, create the class Elevator. An Elevator represents a moveable...

Elevator (C++)

Following the 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.

Elevator1  Elevator2

Elevator

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 my_Floor;
int my_NumberOfPassengers;
bool my_DoorsOpen;

Sample Driver Code

Elevator e;
e.openDoors();
e.acceptPassengers( 5 );
e.requestFloor( 3 );
e.closeDoors();
e.openDoors();
e.letOffPassengers( 1 );
e.acceptPassengers( 2 );
e.requestFloor( 4 );
e.closeDoors();
e.openDoors();
e.letOffPassengers( 3 );

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

Solutions

Expert Solution

Elevator.cpp ------

#include<iostream>

using namespace std;

class Elevator
{
   private:
       int my_Floor;
       int my_NumberOfPassengers;
       bool my_DoorsOpen;
   public:
       Elevator();//constructor
       void openDoors();//this function is used to open the door of the elevator
       void closeDoors();//this function is used to close the door of the elevator
       void letOffPassengers(int);//this function is used to let off passengers form the lift
       void requestFloor(int);//this function is used to go to a floor
       bool isOnFloor(int);//this function checks whether the lift is in specified floor
                    //and if it is in the floor then it returns true else returns false
       int getFloor();//this function returns the current floor number
       int getPassengers();//this function returns total number of passengers currently is in the elevator
       void acceptPassengers(int);//accepts passengers in the elevator
};

void Elevator::requestFloor(int floor)
{
   if(floor<0)
   {
       cout<<"Invalid Floor\n";
       return;
   }
   cout<<"Passengers want floor "<<floor<<endl<<"Elevator moving to floor "<<floor<<endl;
}

void Elevator::letOffPassengers(int amount)
{
   my_NumberOfPassengers-=amount;
   cout<<"Elevator has "<<my_NumberOfPassengers<<" passengers\n";
}

void Elevator::acceptPassengers(int amount)
{
   my_NumberOfPassengers+=amount;
   cout<<"Elevator has "<<my_NumberOfPassengers<<" passengers\n";
}

void Elevator::closeDoors()
{
   my_DoorsOpen=false;
}

void Elevator::openDoors()
{
   cout<<"Elevator Door's Open\n";
   my_DoorsOpen=true;
}

Elevator::Elevator()
{
   cout<<"\nElevator on Floor 1 with 0 passengers\n";
   my_Floor=1;//initally the elevator is in the floor 1
   my_NumberOfPassengers=0;//initially the elevator is empty
   my_DoorsOpen=false;//initiall the door of the elevator is closed
}

int Elevator::getFloor()
{
   return my_Floor;
}

int Elevator::getPassengers()
{
   return my_NumberOfPassengers;
}

bool Elevator::isOnFloor(int floor)
{
   if(floor==my_Floor)
       return true;
   else
       return false;
}

int main()
{
   Elevator e;
   e.openDoors();
   e.acceptPassengers( 5 );
   e.requestFloor( 3 );
   e.closeDoors();
   e.openDoors();
   e.letOffPassengers( 1 );
   e.acceptPassengers( 2 );
   e.requestFloor( 4 );
   e.closeDoors();
   e.openDoors();
   e.letOffPassengers( 3 );
   return 0;
}


Related Solutions

In C code Consider the finite state machine shown below that controls a two story elevator....
In C code Consider the finite state machine shown below that controls a two story elevator. The elevator has a toggle button that can be in the UP position or the DOWN position, and an LED light that can be RED or GREEN . When the elevator is on the GROUND floor the light is RED, and when the elevator is on the FIRST floor the light is GREEN. Assume the existence of function enum Button getButton(); that returns a...
Consider the finite state machine shown below that controls a two story elevator. The elevator has...
Consider the finite state machine shown below that controls a two story elevator. The elevator has a toggle button that can be in the UP position or the DOWN position, and an LED light that can be RED or GREEN . When the elevator is on the GROUND floor the light is RED, and when the elevator is on the FIRST floor the light is GREEN. Assume the existence of function enum Button getButton(); that returns a value of DOWN...
Complete the C++ class Triple below so that it represents a vector with 3 elements: (a,...
Complete the C++ class Triple below so that it represents a vector with 3 elements: (a, b, c) Most of these function bodies can be written in only a few lines. Error checking is not required. Test your class using the test.h file. The triple.cpp file is the code unit tested on submission. main.cpp #include #include #include #include "triple.h" #include "test.h" using namespace std; int main() { myTest(); return 0; } triple.h #ifndef TRIPLE_H #define TRIPLE_H #include #include using namespace...
Four displacement vectors, A, B, C, and D, are shown in the diagram below. Their magnitudes...
Four displacement vectors, A, B, C, and D, are shown in the diagram below. Their magnitudes are:  A = 16.2 m, B = 11.0 m, C = 12.0 m, and D =  24.0 m What is the magnitude, in meters, and direction, in degrees, of the resultant vector sum of A, B, C, and D? Give the direction as an angle measured counterclockwise from the +x direction.
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int maxRevenue(int[] billboard, int[] revenue, int distance, int milesRes) { int[] MR = new int[distance + 1]; //Next billboard which can be used will start from index 0 in billboard[] int nextBillBoard = 0; //example if milesRes = 5 miles then any 2 bill boards has to be more than //5 miles away so actually we can put at 6th mile so we can add...
create class diagram of the following case. Case: Once a month, the person in charge of...
create class diagram of the following case. Case: Once a month, the person in charge of the human resources area of ​​the organization prepares the payroll to be paid. Once the calculation is made, the manager accesses and authorizes the payment of the information generated for payment, which is updated in the database to be sent to the Bank. The person in charge of the payroll, in turn, is in charge of making the entry and / or withdrawal of...
In C++, Implement the following class that represents a clock. Clock - hour: int - minute:...
In C++, Implement the following class that represents a clock. Clock - hour: int - minute: int - meridiem: string + Clock() + Clock(hr: int, min: int, mer: string) + setTime(hr: int, min: int, mer: string): void + setHour(hr: int): void + setMinute(min: int): void + setMeridiem(mer: string): void + getHour(): int + getMinute(): int + getMeridiem(): string + void tick() + string asString() + string asStandard() Implementation Details: • The default constructor should set the clock to midnight (12:00...
The following diagram represents the money market in Australia.
2. The impact of monetary policy using the AD-AS model The following diagram represents the money market in Australia. Imagine that Australia is a closed economy that does not interact with other economies in the world. The money market is currently in equilibrium at an interest rate of 6.00%, and the quantity of money in the economy is $1 trillion, as indicated by the grey star. Imagine the Reserve Bank of Australia (RBA) announces that it is lowering its target interest rate...
Revenue Recognition Using Word or Excel, create a diagram or model that represents the series of...
Revenue Recognition Using Word or Excel, create a diagram or model that represents the series of criteria found in CON5. Using Word or Excel, create a diagram or model that represents the process of the revenue recognition process. Guidance: Diagram the process of revenue recognition. Start with the process. What starts the process? Think through from the business perspective what happens when you purchase a good or service? What are the journal entries? What are the accounts? What happens to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT