//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\tP_time\tW_time\n";
for(i=0;i<n;i++)
cout<<p[i]<<"\t"<<bt[i]<<"\t"<<wt[i]<<"\n";
}
void main()
{
fcfs fcfs;
clrscr();
cout<<"Enter no. of processes :";
cin>>n;
fcfs.input(n);
fcfs.apply();
fcfs.display();
cout<<"total waiting time :"<<total<<"\n";
cout<<"Average waiting Time :"<<avg;
getch();
}
//program written by Mars. 06/09/2011. OS lab.
wah
ReplyDeleteThanks for nice post.C programming details here
ReplyDeletepls upload the output
ReplyDelete