#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int wt=0;
float twt=0;
struct node
{
char name;
int bt;
int p;
}n[4];
for(int i=0;i<4;i++)
{
cout<<"enter the name birst time and priority of process="<<i+1<<endl;
cin>>n[i].name>>n[i].bt>>n[i].p;
}
cout<<"pname"<<" "<<"btime"<<" "<<"priority"<<endl;
for(i=0;i<4;i++)
{
cout<<n[i].name<<" "<<n[i].bt<<" "<<n[i].p<<endl;
}
for(i=0;i<3;i++)
{
if(n[i].p>n[i+1].p)
{
node temp;
temp=n[i+1];
n[i+1]=n[i];
n[i]=temp;
}
}
cout<<"waiting time for process having pririty="<<1<<" "<<wt<<endl;
for(i=1;i<4;i++)
{
wt=wt+n[i-1].bt;
twt=twt+wt;
cout<<"waiting time for process having pririty="<<i+1<<" "<<wt<<endl;
}
cout<<"total waiting time="<<twt<<endl;
float avgwt=0;
avgwt=twt/4;
cout<<"average waiting time="<<avgwt<<endl;
getch();
}
No comments:
Post a Comment