/*------------------------------------*/
#include
#include
void main()
{
clrscr();
int n,burst[50],arr[50],wait[50],tat[50],pid[50],i;
cout<<"Enter no of process"<
cin>>n;
cout<<"enter process_id"<
for(i=0;i
{
cin>>pid[i];
}
cout<<"enter burst time"<
for(i=0;i
{
cin>>burst[i];
}
cout<<"enter the Arrival"<
for(i=0;i
{
cin>>arr[i];
}
cout<
int flag=0;
for(int j=0;j<=n-1;j++)
{
for(i=0;i<=n-j;i++)
{
if(burst[j]==burst[i])
{
flag=1;
}
}
}
for(j=0;j<=n-1;j++)
{
for(i=0;i<=n-j;i++)
{
if(flag!=1)
{
if(burst[j]>burst[i])
{
int temp1=burst[j];
burst[j]=burst[i];
burst[i]=temp1;
int temp2=pid[j];
pid[j]=pid[i];
pid[i]=temp2;
int temp3=arr[j];
arr[j]=arr[i];
arr[i]=temp3;
}
}
else
{
if(arr[j]>arr[i])
{
int temp1=burst[j];
burst[j]=burst[i];
burst[i]=temp1;
int temp2=pid[j];
pid[j]=pid[i];
pid[i]=temp2;
int temp3=arr[j];
arr[j]=arr[i];
arr[i]=temp3;
}
}
} }
wait[0]=0;
for(i=0;i
{
wait[i+1]=burst[i]+wait[i];
}
//int tat[50];
for(i=0;i<=n;i++)
{
tat[i]=burst[i]+wait[i];
}
float avg_wt=0;
for(i=0;i
{
avg_wt=wait[i]+avg_wt;
}
cout<<"\tProcess id\tburst\tArrival\twait\tTurnaround"<
for(i=0;i
{
cout<<"\t"<
cout<
}
cout<
cout<<"[1]Gantt Chart:-"<
for(i=0;i
{
cout<<"----";
}
cout<
cout<<"|";
for(i=0;i
{
cout<<" "<
//cout<
}
cout<
for(i=0;i
{
cout<<"----";
}
cout<
for(i=0;i
{
cout<
}
cout<
cout<<"[2]Avg.wait time="<
float avg_tt=0;
for(i=0;i
{
avg_tt=tat[i]+avg_tt;
}
cout<
cout<<"[3]Avg.turnarround time="<
getch();
}
/*
Enter no of process
4
enter process_id
1 2 3 4
enter burst time
2 4 3 6
enter the Priority
2 1 4 3
Process id burst Priority wait Turnaround
2 4 1 0 4
1 2 2 4 6
4 6 3 6 12
3 3 4 12 15
[1]Gantt Chart:-
------------------------
| 2 | 1 | 4 | 3 |
------------------------
0 4 6 12 15
[2]Avg.wait time=5.5
[3]Avg.turnarround time=9.25 */
0 comments:
Post a Comment