Home > database >  There is no
There is no

Time:11-19

Cout<& lt;" Please enter the name and number of available resources "& lt; for(i=0; I{
Cin> The name [I];
Cin> Avaiable [I];
}
Cout<& lt;" Please enter the Max "& lt; for(i=0; Ifor(j=0; jCin> Max [I] [j];
Cout<& lt;" Please enter the Allocation "& lt; for(i=0; Ifor(j=0; jCin> Allocation [I] [j];
for(i=0; Ifor(j=0; jNeed [I] [j]=Max [I] [j] - Allocation [I] [j];
Cout<& lt;" Please input the name of the process "& lt; for(i=0; I{
Cin> Job [I]. Name;
Job [I]. Finish=0;
Size++;
}
Cout<& lt;" System is currently available resources Avaliable "& lt; for(i=0; ICoutCoutfor(i=0; ICoutCoutCout<& lt;" Max Allocation Need "& lt; Cout<& lt;" Process name ";
for(j=0; j<3; J++)
{
for(i=0; ICoutCout<& lt;" ";
}
Coutfor(i=0; I{
Cout<& lt;" "& lt; for(j=0; jCoutCout<& lt;" ";
for(j=0; jCoutCout<& lt;" ";
for(j=0; jCoutCout<& lt;" ";
Cout}
}
//security algorithm
Void safe ()
{
Int I, j, L;
L=0;
int f;
Int q=0;
[100] int w={0};
Int Q [100];
for(i=0; IW=Avaiable [I] [I];
Int k=0;
While (1)
{
for(i=0; I{
F=1;
for(j=0; j{
If (Need [I] [j] & gt; W [j])
{
F=0;
break;
}
}
If (Job [I]. Finish==0 & amp; & F==1)
{
for(j=0; jW=w [j] + [j] Allocation [I] [j];
Job [I]. Finish=1;
Q [Q]=I;
Q++;
K=k + 1;
break;
}
}
L++;
If (L==n + 2)
{
Cout<& lt;" Unsafe conditions "& lt; Pan=0;
break;
}
If (k==n)
{
Cout<& lt;" System security "& lt; Pan=1;
for(i=0; ICoutbreak;
}
}
for(i=0; IJob [I]. Finish=0;
}
//the application resources function
Void (TT)
{
int i;
Int b=1, c=1;
Cout<& lt;" Please select the application process of resources "& lt; Cin> a;
Cout<& lt;" Please enter the number of all the resources & lt;" for(i=0; ICin> Request [a] [I];
for(i=0; I{
If (request [a] [I] & gt; Need [a] [I])
{
B=0;
Pan=0;
break;
}
}
for(i=0; I{
If (request [a] [I] & gt; Avaiable [I])
{
c=0;
Pan=0;
break;
}
}
If (b==1 & amp; & C==1)
{
for(i=0; I{
Avaiable [I]=Avaiable [I] - request [a] [I];
Need [a] [I]=Need [a] [I] - request [a] [I];
Allocation of [a] [I]=Allocation request [a] [I] + [a] [I];
}
}
}
//the application failed to return data function
Void of TD ()
{
int i;
for(i=0; I{
Avaiable [I]=Avaiable request [I] + [a] [I];
Need [a] [I]=Need [a] [I] + request [a] [I];
Allocation of [a] [I]=Allocation [a] [I] - request [a] [I];
}
}
};
Int main ()
{
The work s;
Int T;
Int V=1;
S.i n_put ();
S.s afe ();
While (V!=0)
{
Cout<& lt;" Please choose whether or not the application resources "& lt; & lt;" : 1:2: no "& lt; Cin> T;
The switch (T)
{
Case 1: s.T (T);
If (pan==0)
{
S.T (D);
Cout<& lt;" Don't agree to apply for "& lt; break;
}
S.s afe ();
If (pan==0)
{
S.T (D);
Cout<& lt;" Don't agree to apply for "& lt; }
The else
CoutCout<& lt;" Agree to apply for "& lt; break;
Case 2: V=0;
break;
}
}
return 0;
}
  • Related