
السلاااام عليكم ،
انا محتاجه ضرووري ياليت تقدر تبرمج لي هذا الشيت
Write a program to implement the banker's algorithm in C++ version.5 code.
Do the following:
Declare these variables as global constants:
N number of processes
M number of resources' types
Declare these variables as global variables:
Inst 1-dimension array (M) contains the number of instances of each recourse type
Alloc 2-dimension array (N*M) contains the allocated recourses for each process
Max 2-dimension array (N*M) contains the maximum need for each process
Pè the process number that send a request (Req) (0,1,2,…..,n)
Req è 1-dimension array (M) contains the requested recourses of process P
You must use these variables' names:
Need 2-dimension array (N*M) contains the actual need for each process
Avl è 1-dimension array (M) contains the available recourses (i.e. not allocated)
Workè1-dimension array (M) contains the available recourses (used in safety algorithm)
Fnshè1-dimension array (N) contains flags to indicate if a process finished or not (used in safety algorithm)
Program Input:
No input from user. All needed values will be declared as global variables and initialized inside the program.
Const int n =5; //number of processes
Const int m= 3; //number of recourses' types
// values of resources' instances
Int inst[m]= {10,5,7};
// values of allocation array
Int alloc[n][m]= { {0,1,0},
{2,0,0},
{3,0,2},
{2,1,1},
{0,0,2}};
// values of max array
Int max[n][m]= { {7,5,3},
{3,2,2},
{9,0,2},
{2,2,2 },
{4,3,3}};
Int p=1; // the requested process' No.
int req[m] ={1,0,2}; //the request
Program output:
The output will be a display of the contents of Avl ,Need,Alloc, work, fnsh and a suitable message of the following:
Invalid requestè (if Req ≤ Need)
Process (i) will wait because recourses are not availableè (if Req ≤ Avl)
Process (i) will wait because new state is not safe.
Process (i) will executed immediately & display the appropriate process's sequences.
Where : ( i) is the process number.
Delivery procedure:
Deadline: Sunday 13/11/1430 H – 1/11/2009 @ 12:05 PM
You must deliver :
A print of source code.
A soft copy (on a CD)of source code (.cpp) and all files produced after compiling & linking
CD must be clean (free of viruses and threats)
The code must be able to run ( No errors in syntax or linking…etc), any code with errors will be evaluated by zero!!!
Use Only CD's and an enclosed plastic file
Write your name + your group (A/B/C) on each page on the hardcopy , on CD, on the plastic file and in side the code (in the header) .
Loose paper is not allowed use pins or paper's clip.
In side the code , you must use clear & summarized comments.
Output format:
Important note: the values bellow aren't true
The arrays contents:
PROCESS ALLOCATED NEED Finish
======== =========== ===== ======
R0 R1 R3 R0 R1 R3
P0 0 1 0 7 4 3 T
P1 3 1 0 6 4 3 T
P2 0 1 4 7 0 3 F
P3 2 1 0 1 4 3 T
P4 1 1 0 3 4 3 F
================================================== =====
Resource Available work
======== =========== =====
R0 3 10
R1 3 5
R2 2 7
================================================== =====
Process (1) will executed immediately
Process's sequences: P1, P2, P0, P4, P3
بكره الساعه 12 التسليم :(