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.
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int input_len , *pri , *bt , temp_wt=0 , temp_tr=0 , sum_wt = 0 , sum_tr = 0;
cin>>input_len;
pri = new int[input_len];
bt = new int[input_len];
for(int i =0 ;i<input_len;i++){
cin>>bt[i];
}
for(int i =0 ;i<input_len;i++){
cin>>pri[i];
}
for(int i =0 ;i<input_len;i++){
temp_wt =0;
for (int j =0; j < i ;j++){
temp_wt+=bt[j];
}
temp_wt-=pri[i];
temp_tr = temp_wt+bt[i];
sum_wt+=temp_wt;
sum_tr += temp_tr;
cout<<"Passenger"<<i<<' '<<temp_wt<<' '<<temp_tr<<endl;
}
float val = (float)sum_wt/(float)input_len;
printf("Average waiting time=%.6f\n",val);
val = (float)sum_tr / (float)input_len;
printf("Average turn around time=%.6f",val);
return 0;
}
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.
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int input_len , *pri , *bt , temp_wt=0 , temp_tr=0 , sum_wt = 0 , sum_tr = 0;
cin>>input_len;
pri = new int[input_len];
bt = new int[input_len];
for(int i =0 ;i<input_len;i++){
cin>>bt[i];
}
for(int i =0 ;i<input_len;i++){
cin>>pri[i];
}
for(int i =0 ;i<input_len;i++){
temp_wt =0;
for (int j =0; j < i ;j++){
temp_wt+=bt[j];
}
temp_wt-=pri[i];
temp_tr = temp_wt+bt[i];
sum_wt+=temp_wt;
sum_tr += temp_tr;
cout<<"Passenger"<<i<<' '<<temp_wt<<' '<<temp_tr<<endl;
}
float val = (float)sum_wt/(float)input_len;
printf("Average waiting time=%.6f\n",val);
val = (float)sum_tr / (float)input_len;
printf("Average turn around time=%.6f",val);
return 0;
}
Comments
Post a Comment