Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Given the following code snippet, encode, debut and execute the program. The sample code is below. PROGRAMIMING EXERCISE WRITE THE CODE FOR THE FUNCTIONS:

C++ Given the following code snippet, encode, debut and execute the program. The sample code is below. image text in transcribed image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

PROGRAMIMING EXERCISE WRITE THE CODE FOR THE FUNCTIONS: bool release(ProcList*, ResList*, int); intgetMax(ProcList*, ResList*); intgetAlloc(ProcList*,ResList*); intgetAvail(ResList*); \begin{tabular}{r|r} Drill 5 & 5 \\ BANKER'S ALGORITHIM & \end{tabular} PARTIAL CODE (SAMPLE PROGRAM) \#include "stdafx.h" structProclist \{ intpid; char *ptrResRequired; char "ptrResserved; intnResRequired; Proclist *nxt; \} structReslist \{ int rid; char resData; char "ptrResources; intnRes; Reslist *nxt; \} bool allocate(ProcList*, Reslist*, int); bool release(Proclist*, ResList*, int); bool simulate(ProcList *, ResList ); boolprintMatrix(ProcList *, ResList ); intgetMax(ProcList*, ResList*); intgetAlloc(ProcList*, ResList*); intgetAvail(ResList*); boolinitRes(ResList*\&, int*, int); booldeinitRes(Restist \& ); boolinitProc(ProcList*\&, char**, int); booldeinitProc(ProcList*\&); int _tmain(intargc,_TCHAR* argv[]) f intarrRes [ ] = {3,3,5,3}; char "arrptrProc []={ "aabbccdd", "bbccdd", "ccddaa" }; intnProc, length; for (nProc =0, length =0; length +=sizeof(arrptrProc[nProc]); BANKER'S ALGORITHM 56 Drill 5 BANKER'S ALGORITHM BANIIII 59 } boolisReadytoAlloc(ProcList *ptrProc, ResList *ptrRes) \{ int need, avail; do \{ need =getNax( ptrProc, ptrRes )getAlloc( ptrProc, ptrRes ); avail = getAvail (ptrRes); if (need>avail) return false; ptrRes=ptrRes - nxt; \}while (ptrRes!=NULL); return true; \} bool simulate (ProcList *ptrprocstart, ResList *ptrResstart) \{ Proclist * ptrProc = ptrProcstart; ResList "ptrRes = ptrResstart; int need, avail; printf(">Initial Matrix"); printMatrix(ptrProcstart, ptrRes\$tart); printf(" (n"); do \{ if (ptrProc nResRequired !=0 \&\&isReadytoAlloc) \{ ptrRes=ptrResStart; do \{ need =getMax(p trProc, ptrRes )getAlloc(ptrProc, ptrRes ); allocate (ptrproc, ptrRes, need); ptrRes = ptrRes >nxt; \}while (ptrRes 1= NULL); printf(" A Process was allocated: P\%d", ptrproc pid); printMatrix (ptrprocStart, ptrResStart); printf( ); release (ptrProc, ptrResstart, ptrproc-spid); printf(" In>A Process resources was released: p\%d", ptrproc->pid); printMatrix(ptrProcstart, ptrResStart); printf(" ); ptrProc = ptrProcstart; f else ptrProc =p trProc >nxt; \}while (ptrProc!=NULL); ptrProc = ptrProcstart; do \{ if (ptrProc nResRequired I= ) return false; ptrProc = ptrProc >nxt; \}while (ptrProcl=NULL); \begin{tabular}{r|r} Dril 5 & 10 \\ BANKER'S ALGORITHM & \end{tabular} \} return true; bool allocate (ProcList* ptrProc, Reslist *ptrRes, intnToAlloc) f char newptrResources = ptrRes ptrResources; char * chRes; char chProckes = strchr(ptrProc->ptrResRequired, ptrRes->resData); intnRes, nProcRes; for (int i=0;iresData); if(chProcRes i= NULL) \{ nProcRes = chProcRes-ptrProc-sptrResRequired; // index of res memset (ptrProc->ptrResServed+nProcRes, ptrRes->resData, 1); \} chRes = strchr(ptrRes->ptrResources, ptrRes->resData); if(chRes I= NULL) \{ nRes = chRes-ptrRes->ptrResources; // index of res memset (ptrRes > ptrResources + nRes, "?", 1); \} \} return true; \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

a valuing of personal and psychological privacy;

Answered: 1 week ago