<<" "; } //Priority Algorithm void cpuschedule::Priority() { int i,B[10],P[10],j; w=0.0; int max; Twt=0.0; max=1; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process p"<<<"= "; cout<<<"Enter the priority for process P"<<<"= "; cin>>P[i];
if(max <=max) { i=1; while(i<=n) { if(P[i]==j) { Wt[i]=w; w=w+B[i]; } i++; } j++; } //calculating average weighting Time for(i=1;i<=n;i++) Twt=Twt+Wt[i]; Awt=Twt/n; cout<<"Total Weighting Time="<<<" "; cout<<"Average Weighting Time="<<<" "; } //Shortest job First Algorithm with Preemption void cpuschedule::SjfP() { int i,j,m,Wt[10],k,B[10],A[10],Tt=0,Wtm[10],temp; char S[20],start[20]; int max=0,Time=0,min; float Twt=0.0,Awt; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process P"<<<"= "<max)
max=B[i];
Wt[i]=0;
S[i]='T';
start[i]='F';
Tt=Tt+B[i];
cout<<"Enter the Arrival Time for"<<<"th process= "; cin>>A[i];
if(A[i]>Time)
Time=A[i];
}
//cout<<"Max="<<=t && B[i]!=0) { if(flag==0) { Wt[i]=Wt[i]+w; cout<<"Wt["<<<"]="<<=n && flag!=0) { if(S[j]!='F' && B[i]>B[j] && A[j]<=t && i!=j ) { flag=0; Wt[i]=Wt[i]-w; i=j; } else { flag=1; } j++; } } else { i++; j=1; while(A[j]<=t &&j<=n) { if(B[i]>B[j] && S[j]!='F')
{
flag=0;
i=j;
}
j++;
}
}
}
else
if(flag==0)
i++;
}
cout<<"Printing remaining burst time"; for(i=1;i<=n;i++) cout<<"B["<<<"]="<<<" "; while(w<=n) { if(min>B[i] && S[i]=='T')
{
min=B[i];
j=i;
}
i++;
}
i=j;
if(w==Time && start[i]=='T')
{
w=w+B[i];
S[i]='F';
}
else
{
Wt[i]=Wt[i]+w;
w=w+B[i];
S[i]='F';
}
}
cout<<"Weight info"; for(i=1;i<=n;i++) cout<<"WT["<<<"]="<<<"after subtracting arrival time"; for(i=1;i<=n;i++) { Wt[i]=Wt[i]-A[i]; cout<<"WT["<<<"]="<<<"Average Weighting Time="<<<"Burst time for process p"<<<"= "; cout<<<"Enter the Time Quantum="; cin>>tq;
//TO find the dimension of the Rrobin array
m=max/tq+1;
//initializing Rrobin array
for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { Rrobin[i][j]=0; } } //placing value in the Rrobin array i=1; while(i<=n) { j=1; while(B[i]>0)
{
if(B[i]>=tq)
{
B[i]=B[i]-tq;
Rrobin[i][j]=tq;
j++;
}
else
{
Rrobin[i][j]=B[i];
B[i]=0;
j++;
}
}
count[i]=j-1;
i++;
}
cout<<"Display"; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cout<<"Rr["<<<","<<<"]="<<<" "; } cout<<" "; } //calculating weighting time int x=1; i=1; while(x<=n) { for(int a=1;a<=j-1) { if(i==n+1) { i=1; k++; } else { if(i!=z) { Wt[z]=Wt[z]+Rrobin[i][k]; } i++; } } x++; } for(i=1;i<=n;i++) cout<<"Weighting Time for process P"<<<"="<<<"Total Weighting Time="<<<"Average Weighting Time="<<<" "; } //Application file for cpu Scheduling #include "cpuh.h" void main() { int ch,cho; cpuschedule c; do { cout<<" MENU"; cout<<"1.Getting BurstTime"; cout<<"2.FirstComeFirstServed"; cout<<"3.ShortestJobFirst"; cout<<"4.RoundRobin"; cout<<"5.Priority"; cout<<"6.EXIT"; cout<<"Enter your choice"; cin>>ch;
switch(ch)
{
case 1:
c.Getdata();
break;
case 2:
cout<<"FIRST COME FIRST SERVED SCHEDULING"; c.Fcfs(); break; case 3: cout<<"SHORTEST JOB FIRST SCHEDULING"; do { cout<<"1.SJF-Normel"; cout<<"2.SJF-Preemptive"; cout<<"3.SJF-NonPreemptive"; cout<<"Enter your choice"; cin>>cho;
switch(cho)
{
case 1:
c.Sjf();
break;
case 2:
c.SjfP();
break;
case 3:
c.SjfNp();
break;
}
}while(cho<=3); break; case 4: cout<<"ROUND ROBIN SCHEDULING"; c.RoundRobin(); break; case 5: cout<<"PRIORITY SCHEDULING"; c.Priority(); break; case 6: break; } }while(ch<=5); }
No comments:
Post a Comment