Saturday, April 5, 2014

FCFS CPU Scheduling : C++

#include "stdafx.h"
#include <iostream>

using namespace std;

void main()
{
cout<<"Enter the number of processess: ";
int nProc=0;
cin>>nProc;

cout<<"Enter the burst times of processess: ";
int data[10][3];

for(int i =0;i<nProc;++i)
{
cin>>data[i][0];
data[i][1]=0;
data[i][2]=0;
}

//Calculation of waiting times
for(int i =1;i<nProc;++i)
{
data[i][1]=data[i-1][1]+data[i-1][0];
}

//calculation of TAT (Turn around time)
for(int i=0;i<nProc;++i)
{
data[i][2] = data[i][0]+data[i][1];
}

//show results
for(int i = 0;i<nProc;++i)
{
cout<<"\nProcess ID "<<i<<endl;
cout<<"Burst time : "<<data[i][0]<<endl;
cout<<"Waiting time: "<<data[i][1]<<endl;
cout<<"TAT: "<<data[i][2]<<endl;
cout<<endl;
}
}

No comments:

Post a Comment