Tuesday, December 14, 2010

FCFS

#include
#include
#include

class process
{
float burst_time,wait_time;
class process *next,*ptr;
int max;
public:
void create();
void fcfs();
}
*front=NULL,*rear=NULL;

void process::create()
{
cout<<"ENTER THE MAXIMUM NUMBER OF PROCESSES THAT CAN BE IN THE QUEUE ==> ";
cin>>max;
class process *new_process;
for(int i=1;i<=max;i++) { new_process=new process; cout<<"ENTER THE BURST TIME OF THE PROCESS "< ";
cin>>new_process->burst_time;
if(front==NULL)
{
front=new_process;
ptr=front;
}
else
rear->next=new_process;
rear=new_process;
}
}

void process::fcfs()
{
float avg_waiting_time,total_waiting_time;
cout<<"PROCESS\tBURST TIME"<next;
}
ptr=front;
ptr->wait_time=0;
total_waiting_time=0;
for(i=2;i<=max;i++) { total_waiting_time=total_waiting_time+(ptr->burst_time);
ptr=ptr->next;
ptr->wait_time=total_waiting_time;
}
ptr=front;
total_waiting_time=0;
for(i=1;inext;
total_waiting_time=total_waiting_time+(ptr->wait_time);
}
avg_waiting_time=total_waiting_time/max;
cout<<"AVERAGE WAITING TIME IS ==> "< }

void main()
{
process p;
p.create();
p.fcfs();
}



No comments:

Post a Comment