Question

Write a C++ -program that will implement Worst-fit, memory management algorithms. Your program must do the...

Write a C++ -program that will implement Worst-fit, memory management algorithms. Your program must do the following:

1. Input the memory size and the number and sizes of all the partitions (limit the max number of the partitions to 5);

2. Input the job list that includes:

- Job's name;

- Job's size.

3. 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);

4. Calculate and display initial memory allocation.

Display the memory waste and the jobs that could not be allocated and have to wait.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

program;

#include<bits/stdc++.h>

using namespace std;

void firstFit(int blockSize[], int m, int processSize[], int n)

{

int allocation[n];

memset(allocation, -1, sizeof(allocation));

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

{

for (int j=0; j<m; j++)

{

if (blockSize[j] >= processSize[i])

{

allocation[i] = j;

blockSize[j] -= processSize[i];

break;

}

}

}

cout << "\nProcess No.\tProcess Size\tBlock no.\n";

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

{

cout << " " << i+1 << "\t\t" << processSize[i] << "\t\t";

if (allocation[i] != -1)

cout << allocation[i] + 1;

else

cout << "Not Allocated";

cout << endl;

}

}

int main()

{

int i,n,m;

cout<<"Enter blockSize and memorySize"<<endl;

cin>>m>>n;

int blockSize[m+1],memorySize[n+1];

cout<<"Enter blocks";

for(i=0;i<m;i++)

cin>>blockSize[i];

cout<<"Enter memory sizes to be allocated";

for(i=0;i<m;i++)

cin>>memorySize[i];

firstFit(blockSize, m, memorySize, n);

return 0 ;

}

Add a comment
Know the answer?
Add Answer to:
Write a C++ -program that will implement Worst-fit, memory management algorithms. Your program must do the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The second picture that I attached is the input and output. I already did the code...

    The second picture that I attached is the input and output. I already did the code but I also have to add the partition number assigned to the job (if the job was allocated). Can you please do that for me? I copied and pasted my code below. #include <iostream> #include <string.h> #include <stdio.h> using std::cout; using std::cin; using std::endl; unsigned int memorySize; // Function prototypes unsigned int FirstFit(struct Partition *, int, struct Job *, int); unsigned int BestFit(struct Partition...

  • 4. Worst-fit is an allocation algorithm that allocates the largest free block to a new job....

    4. Worst-fit is an allocation algorithm that allocates the largest free block to a new job. It is the opposite of the best-fit algorithm. Using the following configuration with jobs arriving in order (Job A, B, C, D) and with blocks shown in order from low order memory to high order memory: Job List: Memory Block List: Job Number Memory Requested Memory Block Memory Block Size Job A 44K Block 1 250K Job B 220K Block 2 900K Job C...

  • In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE...

    In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING Your MMS will handle all requests of allocation of memory space by different users (one thread per user) …. HINT(You will use Pthreads and Semaphores). Your MMS will provide the user with an interface for making memory requests and also for freeing up memory that is no longer needed by the user. One of the jobs of your memory management...

  • DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them...

    DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them in three arrays, then sorts the arrays with Insertion Sort, Merge Sort, and Quick Sort, respectively. Augment the three sorting algorithms with counters and report the number of characteristic operations each performs in sorting the (same) random values. INPUT The program reads from the terminal the number of random integers to generate, a seed value for the pseudo-random number generator, and a character that...

  • C++ Code error help. I am getting the error: "expression must have a constant value, the...

    C++ Code error help. I am getting the error: "expression must have a constant value, the value of parameter 'n' ( declared at line 7) cannot be used as a constant" I am also getting this error at lines 65 and 66 with m and n. I do not know how to fix this. Here is my code and ive marked where the errors were with lines: #include<iostream> using namespace std; // Function to allocate memory to blocks as per...

  • Implement a C program unique.c that recreates the functionality of the uniq tool by reading the...

    Implement a C program unique.c that recreates the functionality of the uniq tool by reading the input line by line and dropping each l ine that is identical to the line immediately before it. On the input abc abc abc your program should output abc abc the same output that uniq would produce. While not strictly necessary for this step, it is important as a basis for subsequent steps that you read the entire input and store it as a...

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...

    LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...

  • Requirement Write pseudocode and translate it to ONE C-program for each the following problems. In your...

    Requirement Write pseudocode and translate it to ONE C-program for each the following problems. In your pseudocode and C-program, use only what you have learned in this class so far. (Menu) Design a menu for question 2 and 3. So far, you use one program to solve all lab questions. But some of you may feel awkward when you want to demo/test only one lab question. To overcome that, your program should show a menu so that the users of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT