Further damage control inbound in the form of harsh solution critique.
@Ericool: We do not, as a matter of principle, give out full code solutions on this forum, and here's why:
http://www.cplusplus.com/articles/DjGEy60M/
@Line 5:
#include <windows.h>
There is no reason to have this header or any of the typedefs you are using in it in this code. In fact, there are reasons not to have it. How do you know that the OP isn't coding on a remote Linux machine?
@Line 12: Private default constructor for Car.
Why is this private? To screw up the people who want to use alternate allocation or placement new?
@Line 14:
( ( rand() % 19 ) + 2 )
Use of C-style random functions. However, since <random> is in fairness a bit beginner unfriendly and lesser-known, I'll cut some slack here.
@Line 26:
static Car create(void)
This code would be pointless if your default constructor wasn't private. Seriously, why?
@Line 42:
std::priority_queue<Car , std::vector<Car> , Compare > m_cars;
I suspect you are doing something very incorrect here. You are aware that priority_queue sorts, and the initial m_time value of the cars is the time each car arrives after the previous one, right? Admittedly, sleep deprivation isn't doing good things to me, but in either case, even if this is by some miracle correct, it is seriously overdesigned. An integer in Station's simulation loop that's randomly set from 2 to 20 would have sufficed, and probably been better.
@Lines 43-45:
std::queue<Car> m_carsOnWaitingAtBayN;
How about a 3-long array of them queues?
@Line 48:
Station() : m_cars() , m_carsOnWaitingAtBay1() ,m_carsOnWaitingAtBay2() ,m_carsOnWaitingAtBay3()
Redundant default constructor calls. This isn't Java.
@Line 74:
int Bay = 1 + (rand() % 3); //Michael?
This is neither optimal nor realistic. Even if sending cars to bays is taken out of the station's hands, the drivers themselves will each tend to go for the shortest line. There's nothing that I saw in the problem prompt that called for random assignment.
@Lines 76-128:
And that's why the 3-long array of queues would have been better.
@Line 143:
system("pause");
http://www.cplusplus.com/articles/iw6AC542/
This is typically a problem on Windows, caused by really dumb IDEs that don't know enough to keep the console open after the program finishes. However, it does strike right at one of the main philosophical problems with the way you are thinking about programming. After all, a console program should be run from the console |
http://www.cplusplus.com/articles/j3wTURfi/
TL;DR: system() is not something that should be used here.
In other words, system("pause") is bad design both on a practical and philosophical level.
@Program:
This does not provide any sort of aggregate data that the prompt specifically called for, namely "the average waiting time for the cars and the total amount of idle time for the bays". It additionally does not simulate 30 days.
-Albatross