QUESTION DESCRIPTION
Semester break has started and Bogar is going home from College (Tamil Siddha). He is taking flight from Chennai to Delhi. After entering the Airport, he was asked to get into queue of the Boarding Pass. The Airline staff follows the FCFS algorithm and first process the request of the person who came first that is who is at first position in the queue.
Bogar is a programmer and wanted to gift a program to the airline which shows the service time (time at which that person will reach the counter), waiting time (service time -arrival time) for each person in the queue and turnaround time (total time from arrival till person gets boarding pass). Also, Calculate average waiting and average turnaround time.
Input: The first line contains the Number of Passengers n. The next n line contains the Burst time and Arrival time.
Output: - The first n lines should print input values, service time (time at which that person will reach the counter), waiting time (service time -arrival time) for each person in the queue and turnaround time (total time from arrival till person gets boarding pass).
In next two lines Print average waiting and average turnaround time in next two lines respectively.
Semester break has started and Bogar is going home from College (Tamil Siddha). He is taking flight from Chennai to Delhi. After entering the Airport, he was asked to get into queue of the Boarding Pass. The Airline staff follows the FCFS algorithm and first process the request of the person who came first that is who is at first position in the queue.
Bogar is a programmer and wanted to gift a program to the airline which shows the service time (time at which that person will reach the counter), waiting time (service time -arrival time) for each person in the queue and turnaround time (total time from arrival till person gets boarding pass). Also, Calculate average waiting and average turnaround time.
Input: The first line contains the Number of Passengers n. The next n line contains the Burst time and Arrival time.
Output: - The first n lines should print input values, service time (time at which that person will reach the counter), waiting time (service time -arrival time) for each person in the queue and turnaround time (total time from arrival till person gets boarding pass).
In next two lines Print average waiting and average turnaround time in next two lines respectively.
TEST CASE 1
INPUT
INPUT
4
4 9 8 3
0 2 4 3
OUTPUTPassenger0 0 4
Passenger1 2 11
Passenger2 9 17
Passenger3 18 21
Average waiting time=7.250000
Average turn around time=13.250000
TEST CASE 2
INPUT
INPUT
5
4 9 8 3 4
0 2 4 3 2
OUTPUTPassenger0 0 4
Passenger1 2 11
Passenger2 9 17
Passenger3 18 21
Passenger4 22 26
Average waiting time=10.200000
Average turn around time=15.800000
Code :
#include<iostream>
#include<iomanip>
using namespace std;
void findWaitingTime(int processes[], int n, int bt[],int wt[], int at[])
{
int service_time[n];
service_time[0] = 0;
wt[0] = 0;
for (int i = 1; i < n ; i++)
{
service_time[i] = service_time[i-1] + bt[i-1];
wt[i] = service_time[i] - at[i];
if (wt[i] < 0)
wt[i] = 0;
}
}
void findTurnAroundTime(int processes[], int n, int bt[],int wt[], int tat[])
{ for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
void findavgTime(int processes[], int n, int bt[], int at[])
{
int wt[n], tat[n];
findWaitingTime(processes, n, bt, wt, at);
findTurnAroundTime(processes, n, bt, wt, tat);
int total_wt = 0, total_tat = 0;
for (int i = 0 ; i < n ; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
int compl_time = tat[i] + at[i];
cout << "Passenger" << i << " " << wt[i] << " "<< tat[i] <<endl ;
}
cout<<fixed;
cout << "Average waiting time="<< (float)total_wt / (float)n;
cout << "\nAverage turn around time="<< (float)total_tat / (float)n;
}
int main()
{
int n ;
cin>>n;
int processes[n];
char ch='A';
int burst_time[n];
int arrival_time[n];
for(int i=0;i<n;i++)
{
cin>>burst_time[i];
processes[i]=ch;
ch++;
}
for(int i=0;i<n;i++)
{
cin>>arrival_time[i];
}
findavgTime(processes, n, burst_time, arrival_time);
return 0;
}