Program Os
Program Os
Code :
#include<iostream>
int main()
{ int n,bt[20],wt[20],tat[20],avg_wt=0,avg_tat=0,i,j;
cin>>n;
for(i=0;i<n;i++)
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurn
around Time";
for(i=0;i<n;i++)
tat[i]=bt[i]+wt[i];
avg_wt+=wt[i];
avg_tat+=tat[i];
cout<<"\nP["<<i+1<<"]"<<"\t\t\t"<<bt[i]<<"\t\t\t\t"<<wt[i
]<<"\t\t\t\t"<<tat[i];
avg_wt/=i;
avg_tat/=i;
return 0;
}
Program:2
AIM : Write a program to implement Shortest Job First scheduling(SJF).
Code:
#include <iostream>
int main()
int A[100][4];
cin >> n;
A[i][0] = i + 1;
index = i;
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
A[0][2] = 0;
A[i][2] = 0;
A[i][2] += A[j][1];
total += A[i][2];
avg_wt = (float)total / n;
total = 0;
cout << "P BT WT TAT" << endl;
// data.
total += A[i][3];
cout << "P" << A[i][0] << " " << A[i][1] << "
" << A[i][2] << " " << A[i][3] << endl;
avg_tat = (float)total / n;
cout << "Average Waiting Time= " << avg_wt << endl;
}
Program:3
AIM : Write a program to implement priority based scheduling.
Code :
#include<iostream>
int main()
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,
temp,avg_wt,avg_tat;
cin>>n;
for(i=0;i<n;i++)
cout<<"\nP["<<i+1<<"]\n";
cout<<"Burst Time:";
cin>>bt[i];
cout<<"Priority:";
cin>>pr[i];
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
if(pr[j]<pr[pos])
pos=j;
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
total=0;
for(i=0;i<n;i++)
total+=tat[i];
cout<<"\nP["<<i+1<<"]"<<"\t\t\t"<<bt[i]<<"\t\t\t\t"<<wt[i
]<<"\t\t\t\t"<<tat[i];
return 0;