MUST BE WRITTEN IN OBJECT ORIENTED C++ STYLE. Please make sure the program fulfi
ID: 3771717 • Letter: M
Question
MUST BE WRITTEN IN OBJECT ORIENTED C++ STYLE.
Please make sure the program fulfills all requirements before posting.
MUST USE CLASSES
MUST WORK
Industrial engineering, it is sometimes necessary to simulate manufacturing and service operations for the purpose of improving efficiency and optimizing the system. In this problem you are to model a rapid oil change and lubrication business. The queue data structure can be used to do this. Assume that the station has the following:
A. There are three bays for changing oil
B. It takes 15 minutes to service each car
C. One car arrives randomly between every 2 and 20 minutes
D. At the end of a 12-hour day, all waiting car are sent away.
Write you program to model 30 days of operation. Determining the average waiting time for the cars and the total amount of idle time for the bays. Run your program 12 times to get an understanding of the variability of the results. Report all your answers.
Explanation / Answer
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include<algorithm>
class Car
{
int m_time;
Car()
{
m_time = ( ( rand() % 19 ) + 2 );//range [2,20] minutes
}
public:
int getTime(void) const
{
return m_time;
}
void setTime(int _time)
{
m_time = _time;
}
static Car create(void)
{
return Car();
}
};
class Station
{
struct Compare
{
bool operator()(Car const & p1, Car const & p2)
{
return p1.getTime() > p2.getTime();
}
};
std::priority_queue<Car , std::vector<Car> , Compare > m_cars;
std::queue<Car> m_carsOnWaitingAtBay1;
std::queue<Car> m_carsOnWaitingAtBay2;
std::queue<Car> m_carsOnWaitingAtBay3;
public:
Station() : m_cars() , m_carsOnWaitingAtBay1() ,m_carsOnWaitingAtBay2() ,m_carsOnWaitingAtBay3() {}
void SimulateOneDay(unsigned int nCars)
{
std::cout << "Expecting " << nCars << " cars ..." << std::endl;
size_t n = 0;
for ( ; n < nCars ; ++ n)
m_cars.push( Car::create() );
int nHours = 24;
const int timeMultiplier = 60;
const int aDay = nHours * timeMultiplier ; // in minutes
int currentTime = 0;
int currentTimeAtBay1 = 0;
int currentTimeAtBay2 = 0;
int currentTimeAtBay3 = 0;
while( currentTime ++ < aDay )
{
if(!m_cars.empty())
{
if(m_cars.top().getTime() < currentTime )
{
std::cout << "Frame " << currentTime << " .Car n." << m_cars.top().getTime() << " arriving at bay n.";
Car _car = Car::create();
_car.setTime(m_cars.top().getTime());
int Bay = 1 + (rand() % 3);
switch(Bay)
{
case 1:
std::cout << "1 ";
m_carsOnWaitingAtBay1.push( _car);
break;
case 2:
std::cout << "2 ";
m_carsOnWaitingAtBay2.push( _car);
break;
case 3:
std::cout << "3 ";
m_carsOnWaitingAtBay3.push( _car);
break;
default:break;
}
int avgtime =currentTimeAtBay1+currentTimeAtBay2+currentTimeAtBay3/3;
std::cout<<"time of arrival";
std::cout<<avgtime;
m_cars.pop();
}
}
if(!m_carsOnWaitingAtBay1.empty())
{
if( ++ currentTimeAtBay1 > 15 )
{
m_carsOnWaitingAtBay1.pop();
currentTimeAtBay1 = 0;
}
}
if(!m_carsOnWaitingAtBay2.empty())
{
if( ++ currentTimeAtBay2 > 15 )
{
m_carsOnWaitingAtBay2.pop();
currentTimeAtBay2 = 0;
}
}
if(!m_carsOnWaitingAtBay3.empty())
{
if( ++ currentTimeAtBay3 > 15 )
{
m_carsOnWaitingAtBay3.pop();
currentTimeAtBay3 = 0;
}
}
}
int avgtime =currentTimeAtBay1+currentTimeAtBay2+currentTimeAtBay3/3;
std::cout<<"avg time after poping";
std::cout<<avgtime;
}
};
int main(int argc , char * argv[])
{
srand((unsigned)time(NULL));
{
Station station;
int nCarsThatDay = 1 + ( rand() % 100 ) ; // range [1 , 100]
station.SimulateOneDay(nCarsThatDay);
}
return EXIT_SUCCESS;
}
as we know we have only 3 oil bays we should have track of time for each of it and the car arrival
to make it all cars that are in service in queue of 3 length whereas the remaining cars are in priority queue.
by placing them in currect order and after 12 hours they all been poped out so the avg time at that would be zero.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.