Question

In: Computer Science

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:

  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.

Solutions

Expert Solution

// Some topic to refer for setw http://www.cplusplus.com/reference/iomanip/setw/
// class in c++ https://www.geeksforgeeks.org/c-classes-and-objects/
// queue in c++ https://www.geeksforgeeks.org/queue-cpp-stl/
// Reading data from file http://www.cplusplus.com/reference/cstdio/freopen/
// Variable name are written in form such that you will understand what is going in example.
#include<bits/stdc++.h>
using namespace std;
class car
{
public:
int Car_number,Arrival_time,Car_wash_start_time,Departure_time,Wait_time,Total_time;   
};
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
fstream file;
ifstream myfile;
myfile.open("input-1.txt"); // https://www.geeksforgeeks.org/file-handling-c-classes/ read form here
// Arrival time of each car is in sorted order as mentioned in question
int t,cnt=0,i=0;
queue<int> q1;
while(myfile>>t) // Reading data from file till there is data in file..
{ q1.push(t); cout<<t<<" "; cnt++; } cout<<endl;
car a1[cnt];
int p=0,l=0,i1,Total_wait_time=0;
while(!q1.empty()) // Storing data in queue
{
t=q1.front();
p=max(p,t); if(p>537) break; // if(p>537) it means before closing time car can not be washed so we are breaking loop .
q1.pop();
a1[i].Car_number=i+1;
a1[i].Arrival_time=t; // Here in loop p is max( p,t) which means let arrival time of new car is 10 and we have take 15 minutes to process car which came before it so
// now this car will be processed after 15 minute and if arrival of new car is 20 and we have taken 10 minute to preproces previous car so we have time left but we
// can't do anything with it we have to wait till 20 . so p= max(p,t)
a1[i].Car_wash_start_time=p; p+=3;
a1[i].Departure_time=p; // Car is washed for 3 minute so car departure time is p+3;
a1[i].Wait_time=a1[i].Car_wash_start_time - a1[i].Arrival_time;
Total_wait_time+=a1[i].Wait_time;
a1[i].Total_time=a1[i].Wait_time+3; i++;
l++;
}
cout<<"Opening Time: 8:00 AM(0 minutes)"<<endl;
cout<<"Closing Time: 5:00 PM(540 minutes)"<<endl;
cout<<"Start of Simulation"<<endl;
cout<<"Car Number Arrival Time Car Wash Departue Wait Time Total"<<endl;
cout<<setw(34)<<"Start time"<<setw(9)<<"time"<<setw(21)<<"time"<<endl;
cout<<"-----------------------------------------------------------------------------"<<endl;
for(i1=0;i1<l;i1++)
{
cout<<setw(10)<<a1[i1].Car_number<<setw(12)<<a1[i1].Arrival_time<<setw(11)<<a1[i1].Car_wash_start_time<<setw(9)<<a1[i1].Departure_time<<setw(14)<<a1[i1].Wait_time<<setw(8)<<a1[i1].Total_time<<endl;
}
int Average_wait_time_in_min=0,Average_wait_time_in_sec=0;
int Total_car_wash_use_time=i*3;
if(i>0)
{
Average_wait_time_in_min=Total_wait_time/i; // To find minute part of average wait time we have multiplied total time*60 and divided it by i
Average_wait_time_in_sec=((Total_wait_time-(Average_wait_time_in_min*i))*60)/i;
}
if(!q1.empty())
{
   while(!q1.empty())
{ cout<<setw(10)<<i+1<<setw(12)<<q1.front()<<" Car arrived after Simulation time and was not served"<<endl; i++; q1.pop();}
}
int Percentage_of_time_car_was_in_use=(Total_car_wash_use_time*100)/540; // percenatage would be total time used *100 divide by total time we have
cout<<"End of Simulation"<<endl<<endl;
cout<<"Statistics:"<<endl;
cout<<setw(5)<<"Total wait time : "<<setw(20)<<Total_wait_time<<"minutes"<<endl;
cout<<setw(5)<<"Average wait time: "<<setw(20)<< Average_wait_time_in_min<<" minutes and "<<Average_wait_time_in_sec<<" seconds"<<endl;
cout<<setw(5)<<"Total car wash use time: "<<setw(14)<<Total_car_wash_use_time<<" minutes"<<endl;
cout<<setw(5)<<"Percentage of time car was in use:"<<setw(4)<<Percentage_of_time_car_was_in_use<<"%"<<endl;
  
   return 0;
}

First line of output is input that i have in my file .

In sample output total time is taken as 1 hour but in question we have total of 9 hours so percentage is calculated accordingly.

Total wait time is sum of wait time in each case.

Average wait time is = ( Total wait time )/ (Number of car washed ).

i hope it helps..

If you have any doubts please comment and please don't dislike.

PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME


Related Solutions

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: Each car takes 3 minutes from start of the car...
Note: This is a single file C++ project - No documentation is required on this assignment....
Note: This is a single file C++ project - No documentation is required on this assignment. Write a Fraction class whose objects will represent Fractions. Note: You should not simplify (reduce) fractions, you should not use "const," and all of your code should be in a single file. In this single file, the class declaration will come first, followed by the definitions of the class member functions, followed by the client program. You must provide the following member functions: A...
HW 20. Due November 1. In this assignment, we will see an example of an integral...
HW 20. Due November 1. In this assignment, we will see an example of an integral domain that has elements that can be factored as a product of irreducible elements, but that factorization is not unique. Let R denote the set of all complex numbers a + b √ 5i, where a, b ∈ Z. Let N be the norm on R defined by N(a + b √ 5i) = a 2 + 5b 2 . As before N(z1z2) =...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
This is for a lab report so a good explantion in that format would be great,...
This is for a lab report so a good explantion in that format would be great, thank you In class we learned that magnetic field lines form closed loops, and that magnetic monopoles (“charges”) did not actually exist in nature (or at least have yet to be found). Why then does this field l ook like that of a dipole with two magnetic charges? 3. Look up “Geomagnetic Reversal” and describe how we know this has happened on Earth in...
Individual Assignment #4: We have covered a great deal of ground and information between the last...
Individual Assignment #4: We have covered a great deal of ground and information between the last assignment and this assignment. I would like you to focus your time on two on the most forgotten areas of training and development. Those two areas include analysis and evaluation. 1. Define the term needs analysis and evaluation 2.Describe the components of a needs analysis 3.Explain how you would conduct a needs analysis at BP Amoco 4.Describe the levels of evaluation and which ones...
In C++ In this assignment, we will implement a square root approximater and then an nth...
In C++ In this assignment, we will implement a square root approximater and then an nth root approximater. Recall that the nth root of x is the number when raised to the power n gives x. We can use the concepts of binary search to approximate the square root of a number, and we can continue this logic to approximate the nth square root. We're going to use the concepts of binary search to try and approximate ending the square...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… For each new class entry that is taken, you will write out the information to a file. The file can be any .txt file name of your choosing. The file should be appended to each...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… Convert all of the function’s parameters from pass by value to pass by reference. Accumulate totals for each of the class rooms that we are using for this program. When the program ends (user choice...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college...
C++ For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… Convert all of the function’s parameters from pass by value to pass by reference. Accumulate totals for each of the class rooms that we are using for this program. When the program ends (user choice...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT