This is c++ question Please make 2 class and a main function using copy construc
ID: 3741504 • Letter: T
Question
This is c++ question
Please make 2 class and a main function using copy constructor
This lab implements classes that may be used to simulate the operation of an elevator in a building as people request to move between floors. The classes use randomized numbers to determine the times that people arrive, which floor they want to go to, etc. In this lab you will write two classes and a main program that demonstrates the use of the classes. This lab does NOT include the complete simulation of the elevator. The building has ten floors, numbered 0..9. Each person will arrive at the buildinglobby, which is floor 0. The person will have a definite floor that she wishes to visit for a definite amount of time. Using documentation such as your textbook Ch. 3.9 and www.cplusplus.com, review C++ pseudo-random number functions, especially the seed function. 1. 2. Write a function named timeVisiting that accepts two integer parameters, a and b. The range of a and b are 0a,bINT_MAX. returns a random integer uniformly distributed between a and b inclusive.. (You will need to scale and shift the value returned by rand().). . 3. Write a class named Person The class contains data members for o 0 o time of arrival at the building. destination floor that the person will visit, uniformly distributed in the range 0.9. time that the person will spend at the destination floor, uniformly distributed in a sensible range time the person arrives back at the lobby to leave the building. OExplanation / Answer
#include <iostream>
#include <string>
using namespace std;
class Person
{
private:
int m_ArrivalHourTime;
int m_ArrivalMinutesTime;
int m_destinationFloor;
int m_timeSpendDestinationFloor; //Minutes
int m_timeBackLobbyHour;
int m_timeBackLobbyMinute;
public:
Person()
{
}
Person(int arrivalHourTime, int arrivalMinutesTime)
{
m_ArrivalHourTime = arrivalHourTime;
m_ArrivalMinutesTime = arrivalMinutesTime;
Initilize();
}
void Initilize()
{
m_timeSpendDestinationFloor = timeVisiting(0, 120);
int tBack = m_timeSpendDestinationFloor + m_ArrivalMinutesTime;
m_timeBackLobbyHour = m_ArrivalHourTime + tBack/60;
m_timeBackLobbyMinute = tBack%60;
}
int timeVisiting(int a, int b)
{
int v = rand()%(b-a+1) + a;
return v;
}
void Display()
{
cout<<"Entery time "<<m_ArrivalHourTime<<":"<<m_ArrivalMinutesTime<<endl;
cout<<"Time spend in des floor "<<m_timeSpendDestinationFloor<<" minutes"<<endl;
cout<<"Time back to lobby "<<m_timeBackLobbyHour<<":"<<m_timeBackLobbyMinute<<endl;
}
};
class ElevatorQueue
{
private:
int counter = 0;
Person m_personArray[1000];
public:
ElevatorQueue()
{
}
ElevatorQueue(const ElevatorQueue &eQ)
{
for(int i = 0; i<1000; i++)
{
m_personArray[i] = eQ.m_personArray[i];
}
}
int GetCounter()
{
return counter;
}
Person* GetPersonArray()
{
return m_personArray;
}
void AddValue(Person person)
{
m_personArray[counter] = person;
counter++;
}
void ChangeValueAtPosition(int i, Person p)
{
m_personArray[i] = p;
}
};
int main()
{
ElevatorQueue elQ;
cout<<"Elevator demo start"<<endl;
while(true)
{
int hours;
cout<<"Enter the person entery in hours (-1 to exit)"<<endl;
cin>>hours;
if(hours == -1)
{
break;
}
int seconds;
cout<<"Enter the person entery in seconds (-1 to exit)"<<endl;
cin>>seconds;
Person person(hours,seconds);
elQ.AddValue(person);
}
Person *personArray = elQ.GetPersonArray();
for(int j=0; j< elQ.GetCounter(); j++)
{
personArray->Display();
personArray++;
}
cout<<"Demo of copy constructor for ElevatorQueue class"<<endl;
ElevatorQueue eQ1;
Person person(5, 18);
eQ1.AddValue(person);
ElevatorQueue eQ2 = eQ1;
Person person2(4, 19);
eQ1.ChangeValueAtPosition(0,person2);
cout<<"First object data"<<endl;
eQ1.GetPersonArray()->Display();
cout<<"Second object data"<<endl;
eQ2.GetPersonArray()->Display();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.