FCFS scheduling program in C++

Hello frnds, FCFS is a CPU scheduling  algorithm for OS which stands for First Come Fist Serve
Following program is illustrated the FCFS algorithm:-

#include
#include
#define max 20

struct FCFS
{
char proName;
int burstTime;
};

int main()
{
clrscr();
FCFS data[max];
int i,j,n,temp,wTime[max],taTime[max];
float s=0.0,avgTAT=0.0;

//Input data//
//---------------------------------------------------------------------//
cout<<"\nEnter no. of jobs:";
cin>>n;

cout<<"\nEnter name of job:";
for(i=1;i<=n;i++)
{
cin>>data[i].proName;
}

cout<<"\nEnter burst time of each job:";
for(i=1;i<=n;i++)
{
cin>>data[i].burstTime;
}
//------------------------------------------------------------------------//
 

//Evaluating waiting time and turn around time
wTime[1]=0;
for(i=1;i<=n;i++)
{
wTime[i]=s;
s=s+data[i].burstTime;
taTime[i]=s;
}



//Displaying Name, waiting time and turn around time of each process

cout<<"\nJob\tWT\tTAT\n";
for(i=1;i<=n;i++)
{
cout<}

s=0;



//For the calculation of average waiting and turn around time

for(i=1;i<=n;i++)
{
s=s+wTime[i];
avgTAT=avgTAT+taTime[i];
}

avgTAT=avgTAT/n;
s=s/n;
//--------------------------------------------------------------------------------


cout<<"\nAverage waiting time is "<cout<<"\nAverage turn around time is "<getch();
return 0;
}

Comments

  1. #include
    #include
    #include
    void main()
    {
    int at[5],st[5],tt=0,wt=0,tr=0;
    char name[5];
    float res,tres;
    clrscr();
    cout<<"\n\tName \tAT \tST \tWT \tTAT \tRR";
    for(int i=0;i<5;i++)
    {
    cout<<"\n\t";
    cin>>name[i];
    cout<<"\t";
    cin>>at[i];
    cout<<"\t";
    cin>>st[i];
    wt = tr - at[i];
    cout<<"\t\t"<<wt;
    tt = wt + st[i];
    cout<<"\t"<<tt;
    tr+=st[i];
    res=(float)tt/st[i];
    tres+=(float)res;
    cout<<"\t"<<res;
    }
    cout<<"\nAverage response ratio is: "<<tres/5;
    getch();
    }

    ReplyDelete

Post a Comment