Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pls help in completing the program. Then Encode, compile, debug the following code (page 7 was not provided to us). Also pls give explanation to

Pls help in completing the program. Then Encode, compile, debug the following code (page 7 was not provided to us). Also pls give explanation to the whole process of the program and show output. (if need more information can you pls state on what it is you needed.) Thanks in advance and will rate it ASAP. image text in transcribed image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed PAGE 5 #include"stdafx.h" #includestdio.h> #include #includestring.h> #includestdlib.h> #include&, int int); boolinitAlloc(allocList*&, int*, int); intdoFirstFit(proclist * allocList *) ; intcmptFragmentation(procList*,allocList*); int search(procList*, int); bool reset(procList*, allocList*); int tmain(intargc, TCHAR* argv[]) { intarrMemory[]={100, 500, 200, 300, 600}; intarrJobs[]={212, 17, 112, 426, 500}; allocList *ptrAllocStart=NULL; proclist *ptrProcStart=NULL; initProc(ptrProcStart, arrjobs, (sizeof(arrJobs)/sizeof(int))); initAlloc(ptrAllocStart,arrMemory,(sizeof(arrMemory)/sizeof(int))); cout

PAGE 6 cout&ptrProcStart, int ptrArrProc, int length) { int i; proclist*ptrProc=ptrProcStart; for(i=0; ilength; i++) { if(ptrProc != NULL) { ptrProc-nxt=newproclist; ptrProc = ptrproc-nxt; ptrProc-startProc=(char*)malloc(*(ptrArrProc+i)); ptrProc-endProc=ptrProc-startproc+ *(ptrArrProc+i); memset(ptrProc-startProc, 'a'+i, * (ptrArrProc+i)); ptrProc-jobstatus=0; ptrProc-pid=i; ptrProc-nxt=NULL; } else { ptrProc=newproclist; ptrproc-startProc=(char*)malloc(*(ptrArrp/oc+i)); ptrProc-endProc=ptrProc-startProc+*(ptrArrProc+i); memset(ptrProc-startproc, 'a'+i, * (ptrArrProc+i)); ptrProc-jobstatus=0; ptrProc-pid=i; ptrProc-nxt=NULL; ptrProcStart=ptrProc; } return true; } { int i; allocList*ptrAlloc=ptrAllocStart; for (i=0; ilength;i++) { if(ptrAlloc !=NULL) boolinitAlloc (allocList*&ptrAllocStart, int *ptrArrAlloc, int length)

PAGE 8 coutnxt; } return size; intemptFragmentation(procList* jobs, allocList* mem) > allocList *memtrav, *temp; proclist *jobtrav; jobtrav=jobs; memtrav=mem; intfreespace=, memsize, jobsize; int i=0; while(memtrav-nxt!=NULL) { if(memtrav-nxt->fk pid==0) freespace+=(memtrav-nxt-endAlloc-memtrav-nxt-startAlloc); temp=memtrav-nxt; memtrav-nxt=memtrav-nxt-nxt; delete temp; } memtrav=memtrav-nxt;

PAGE 9 if(memtrav-fk pid==0) { freespace+=(memtrav-endAlloc-memtrav-startAlloc); memtrav=memtrav-nxt; } memtrav=mem; while(memtrav!=NULL) { jobsize=search(jobs,memtrav-fk_pid-1); memsize=memtrav-endAlloc-memtrav-startAlloc; if (memtrav-fk_pid!=0) memtrav-endAlloc=memtrav-startAlloc+jobsize; } freespace+=(memsize-jobsize); memtrav=memtrav-nxt; I memtrav=mem; while(memtrav!=NULL){ if(memtrav-nxt==NULL) memtrav-nxt=newallocList; memtrav=memtrav-nxt; memtrav-startAlloc=(char*)malloc(freespace); memtrav-endAlloc=memtrav-startAlloc+freespace; memset (memtrav-startAlloc, 0, freespace); memtrav-fk_pid=0; memtrav-nxt=NULL; break; } memtrav=memtrav-nxt; 3 memtrav=mem; cout

PAGE 10 if(jobtrav-jobStatus==0) { doFirstFit(jobs, mem); cmptFragmentation(jobs, mem); } jobtrav=jobtrav-nxt; } return 0; } { bool reset(proclist* jobs, allocList* mem) proclist* tempj=jobs;; alloclist* tempa=mem; while(jobs-nxt!=NULL) { jobs=jobs-nxt; free(tempj); tempj=jobs; } free(tempj); while(mem-nxt!=NULL) { mem=mem->nxt; free(tempa); tempa=mem; } free(tempa); return true;

Drill 25 MEMORY MANAGEMENT PARTIAL CODE (SAMPLE PROGRAM) #include" stdafx.h" #include #include. #include #include #include usingnamespacestd; struct alloclist { char *startAlloc; char *endAlloc; intfk_pid; allocList *nxt; }; Struct procList { int pid; int jobStatus; char *start Proc; char *endProc; proclist *nxt; }; boolinitProc(procList *&, int*, int); boolinitAlloc(allocList*&, int*,int); intdoFirstFit(proclist *, alloclist *); intcmptFragmentation (procList*, allocList*); int search(proclist*, int); bool reset(procList*, allocList*); int _tmain(intargc, _TCHAR* argv[]) { intarrMemory []={100, 500, 200, 300, 600}; intarr Jobs ( )={212, 17, 112, 426, 500}; alloclist *ptrAllocStart=NULL; procList *ptr ProcStart=NULL; initProc(ptrProcStart, arrJobs, (sizeof(arrJobs)/sizeof(int))); initAlloc(ptrAllocStart, arrMemory, (sizeof(arrMemory)/sizeof(int))); coutnxt=newproclist; ptrProc = ptr Proc->nxt; ptrProc->startProc=(char*)malloc(*(ptrArrProc+i)); ptrProc->endProc=ptr Proc->startProc + *(ptrArrProc+i); memset(ptr Proc->startProc, 'a'+i,*(ptrArrProc+i)); ptr Proc-jobStatus=0; ptrProc->pid=i; ptr Proc->nxt=NULL; } else { ptr Proc=newproclist; ptrProc->startProce(char*) malloc(*(ptrArrpfoc+i)); ptr Proc->endProcuptr Proc->startProc + *(ptrArr Proc+i); memset(ptrProc->startProc, 'a'+i, *(ptrArrProc+i)); ptrProc->jobStatus=0; ptr Proc->pid=i; ptr Proc->nxt=NULL; ptr ProcStart=ptrProc; } } return true; } boolinitAlloc (allocList*&ptrAllocStart, int *ptrArralloc, int length) { int i; alloclist *ptrAlloc=ptrAllocStart; for(i=0; iendAlloc-memory->startAllocfk_pidendAlloc-memory->startAlloc-search(proc, memory->fk_pid-1) nxt; } return; } int search(proclist* job, int id) { int size=0; whil(job!=NULL) { if(job->pid==id) { size=(int)job->endProc-(int)job->startProc; break; } job=job->nxt; } return size; } intcmptFragmentation (procList* jobs, alloclist* mem) { alloclist *memtrav, *temp; proclist *jobtrav; jobtrav=jobs; memtrav=mem; int freespace=0, memsize, jobsize; int i=0; while(memtrav->nxt !=NULL) { if(memtrav->nxt->fk_pid==6) { freespace+=(memtrav->nxt->endAlloc-memtrav->nxt->startAlloc); temp=memtrav->nxt; memtrav->nxt=memtrav->nxt->nxt; delete temp; } memtrav=memtrav->nxt; } 9 Drill 2 MEMORY MANAGEMENT if(memtrav->fk_pid==0) { freespace+=(memtrav->endAlloc-memtrav->startAlloc); memtrav=memtrav->nxt; } memtrav=mem; while(memtrav!=NULL) { jobsize=search(jobs, memtrav->fk_pid-1); memsize=memtrav->endAlloc-memtrav->startAlloc; if(memtrav->fk_pid!=0) { memtrav->endAlloc=memtrav->startAlloc+jobsize; } freespace+=(memsize-jobsize); memtrav=memtrav->nxt; } memtrav=mem; while(memtrav!=NULL) { if(memtrav->nxt==NULL) { memtrav->nxt=newallocList; memtrav=memtrav->nxt; memtrav->startAlloc=(char*) malloc(freespace); memtrav->endAlloc=memtrav->startAlloc+freespace; memset(memtrav->startAlloc, 0, freespace); memtrav->fk_pid=0; memtrav->nxt=NULL; break; } memtrav=memtrav->nxt; } memtrav=mem; coutendAlloc-memtrav->startAlloc fk_pid endAlloc-memtrav->startAlloc- search(jobs,memtrav->fk_pid-1)nxt; } while(jobtrav!=NULL) { 10 Drill 2 MEMORY MANAGEMENT if(jobtrav->jobStatus==0) { doFirstFit (jobs, mem); cmptFragmentation(jobs, mem); } jobtrav=jobtrav->nxt; } return; } bool reset(proclist* jobs, allocList* mem) { proclist* tempj-jobs;; alloclist* tempa=mem; while(jobs->nxt!=NULL) { jobs-jobs->nxt; free(tempj); tempj-jobs; } free(tempj); while(mem->nxt!=NULL) { mem=mem->nxt; free(tempa); tempa-mem; } free(tempa); return true; } Drill 25 MEMORY MANAGEMENT PARTIAL CODE (SAMPLE PROGRAM) #include" stdafx.h" #include #include. #include #include #include usingnamespacestd; struct alloclist { char *startAlloc; char *endAlloc; intfk_pid; allocList *nxt; }; Struct procList { int pid; int jobStatus; char *start Proc; char *endProc; proclist *nxt; }; boolinitProc(procList *&, int*, int); boolinitAlloc(allocList*&, int*,int); intdoFirstFit(proclist *, alloclist *); intcmptFragmentation (procList*, allocList*); int search(proclist*, int); bool reset(procList*, allocList*); int _tmain(intargc, _TCHAR* argv[]) { intarrMemory []={100, 500, 200, 300, 600}; intarr Jobs ( )={212, 17, 112, 426, 500}; alloclist *ptrAllocStart=NULL; procList *ptr ProcStart=NULL; initProc(ptrProcStart, arrJobs, (sizeof(arrJobs)/sizeof(int))); initAlloc(ptrAllocStart, arrMemory, (sizeof(arrMemory)/sizeof(int))); coutnxt=newproclist; ptrProc = ptr Proc->nxt; ptrProc->startProc=(char*)malloc(*(ptrArrProc+i)); ptrProc->endProc=ptr Proc->startProc + *(ptrArrProc+i); memset(ptr Proc->startProc, 'a'+i,*(ptrArrProc+i)); ptr Proc-jobStatus=0; ptrProc->pid=i; ptr Proc->nxt=NULL; } else { ptr Proc=newproclist; ptrProc->startProce(char*) malloc(*(ptrArrpfoc+i)); ptr Proc->endProcuptr Proc->startProc + *(ptrArr Proc+i); memset(ptrProc->startProc, 'a'+i, *(ptrArrProc+i)); ptrProc->jobStatus=0; ptr Proc->pid=i; ptr Proc->nxt=NULL; ptr ProcStart=ptrProc; } } return true; } boolinitAlloc (allocList*&ptrAllocStart, int *ptrArralloc, int length) { int i; alloclist *ptrAlloc=ptrAllocStart; for(i=0; iendAlloc-memory->startAllocfk_pidendAlloc-memory->startAlloc-search(proc, memory->fk_pid-1) nxt; } return; } int search(proclist* job, int id) { int size=0; whil(job!=NULL) { if(job->pid==id) { size=(int)job->endProc-(int)job->startProc; break; } job=job->nxt; } return size; } intcmptFragmentation (procList* jobs, alloclist* mem) { alloclist *memtrav, *temp; proclist *jobtrav; jobtrav=jobs; memtrav=mem; int freespace=0, memsize, jobsize; int i=0; while(memtrav->nxt !=NULL) { if(memtrav->nxt->fk_pid==6) { freespace+=(memtrav->nxt->endAlloc-memtrav->nxt->startAlloc); temp=memtrav->nxt; memtrav->nxt=memtrav->nxt->nxt; delete temp; } memtrav=memtrav->nxt; } 9 Drill 2 MEMORY MANAGEMENT if(memtrav->fk_pid==0) { freespace+=(memtrav->endAlloc-memtrav->startAlloc); memtrav=memtrav->nxt; } memtrav=mem; while(memtrav!=NULL) { jobsize=search(jobs, memtrav->fk_pid-1); memsize=memtrav->endAlloc-memtrav->startAlloc; if(memtrav->fk_pid!=0) { memtrav->endAlloc=memtrav->startAlloc+jobsize; } freespace+=(memsize-jobsize); memtrav=memtrav->nxt; } memtrav=mem; while(memtrav!=NULL) { if(memtrav->nxt==NULL) { memtrav->nxt=newallocList; memtrav=memtrav->nxt; memtrav->startAlloc=(char*) malloc(freespace); memtrav->endAlloc=memtrav->startAlloc+freespace; memset(memtrav->startAlloc, 0, freespace); memtrav->fk_pid=0; memtrav->nxt=NULL; break; } memtrav=memtrav->nxt; } memtrav=mem; coutendAlloc-memtrav->startAlloc fk_pid endAlloc-memtrav->startAlloc- search(jobs,memtrav->fk_pid-1)nxt; } while(jobtrav!=NULL) { 10 Drill 2 MEMORY MANAGEMENT if(jobtrav->jobStatus==0) { doFirstFit (jobs, mem); cmptFragmentation(jobs, mem); } jobtrav=jobtrav->nxt; } return; } bool reset(proclist* jobs, allocList* mem) { proclist* tempj-jobs;; alloclist* tempa=mem; while(jobs->nxt!=NULL) { jobs-jobs->nxt; free(tempj); tempj-jobs; } free(tempj); while(mem->nxt!=NULL) { mem=mem->nxt; free(tempa); tempa-mem; } free(tempa); 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

More Books

Students also viewed these Databases questions