السلام عليكم ورحمة الله وبركاته
هذا عبارة عن كود لعمليات الجدولة في المعالج
والمطلوب أن أعمل
FCFS
و
RR
توجد مشكلة في هذا الكود تمنع من تنفيذه لكن إلى الآن لم أعرفها
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class cpuschedule
{
int n,Bu[20];
float Twt,Awt,A[10],Wt[10],w;
public:
//Getting the No of processes & burst time
void Getdata();
//First come First served Algorithm
void Fcfs();
//Shortest job First Algorithm
void Sjf();
//Shortest job First Algorithm with Preemption
void SjfP();
//Shortest job First Algorithm with NonPreemption
void SjfNp();
//Round Robin Algorithm
void RoundRobin();
//Priority Algorithm
void Priority();
};
// Implementation file for Cpu scheduling
#include "cpuh.h"
//Getting no of processes and Burst time
void cpuschedule::Getdata()
{
int i;
cout<<"Enter the no of processes:";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"Enter The BurstTime for Process p"<<i<<"= ";
cin>>Bu;
}
}
//First come First served Algorithm
void cpuschedule::Fcfs()
{
int i,B[10];
Twt=0.0;
for(i=1;i<=n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"=";
cout<<B;
}
Wt[1]=0;
for(i=2;i<=n;i++)
{
Wt=B[i-1]+Wt[i-1];
}
//Calculating Average Weighting Time
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<"";
}
//Round Robin Algorithm
void cpuschedule::RoundRobin()
{
int i,j,tq,k,B[10],Rrobin[10][10],count[10];
int max=0;
int m;
Twt=0.0;
for(i=1;i<=n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
if(max<B)
max=B;
Wt=0;
}
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[j]=0;
}
}
//placing value in the Rrobin array
i=1;
while(i<=n)
{
j=1;
while(B>0)
{
if(B>=tq)
{
B=B-tq;
Rrobin[j]=tq;
j++;
}
else
{
Rrobin[j]=B;
B=0;
j++;
}
}
count=j-1;
i++;
}
cout<<"Display ";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"Rr["<<i<<","<<j<<"]="<<Rrobin[j];
cout<<" ";
}
cout<<"";
}
//calculating weighting time
int x=1;
i=1;
while(x<=n)
{
for(int a=1;a<x;a++)
{
Wt[x]=Wt[x]+Rrobin[a];
}
i=1;
int z=x;
j=count[z];
k=1;
while(k<=j-1)
{
if(i==n+1)
{
i=1;
k++;
}
else
{
if(i!=z)
{
Wt[z]=Wt[z]+Rrobin[k];
}
i++;
}
}
x++;
}
for(i=1;i<=n;i++)
cout<<"Weighting Time for process P"<<i<<"="<<Wt;
//calculating Average Weighting Time
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<" ";
}
//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);
}أنتظر منكم المساعدة
