السلام عليكم ورحمة الله وبركاته
عندي هذا الكود لعمل جدولة العمليات
لكن يحتوي على مشاكل
للذي عنده الخبرة ليحل هذه المشاكل مع ذكر سبب المشكلة
السلام عليكم ورحمة الله وبركاته
عندي هذا الكود لعمل جدولة العمليات
لكن يحتوي على مشاكل
للذي عنده الخبرة ليحل هذه المشاكل مع ذكر سبب المشكلة
تم تعديل هذه المشاركة بواسطة designerh في 5 يونيو 2008 في 03:02
designerh كتب:السلام عليكم ورحمة الله وبركاتهعندي هذا الكود لعمل جدولة العمليات
؟؟؟؟؟؟؟
لكن يحتوي على مشاكل
للذي عنده الخبرة ليحل هذه المشاكل مع ذكر سبب المشكلة
عليكم السلام ورحمة الله وبركاته
fill in the blank :rolleyes: ....
وين الشيفرة اخي الكريم؟
:happy:
[وسط]
♥ Countess ♥

♥
[/وسط]
أريد تعديل الكود على الشكل التالي
حيث
Turnarround time = total Burst time + total witing time / number of processor
وقانون
CPU utilization = (total Bust time / total time)*100
وقانون
Throuput =number of processor/total time
حاولت أن أعمل عداد للبرست تايم لكن ما ضبطت معي وهذا هو الكود
وأريد عمل تعديل آخر لكن خلينا في هذه المشكلة بالأول
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class cpuschedule
{
int n,Bu[20];
float Twt,Awt,A[10],Wt[10],w;
public:
void Getdata();
void Fcfs();
void Sjf();
void SjfP();
void SjfNp();
void RoundRobin();
void Priority();
};
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;
}
}
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];
}
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<" ";
}
void cpuschedule::Sjf()
{
int i,j,temp,B[10];
Twt=0.0;
for(i=1;i<=n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
}
for(i=n;i>=1;i--)
{
for(j=1;j<=n;j++)
{
if(B[j-1]>B[j])
{
temp=B[j-1];
B[j-1]=B[j];
B[j]=temp;
}
}
}
Wt[1]=0;
for(i=2;i<=n;i++)
{
Wt=B[i-1]+Wt[i-1];
}
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<" ";
}
void cpuschedule::SjfNp()
{
int i,B[10],Tt=0,temp,j;
char S[10];
float A[10],temp1,t;
Twt=0.0;
w=0.0;
for(i=1;i<=n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
S='T';
Tt=Tt+B;
cout<<"=Enter the Arrival Time for"<<i<<"th process= ";
cin>>A;
}
for(i=n;i>=1;i--)
{
for(j=3;j<=n;j++)
{
if(B[j-1]>B[j])
{
temp=B[j-1];
temp1=A[j-1];
B[j-1]=B[j];
A[j-1]=A[j];
B[j]=temp;
A[j]=temp1;
}
}
}
for(i=1;i<=n;i++)
{
cout<<"p"<<i<<" "<<B<<" "<<A;
}
Wt[1]=0;
w=w+B[1];
t=w;
S[1]='F';
while(w<Tt)
{
i=2;
while(i<=n)
{
if(S=='T'&&A<=t)
{
Wt=w;
cout<<"WT"<<i<<"="<<Wt;
S='F';
w=w+B;
t=w;
i=2;
}
else
i++;
}
}
for(i=1;i<=n;i++)
cout<<"Wt"<<i<<"=="<<Wt;
for(i=1;i<=n;i++)
Twt=Twt+(Wt-A);
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt<<" ";
cout<<"Average Weighting Time="<<Awt<<" ";
}
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=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
cout<<"Enter the priority for process P"<<i<<"= ";
cin>>P;
if(max<P)
max=P;
}
j=1;
while(j<=max)
{
i=1;
while(i<=n)
{
if(P==j)
{
Wt=w;
w=w+B;
}
i++;
}
j++;
}
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt<<" ";
cout<<"Average Weighting Time="<<Awt<<" ";
}
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=Bu;
cout<<"Burst time for process P"<<i<<"= "<<B;
if(B>max)
max=B;
Wt=0;
S='T';
start='F';
Tt=Tt+B;
cout<<"Enter the Arrival Time for"<<i<<"th process= ";
cin>>A;
if(A>Time)
Time=A;
}
int w=0,flag=0,t=0;
i=1;
while(t<Time)
{
if(A<=t && B!=0)
{
if(flag==0)
{
Wt=Wt+w;
cout<<"Wt["<<i<<"]="<<Wt;
}
B=B-1;
if(B==0)
S='F';
start='T';
t++;
w=w+1;
if(S!='F')
{
j=1;flag=1;
while(j<=n && flag!=0)
{
if(S[j]!='F' && B>B[j] && A[j]<=t && i!=j )
{
flag=0;
Wt=Wt-w;
i=j;
}
else
{
flag=1;
}
j++;
}
}
else
{
i++;
j=1;
while(A[j]<=t &&j<=n)
{
if(B>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["<<i<<"]="<<B;
cout<<" ";
while(w<Tt)
{
min=max+1;
i=1;
while(i<=n)
{
if(min>B && S=='T')
{
min=B;
j=i;
}
i++;
}
i=j;
if(w==Time && start=='T')
{
w=w+B;
S='F';
}
else
{
Wt=Wt+w;
w=w+B;
S='F';
}
}
cout<<"Weight info";
for(i=1;i<=n;i++)
cout<<"WT["<<i<<"]="<<Wt;
cout<<"after subtracting arrival time";
for(i=1;i<=n;i++)
{
Wt=Wt-A;
cout<<"WT["<<i<<"]="<<Wt;
}
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Average Weighting Time="<<Awt;
}
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;
m=max/tq+1;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
Rrobin[j]=0;
}
}
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<<" ";
}
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;
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<" ";
}
int main()
{
int ch,cho;
cpuschedule c;
do
{
cout<<"MENU\n";
cout<<"1.Getting BurstTime\n";
cout<<"2.FirstComeFirstServed\n";
cout<<"3.ShortestJobFirst\n";
cout<<"4.RoundRobin \n";
cout<<"5.Priority \n";
cout<<"6.EXIT \n";
cout<<"Enter your choice \n";
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);
return 0;
}تم تعديل هذه المشاركة بواسطة designerh في 6 يونيو 2008 في 01:54
الآن البرنامج يطلب ادخال Burst time لكل عمليه. سهل ايجاد مجموعه.
لكن witing time هل تريد ان يطلب من المستخدم ام ماذا؟
total time ! اي وقت هل تقصد Burst +witing ام ماذا؟
ايضا هناك المصفوفة Bu حجمها عشرون والمستخدم قد يدخل اكثر من ذلك.
وكذلك B=Bu حجم ثابت عشرة!
witing time أوكي محسوب بشكل مضبوط وهو عبارة عن الوقت الذي تتنظره العملية رقم 2 حتى ينجز رقم واحد
ورقم ثلاثة حتى ينجز رقم 2
أنتظر الرسمة التالية
يخرج محسوب بشكل سليم يعني أترك witing time
total time هو عبارة عن مجموع burst timeمع مجموع witing time
______________________________________________________
بخصوص المصفوفات التي عددها ثابت إذا ممكن تعدلها إلى الكمية التي يريدها المستخدم تكون أفضل
نفس العملية مع Bu
................................................................
تجد الرسمة في المرفقات توضح المطلوب
أنتظر الرد على هذا السؤال
...........................
عـــــــــــــاجل
السلام عليكم: هناك أمور في البرنامج ....
لكن هنا بعض التعديل والأضافات البرنامج يحتاج الى أكثر من ذلك.
[background=#CBA]
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
class cpuschedule
{
int n;
int *Bu;
float Twt,Awt,A[10],Wt[10],w;
public:
void Getdata();
void Fcfs();
void Sjf();
void SjfP();
void SjfNp();
void RoundRobin();
void Priority();
};
void cpuschedule::Getdata()
{
int i;
cout<<"Enter the no of processes:";
cin>>n;
Bu=new int(n);
for(i=0;i<n;i++)
{
cout<<"Enter The BurstTime for Process p"<<i<<"= ";
cin>>Bu;
}
}
void cpuschedule::Fcfs()
{
int i,kk=0;
float zz=0;
int* B;
int*uu;
B=new int(n);
uu=new int(n);
Twt=0.0;
for(int ggg=0;ggg<n;ggg++)
{
kk+=Bu[ggg];
uu[ggg]=kk;
}
for(int ggg=0;ggg<n;ggg++)zz+=float(uu[ggg]);
zz=float(zz/n);
for(i=0;i<n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B<<endl;
}
Wt[1]=0;
for(i=2;i<=n;i++)
{
Wt=B[i-1]+Wt[i-1];
}
for(i=0;i<n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Turnarround time="<<zz<<endl;
cout<<"Total Weighting Time="<<Twt<<endl;
cout<<"Average Weighting Time="<<Awt<<endl;
}
void cpuschedule::Sjf()
{
int i,j,temp;
int *B;
B=new int(n);
Twt=0.0;
for(i=0;i<n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
}
for(i=n-1;i>=0;i--)
{
for(j=0;j<n;j++)
{
if(B[j-1]>B[j])
{
temp=B[j-1];
B[j-1]=B[j];
B[j]=temp;
}
}
}
Wt[0]=0;
for(i=1;i<n;i++)
{
Wt=B[i-1]+Wt[i-1];
}
for(i=0;i<n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<" ";
}
void cpuschedule::SjfNp()
{
int i,B[10],Tt=0,temp,j;
char S[10];
float A[10],temp1,t;
Twt=0.0;
w=0.0;
for(i=1;i<=n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
S='T';
Tt=Tt+B;
cout<<"=Enter the Arrival Time for"<<i<<"th process= ";
cin>>A;
}
for(i=n;i>=1;i--)
{
for(j=3;j<=n;j++)
{
if(B[j-1]>B[j])
{
temp=B[j-1];
temp1=A[j-1];
B[j-1]=B[j];
A[j-1]=A[j];
B[j]=temp;
A[j]=temp1;
}
}
}
for(i=1;i<=n;i++)
{
cout<<"p"<<i<<" "<<B<<" "<<A;
}
Wt[1]=0;
w=w+B[1];
t=w;
S[1]='F';
while(w<Tt)
{
i=2;
while(i<=n)
{
if(S=='T'&&A<=t)
{
Wt=w;
cout<<"WT"<<i<<"="<<Wt;
S='F';
w=w+B;
t=w;
i=2;
}
else
i++;
}
}
for(i=1;i<=n;i++)
cout<<"Wt"<<i<<"=="<<Wt;
for(i=1;i<=n;i++)
Twt=Twt+(Wt-A);
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt<<" ";
cout<<"Average Weighting Time="<<Awt<<" ";
}
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=Bu;
cout<<"Burst time for process p"<<i<<"= ";
cout<<B;
cout<<"Enter the priority for process P"<<i<<"= ";
cin>>P;
if(max<P)
max=P;
}
j=1;
while(j<=max)
{
i=1;
while(i<=n)
{
if(P==j)
{
Wt=w;
w=w+B;
}
i++;
}
j++;
}
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt<<" ";
cout<<"Average Weighting Time="<<Awt<<" ";
}
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=Bu;
cout<<"Burst time for process P"<<i<<"= "<<B;
if(B>max)
max=B;
Wt=0;
S='T';
start='F';
Tt=Tt+B;
cout<<"Enter the Arrival Time for"<<i<<"th process= ";
cin>>A;
if(A>Time)
Time=A;
}
int w=0,flag=0,t=0;
i=1;
while(t<Time)
{
if(A<=t && B!=0)
{
if(flag==0)
{
Wt=Wt+w;
cout<<"Wt["<<i<<"]="<<Wt;
}
B=B-1;
if(B==0)
S='F';
start='T';
t++;
w=w+1;
if(S!='F')
{
j=1;flag=1;
while(j<=n && flag!=0)
{
if(S[j]!='F' && B>B[j] && A[j]<=t && i!=j )
{
flag=0;
Wt=Wt-w;
i=j;
}
else
{
flag=1;
}
j++;
}
}
else
{
i++;
j=1;
while(A[j]<=t &&j<=n)
{
if(B>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["<<i<<"]="<<B;
cout<<" ";
while(w<Tt)
{
min=max+1;
i=1;
while(i<=n)
{
if(min>B && S=='T')
{
min=B;
j=i;
}
i++;
}
i=j;
if(w==Time && start=='T')
{
w=w+B;
S='F';
}
else
{
Wt=Wt+w;
w=w+B;
S='F';
}
}
cout<<"Weight info";
for(i=1;i<=n;i++)
cout<<"WT["<<i<<"]="<<Wt;
cout<<"after subtracting arrival time";
for(i=1;i<=n;i++)
{
Wt=Wt-A;
cout<<"WT["<<i<<"]="<<Wt;
}
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Average Weighting Time="<<Awt;
}
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;
m=max/tq+1;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
Rrobin[j]=0;
}
}
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<<" ";
}
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;
for(i=1;i<=n;i++)
Twt=Twt+Wt;
Awt=Twt/n;
cout<<"Total Weighting Time="<<Twt;
cout<<"Average Weighting Time="<<Awt<<" ";
}
int main()
{
int ch,cho;
cpuschedule c;
do
{
cout<<"MENU\n";
cout<<"1.Getting BurstTime\n";
cout<<"2.FirstComeFirstServed\n";
cout<<"3.ShortestJobFirst\n";
cout<<"4.RoundRobin \n";
cout<<"5.Priority \n";
cout<<"6.EXIT \n";
cout<<"Enter your choice \n";
cin>>ch;
switch(ch)
{
case 1:
c.Getdata();
break;
case 2:
cout<<"FIRST COME FIRST SERVED SCHEDULING\n";
c.Fcfs();
break;
case 3:
cout<<"SHORTEST JOB FIRST SCHEDULING \n";
do
{
cout<<"1.SJF-Normel \n";
cout<<"2.SJF-Preemptive \n";
cout<<"3.SJF-NonPreemptive \n";
cout<<"Enter your choice \n";
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 \n";
c.RoundRobin();
break;
case 5:
cout<<"PRIORITY SCHEDULING \n";
c.Priority();
break;
case 6:
break;
}
}while(ch<=5);
return 0;
}
[/background]السلام عليكم:
اليك الكود التالي: فقط ضبط الباقي .
[background=#CBA]
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
class cpuschedule
{
int n;
int *Bu;
public:
void Getdata();
void Turnarround();
void Throuput();
void Average_witting_time();
void CPU_utilization();
};
void cpuschedule::Getdata()
{
cout<<"Enter the no of processes:";
cin>>n;
Bu=new int(n);
for(int i=0;i<n;i++)
{
cout<<"Enter The BurstTime for Process p"<<i+1<<"= ";
cin>>Bu;
}
}
void cpuschedule::Turnarround ()
{
float k=0,zz=0;
int* B;
int*uu;
B=new int(n);
uu=new int(n);
for(int i=0;i<n;i++)
{
k+=Bu;
uu=k;
}
for(int i=0;i<n;i++)zz+=float(uu);
zz=float(zz/n);
for(int i=0;i<n;i++)
{
B=Bu;
cout<<"Burst time for process p"<<i+1<<"= ";
cout<<B<<endl;
}
cout<<"Turnarround time="<<zz<<endl;
}
void cpuschedule::Throuput()
{ float d=0;
for(int i=0;i<n;i++)
{
d+=Bu;
}
cout<<"Throuput ="<<float(n/d)<<endl;
}
void cpuschedule::Average_witting_time()
{ int* h;
int d=0;
float f=0;
h=new int(n);
for(int i=0;i<n;i++)
{
d+=Bu;
h=d;
}
for(int i=0;i<n-1;i++) f+=h;
cout<<"Average witting time ="<<float(f/n)<<endl;
}
void cpuschedule::CPU_utilization()
{
int* h;
int d=0;
float f=0;
h=new int(n);
for(int i=0;i<n;i++)
{
d+=Bu;
h=d;
}
for(int i=0;i<n-1;i++) f+=h ;
cout<<"CPU utilization ="<<float(d/f)*100<<endl;
}
int main()
{
cpuschedule test;
test.Getdata();
test.Turnarround();
test.Throuput();
test.Average_witting_time();
test.CPU_utilization();
return 0;
}
[/background]cpu utilization
حاولت أخليه يطلع في القائمة وما ضبط معي
................................
يا ريت تساعدني