plz do not copy from chegg #include 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 ; 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; } } // Find turn around time void TurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) { for (int i = 0; i < n ; i++) 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 Time\n"; int total_wt = 0, total_tat = 0; for (int i = 0 ; i < n ; i++) { cout << " p" << i+1 << "\t\t" << bt[i] << "\t\t" << at[i] << "\t\t" << tat[i] << "\t\t "<< endl; } cout<<"\n\n Waiting Time and Completion Time for Each Process-->\n\n"; cout << "Processes "<< "Waiting Time" << " Completion Time \n"; 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 << " p" << i+1 << "\t\t" << wt[i] << "\t\t " << compl_time << endl; } cout << "Average waiting time = " << (float)total_wt / (float)n; cout << "\nAverage turn around time = " << (float)total_tat / (float)n<<"\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;
plz do not copy from chegg
#include<iostream>
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 ; 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;
}
}
// Find turn around time
void TurnAroundTime(int processes[], int n, int bt[],
int wt[], int tat[])
{
for (int i = 0; i < n ; i++)
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 Time\n";
int total_wt = 0, total_tat = 0;
for (int i = 0 ; i < n ; i++)
{
cout << " p" << i+1 << "\t\t" << bt[i] << "\t\t"
<< at[i] << "\t\t" << tat[i] << "\t\t "<< endl;
}
cout<<"\n\n Waiting Time and Completion Time for Each Process-->\n\n";
cout << "Processes "<< "Waiting Time"
<< " Completion Time \n";
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 << " p" << i+1 << "\t\t" << wt[i] << "\t\t " << compl_time << endl;
}
cout << "Average waiting time = "
<< (float)total_wt / (float)n;
cout << "\nAverage turn around time = "
<< (float)total_tat / (float)n<<"\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;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images