Semester Break(CPU Scheduling)

#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; 
} 
//code by lakshay singhwal

Leave a comment

Design a site like this with WordPress.com
Get started