In: Computer Science
C++
good documentation as well as explanations would be great. I need the code to be written without (#include if possible. Please don't just copy and paste someone else's answer.
In this HW assignment we will simulate a car wash and calculate the arrival time, departure time and wait time for each car that came in for a car wash. We will use the following assumptions about our car wash:
Each car takes 3 minutes from start of the car wash to the end.
Only one car can be in the car wash at a time. This mean that if a car enters a car wash at 1:00 PM then no car can enter the car wash till 1:03 PM.
Simulation will start at the opening time of the car wash and will be represented with 0. We do not not care about the actual time as we are interested in time intervals. Example: a car arrived at time 5 means that car arrived 5 minutes after the opening of the car wash.
We will assume that car wash opens at 8:00 AM and closes at 5:00 PM. This implies that car wash is open for 9 hours or 540 minutes.
Simulation will run for number of minutes given by SIMULATION_END_TIME. We will set it to 540 as our car wash is open for 540 minutes.
The arrival time of cars will be stored in the file named arrival_time.txt. The file will list the arrival time of one car per line. The numbers of cars that will come to our car wash will be variable. You can have an input file with arrival time for 5 cars or for 100 cars. Example of input file is given at the end of this handout. Any car that arrives after the closing time given by SIMULATION_END_TIME will not be serviced.
The program will display the following information about each car: car number, arrival time, car wash start time, departure time, wait time, and total time in form of a table.
Arrival time, car wash start time, and departure time will be in minutes from the opening of the car wash.
Arrival time and car wash start time may be same if there are no cars in the car wash.
Wait time is car wash start time – arrival time.
Total time is the departure time – arrival time.
The program will also display the following statistics: total wait time, average wait time, total car wash use time, percentage of time car was was in use.
Hint: Use a Car class to keep track of car number, car arrival time and car wash start time.
Sample Input File:
1
2
4
10
13
15
16
75
Sample Output (Set SIMULATION_END_TIME to 60 for this example):
Opening Time: 8:00 AM (0 minutes)
Closing Time: 9:00 AM (60 minutes)
Start of Simulation
Car Number |
Arrival Time |
Car Wash |
Departure Time |
Wait Time |
Total |
1 |
1 |
1 |
4 |
0 |
3 |
2 |
2 |
4 |
7 |
2 |
5 |
3 |
4 |
7 |
10 |
3 |
6 |
4 |
10 |
10 |
13 |
0 |
3 |
5 |
13 |
13 |
16 |
0 |
3 |
6 |
15 |
16 |
19 |
1 |
4 |
7 |
16 |
19 |
22 |
3 |
6 |
8 |
75 |
Car arrived after closing time and was not served. |
End of Simulation
Statistics:
Total wait time: 9 minutes
Average wait time: 1 minutes and 17 seconds
Total car wash use time: 21 minutes
Percentage of time car was was in use: 35%
Notes:
Use Queue STL to keep track of the arrival time.
Multiple cars can arrive at same time.
Input file is sorted by arrival time.
Sample arrival_time.txt:
0
3
10
11
11
14
17
17
24
25
35
38
39
45
48
50
52
52
60
62
68
74
86
99
100
118
124
130
133
143
147
150
175
177
182
185
191
195
200
219
230
231
232
233
248
275
281
293
297
302
305
309
310
315
322
327
327
330
339
342
347
352
371
375
375
384
395
398
402
406
414
417
425
432
441
441
450
453
456
458
462
465
466
475
477
480
482
488
491
508
509
513
513
517
519
520
522
524
526
529
532
537
538
539
540
541
/*CODE STARTS HERE*/
#include <iostream>
#include <fstream>
//Sorry but these header files are absolutely necessary//
//Also Use of queue for such a trivial question is an overkill//
#define SIMULATION_END_TIME 540
#define WASHTIME 3
class car
{
int arrival; // time
int departure; // time
int waittime; // duration
int totaltime; // duration
//Washtime = departure - WASHTIME
static int nos;
static int nextfreetime;
static int totalwaittime;
public:
car(int ar)
{
++nos;
arrival = ar;
if (arrival <
nextfreetime)
departure =
nextfreetime + WASHTIME;
else
departure =
arrival + WASHTIME;
nextfreetime = departure;
totaltime = departure -
arrival;
waittime = totaltime -
WASHTIME;
totalwaittime += waittime;
}
void print()
{
if (arrival <=
SIMULATION_END_TIME)
std::cout
<< nos << "\t\t" << arrival << "\t\t"
<< departure - WASHTIME << "\t\t\t" << departure
<< "\t\t" << waittime << "\t\t" <<
totaltime << std::endl;
else
{
std::cout
<< nos << "\t\t" << arrival << "\t\tCar
arrived after closing time and was not served.\n";
std::cout
<< "\nEnd of Simulation\nStatistics:\n";
std::cout
<< "Total wait time :" << totalwaittime << "
minutes\n";
std::cout
<< "Average wait time: " << totalwaittime / (nos - 1)
<< " minutes and " <<
(int)((60.0/(nos-1))*(totalwaittime - (totalwaittime / (nos - 1))))
<< " seconds\n";
std::cout
<< "Total car wash use time: " << WASHTIME * (nos - 1)
<< " minutes\n";
std::cout
<< "Percentage of time car was was in use: " <<
(int)((WASHTIME * (nos - 1) / (float)SIMULATION_END_TIME) *
100);
}
}
};
int car::nos = 0;
int car::nextfreetime = 0;
int car::totalwaittime = 0;
int main()
{
std::ifstream fin("arrival_time.txt");
int arival;
std::cout << "Car Number\tArrival Time\tCar Wash Start Time\tDeparture Time\tWait Time\tTotal Time\n";
while (!fin.eof())
{
fin >> arival;
car(arival).print();
}
fin.close();
return 0;
}
/*CODE ENDS HERE*/