Question

In: Computer Science

C++ good documentation as well as explanations would be great. I need the code to be...

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:

  1. Each car takes 3 minutes from start of the car wash to the end.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

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

    1. Arrival time, car wash start time, and departure time will be in minutes from the opening of the car wash.

    2. Arrival time and car wash start time may be same if there are no cars in the car wash.

    3. Wait time is car wash start time – arrival time.

    4. Total time is the departure time – arrival time.

  8. 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.

  9. 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
Start Time

Departure Time

Wait Time

Total
Time

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:

  1. Use Queue STL to keep track of the arrival time.

  2. Multiple cars can arrive at same time.

  3. 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

Solutions

Expert Solution

/*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*/


Related Solutions

C++ good documentation as well as explanations would be great. In this HW assignment we will...
C++ good documentation as well as explanations would be great. 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...
Need C++ code for following with a document describing the code as well: Write a program...
Need C++ code for following with a document describing the code as well: Write a program to implement the game of Tic Tac Toe Four. The game is played on a 4 × 4 chessboard, within 2 players. The player who is playing "X" always goes first. Players alternate placing Xs and Os on the board until either one player has four in a row, horizontally, vertically, or diagonally; or all 16 squares are filled(which is a draw). The program...
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
What do I need to implement this code. I need an ADT //--------------------------------------------- // This would...
What do I need to implement this code. I need an ADT //--------------------------------------------- // This would be the Student.h file //--------------------------------------------- #include <iostream> #include <cassert> using namespace std; // each student have a name, an ID (100000000~999999999), and three grades class Student { private: public: Student(); Student(); setName(); setId(); setGrade (); getName(); getId(); getGrade() ; printAll() ; }; //--------------------------------------------- // This would be the Student.cpp file //--------------------------------------------- //====================== YOUR CODE STARTS HERE ====================== Student::Student() //default constructor { } Student::Student(string aName,...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c program, you should end up with a simple English-French and French-English dictionary with a couple of about 350 words(I've provided 5 of each don't worry about this part). I just need a way to look up a word in a sorted array. You simply need to find a way to identify at which index i a certain word appears in an array of words...
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
c++ I need a code that will fill an array size of 1000, an array of...
c++ I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values. Basically like this: array1[1000] = filled all with random numbers array2[2000] = filled all with random numbers array3[10000] = filled all with random numbers C++ no need for print
C++ Hello .I need to convert this code into template and then test the template with...
C++ Hello .I need to convert this code into template and then test the template with dynamic array of strings also if you can help me move the function out of the class that would be great.also There is a bug where the memory was being freed without using new operator. I cant seem to find it thanks in advance #include using namespace std; class DynamicStringArray {    private:        string *dynamicArray;        int size;    public:   ...
Need a summary of chapter 8 of book ' Good to great'
Need a summary of chapter 8 of book ' Good to great'
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT