Posts

Search

Gantt Chart

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).He is asked to submit a chart presentation for the above project. Help him to draw the chart alone.
INPUT:
1st line : number of process
2nd line : Process ID of each process
3rd line : Burst time of each process
4th line : arrival time of each process

TEST CASE 1

INPUT

5
1 2 3 4 5
3 2 8 4 5
2 4 5 7 1
OUTPUT
GANTT CHART
P5 P1 P2 P3 P4 
0 5 8 10 18 22

TEST CASE 2

INPUT

4
11 22 33 44
7 3 6 2
4 3 2 1
OUTPUT
GANTT CHART
P44 P33 P22 P11 
0 2 8 11 18

Code :

#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<<" ";
 
 }
  
  
  
}