Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Asks users for Memory size, # of partitions, partition sizes, and job sizes. I n

ID: 3753524 • Letter: A

Question

Asks users for Memory size, # of partitions, partition sizes, and job sizes. I need the first fit algorithm to be in a function because I will need to edit it for my next lab (Best Fit). Therefore, I want the main function to be the same. Just that I would be calling the algorithm through user defined functions.


This should be the output

Memory size : 1000

# of partitions : 4

Partition Sizes :

P1 = 300

P2 = 200

P3 = 400

P4 = 100

Job Sizes :

J1 : 200

J2 : 300

J3 : 100

J4 : 200

P1-> J1 - Waste : 100 | Status : Run

P2-> J3 - Waste : 100 | Status : Run

P3-> J2 - Waste : 100 | Status : Run

P4-> Nothing - Waste : 100

Total waste : 400

Lab. Assignment #2 First Fit Algorithm Objectives: Learn how First-Fit algorithm work in memory management. Learn how to implement First-Fit lgorithm inC Description: Write a C++ program that will implement First-fit, memory management algorithm Your program must do the following: Input the memory size and the number and sizes of all the partitions (limit the max number of the partitions to 5). Input the job list that includes: 1. 2. Job's name Job's size For each job you should create in your program a data structure that will include the job status (Run/Wait) and the partition number (if the job was allocated Calculate and display initial memory allocation. Display the memory waste and the jobs that could not be allocated and have to wait. 3. 4. 5. Code Quality Requirement: 1. Do not put every single logic in the main() function. 2. You must use functions to separate your program's logic into smaller readable pieces. 3. You must use descriptive variable names. Don't use int b 5. What's b?! It's okay to use i or j or any other letters for loops (only loops) 4. You must write meaningful comments to explain your code.

Explanation / Answer

ANS:

GENERAL CODE:

//C++ program

#include<iostream>

using namespace std;

struct job{

string name;

double size;

};

void Firstfit(struct job job_detail[],int job_count,int allocation[],double memory_block[],int part){

int i,j;

for( i=0;i<job_count;i++){

for( j=0;j<part;i++){

if(memory_block[j]>=job_detail[i].size){

memory_block[j]-=job_detail[i].size;

allocation[i]=j+1;

break;

}

}

if(j==part)allocation[i]=0;

}

}

int main(){

double memory_size;

int partition;

int job_count;

cout<<"Enter memory size : ";

cin>>memory_size;

while(1){

cout<<"Enter number of partitions (1 to 5): ";

cin>>partition;

if(partition>0&&partition<=5)break;

cout<<"Invalid partition choice ";

}

cout<<"Enter number of jobs : ";

cin>>job_count;

struct job job_detail[job_count];

for(int i=0;i<job_count;i++){

cout<<"Enter job name : ";

cin>>job_detail[i].name;

cout<<"Enter job size : ";

cin>>job_detail[i].size;

}

int allocation[job_count];

double memory_block[partition] ;

for(int i=0;i<partition;i++)

memory_block[i]= memory_size/partition;

Firstfit(job_detail,job_count,allocation,memory_block,partition);

for(int i=0;i<job_count;i++){

cout<<job_detail[i].name<<" "<<job_detail[i].size;

if(allocation[i])cout<<" allocate memory block "<<allocation[i]<<" ";

else cout<<"not allocated ";

}

}

PLZZZ VOTE THUMBSUP PLZZZZZZZZZZZZZZZZZZ

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote