using namespace std;
void WaitingTime(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="" ;="">
{
service_time[i] = service_time[i-1] + bt[i-1];
wt[i] = service_time[i] - at[i];
if (wt[i] <>
wt[i] = 0;
}
}
// Find turn around time
void TurnAroundTime(int processes[], int n, int bt[],
int wt[], int tat[])
{
for (int i = 0; i < n="" ;="">
tat[i] = bt[i] + wt[i];
}
// FInd average waiting and turn-around
// times.
void AvgTime(int processes[], int n, int bt[], int at[])
{
int wt[n], tat[n];
WaitingTime(processes, n, bt, wt, at);
TurnAroundTime(processes, n, bt, wt, tat);
cout<"\n\n----------------------output---------------------------------->\n\n";
cout < "processes="" "="">< "="" burst="" time="" "="">< "="" arrival="" time="">
< "="" turn-around="">
int total_wt = 0, total_tat = 0;
for (int i = 0 ; i < n="" ;="">
{
cout < "="" p"="">< i+1="">< "\t\t"="">< bt[i]=""><>
< at[i]="">< "\t\t"="">< tat[i]="">< "\t\t=""><>
}
cout<"\n\n waiting="" time="" and="" completion="" time="" for="" each="" process--="">\n\n";
cout < "processes="">< "waiting="">
< "="" completion="" time="">
for (int i = 0 ; i < n="" ;="">
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
int compl_time = tat[i] + at[i];
cout < "="" p"="">< i+1="">< "\t\t"="">< wt[i]="">< "\t\t="" "="">< compl_time=""><>
}
cout < "average="" waiting="" time="
<< (float)total_wt / (float)n;
cout << " \naverage="" turn="" around="" time="
<< (float)total_tat / (float)n<<">
}
int main()
{
int processes[] = {0,1, 2, 3};
int n = sizeof processes / sizeof processes[0];
int burst_time[] = {5, 3,8, 6};
int arrival_time[] = {0, 1, 2,3};
AvgTime(processes, n, burst_time, arrival_time);
return 0;
}
"\n\n>"\n\n----------------------output---------------------------------->