QUESTION DESCRIPTION
Software Engineer Saran is assigned with several projects from various companies by his Team lead.
He is also insisted to complete the projects based on their ordering sequence (ie., first come basis).
Project order date and their duration is specified.
Your are asked to calculate the individual and the average waiting time of the project.
Also find their individual and the average turnaround time of each project.
INPUT :
Line 1 : No of Process
Line 2 : Burst time of each process
Software Engineer Saran is assigned with several projects from various companies by his Team lead.
He is also insisted to complete the projects based on their ordering sequence (ie., first come basis).
Project order date and their duration is specified.
Your are asked to calculate the individual and the average waiting time of the project.
Also find their individual and the average turnaround time of each project.
INPUT :
Line 1 : No of Process
Line 2 : Burst time of each process
TEST CASE 1
INPUT
INPUT
3
24
3
3
OUTPUTPid BT WT TAT
P[1] 24 0 24
P[2] 3 24 27
P[3] 3 27 30
Average Waiting Time:17
Average Turnaround Time:27
TEST CASE 2
INPUT
INPUT
4
5
4
6
8
OUTPUTPid BT WT TAT
P[1] 5 0 5
P[2] 4 5 9
P[3] 6 9 15
P[4] 8 15 23
Average Waiting Time:7
Average Turnaround Time:13
Code :
#include <iostream>
using namespace std;
int main()
{
int size;
cin>>size;
int burst[size],wait[size],turna[size],ta=0,avg=0,ini=0;
turna[0]=0;
cout<<"Pid BT WT TAT\n";
for(int i=0;i<size;i++)
{
cin>>burst[i];
}
for(int i=0;i<size;i++)
{
cout<<"P["<<i+1<<"] "<<burst[i]<<" "<<ini<<" "<<burst[i]+ini<<"\n";
ini=burst[i]+ini;
}
for(int i=1;i<=size;i++)
{
turna[i]=turna[i-1]+burst[i-1];
ta+=turna[i];
}
wait[0]=0;
for(int i=1;i<size;i++)
{
wait[i]=wait[i-1]+burst[i-1];
avg+=wait[i];
}
cout<<"Average Waiting Time:"<<avg/size;
cout<<"\nAverage Turnaround Time:"<<ta/size;
return 0;
}