//First Come First Serve (FCFS) scheduling algorithm implementation using C++
#include"iostream.h"
#include"conio.h"
int total,i,n;
float avg;
class fcfs
{
int bt[12],wt[12];
char p[12][6];
public:
fcfs()
{
wt[0]=0;
total=0;
avg=0;
}
void input(int n);
void apply();
void display();
};
void fcfs::input(int n)
{
for(i=0;i<n;i++)
{
cout<<"Enter process "<<i+1<<" name :";
cin>>p[i];
cout<<"Enter process time :";
cin>>bt[i];
}
}
void fcfs:: apply()
{
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
total=total+wt[i];
}
avg=(float)total/n;
}
void fcfs::display()
{
cout<<"P_name P_time W_time
";
for(i=0;i<n;i++)
cout<<p[i]<<" "<<bt[i]<<" "<<wt[i]<<"
";
}
void main()
{
fcfs fcfs;
clrscr();
cout<<"Enter no. of processes :";
cin>>n;
fcfs.input(n);
fcfs.apply();
fcfs.display();
cout<<"total waiting time :"<<total<<"
";
cout<<"Average waiting Time :"<<avg;
getch();
}
//program written by Mars. 06/09/2011. OS lab.