www.pudn.com > bank0.rar > bank.cpp
#include "iostream.h"
#include "stdlib.h"
#include "stdio.h"
#define theSize 5
#define theKind 3
#define theValue 15
class banker
{
public:
int* re;
void newbanker(int size)
{
int i;
re = new int[size];
for (i=0; iavailable.re[k])
{
isdo=false;
break;
}
}
else isdo=false;
if (isdo)
{
for (k=0; k0)
{
check=false;
break;
}
if (check)
{
for (x=0; x<=theKind; x++)
{
available.re[x]-=re.re[x];
allocation[p].re[x]+=re.re[x];
need[p].re[x]-=re.re[x];
}
return true;
}
return false;
}
void main()
{
int x,p;
banker temp;
char ch='y';
temp.newbanker(theKind);
allnew();
while (ch=='Y' || ch=='y')
{
do init(); while(!safe());
system("cls");
print();
do
{
cout<<"输入提出请求的进程号:"<>p;
if (p<0 || p>=theSize) cout<<"进程号输入错误!"<=theSize);
cout<<"输入请求资源(共 "<>temp.re[x];
if (request(temp,p))
{
print();
safe();
println();
}
else cout<<"资源请求错误!"<>ch;
}
while (ch!='Y' && ch!='y' && ch!='N' && ch!='n');
}
}