Gantt Chart(CPU Scheduling)

#include <iostream>
#include<bits/stdc++.h> 
using namespace std;
int main() {
	int n;
  cin>>n;
  int arrn[n];
  int arrb[n];
  int arra[n];
  int temp=0;
  int temp1=0;
  for(int i=0;i<n;i++)
  {
    cin>>arrn[i];
    
  }
  for(int i=0;i<n;i++)
  {
    cin>>arrb[i];
    
  }
  for(int i=0;i<n;i++)
  {
    cin>>arra[i];
    
  }
 for(int i=0;i<n;i++)
  {
    for(int j=1;j<n;j++)
    {
      if(arra[j-1]>arra[j])
      {
        temp=arrb[j];
        temp1=arrn[j-1];
        arrb[j]=arrb[j-1];
        arrb[j-1]=temp;
        arrn[j-1]=arrn[j];
        arrn[j]=temp1;
        temp1=0;
        temp1=arra[j-1];
        arra[j-1]=arra[j];
        arra[j]=temp1;
        temp1=0;
      }
    }
 }
  float wait[n+1];
  wait[0]=0;
  for(int i=1;i<=n+1;i++)
  {
       wait[i]=wait[i-1]+arrb[i-1];
  }
   float awt=0;
  for(int i=0;i<n+1;i++)
  {
    awt=awt+wait[i];
  }
  cout<<"GANTT CHART"<<endl;
  for(int i=0;i<n;i++)
  {
  	cout<<"P"<<arrn[i]<<" ";
 
  }
  cout<<endl;
 for(int i=0;i<n+1;i++)
  {
  	cout<<wait[i];
   if(i==n)
   {
     break;
   }
   cout<<" ";
 
 }
  
  
  
}
//code by lakshay singhwal

Leave a comment

Design a site like this with WordPress.com
Get started