SlideShare a Scribd company logo
1 of 4
Download to read offline
Please modify the following code in C. Make sure your code matches the output.
Here is the initial code for OSManagement: "
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define EXIT 0
#define INVALID -1
#define MEMORY 1
#define FILES 2
#define THREAD 3
#define FIRST 0
#define BEST 1
#define WORST 2
#define NEXT 3
int displayMenu();
void clearScreen();
int main() {
int choice = -1;
while (choice != EXIT) {
choice = displayMenu();
switch (choice) {
case MEMORY:
// to be implemented in future assignments
break;
case FILES:
// to be implemented in future assignments
break;
case THREAD:
// to be implemented in future assignments
break;
case EXIT:
exit(0);
break;
default:
printf("Invalid choice. Please try again.n");
}
}
return 0;
}
int displayMenu() {
int choice = -1;
while (choice == -1) {
printf("OS Management Menu:n");
printf("1. Memory Managementn");
printf("2. File Managementn");
printf("3. Multi-Threaded Programmingn");
printf("0. Exitn");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice < 0 || choice > 3) {
printf("Invalid choice. Please try again.n");
choice = -1;
}
}
clearScreen();
return choice;
}
void clearScreen() {
printf("Press ENTER key to continue...");
char c;
scanf("%c", &c);
system("cls"); // comment out for Mac or Linux
// system("clear"); // comment out for Windows
}"
Tasksv. Write decision making logic based on the value of the looping variable (i.e. algorithm) 1.
When algorithm is equal to FIRST, call function firstFit, passing arguments blockSize, blocks,
processSize, and processes 2. When algorithm is equal to BEST, call function bestFit, passing
arguments blockSize, blocks, processSize, and processes 3. When algorithm is equal to WORST,
call function worstFit, passing arguments blockSize, blocks, processSize, and processes 4. When
algorithm is equal to NEXT, call function nextFit, passing arguments blockSize, blocks,
processSize, and processesWrite function nextFit to do the following a. Return type void b.
Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e.
blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One-
dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter
contains the number of processes, data type integer (i.e. processes) c. Declare a one-dimensional
array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is
parameter processes d. Declare a variable, data type integer, to store the block allocation for a
process, initialize to 0 (i.e. id) e. Call function memset, passing arguments i. Array allocation ii. -1
(i.e. INVALID) iii. sizeof(allocation) f. Using a looping construct, loop through the number of
processes i. Using a looping construct, loop while id is less than the number of blocks 1. If the
current block size (i.e. index id) is greater than or equal to the current process size (i.e. index of
outer looping variable) a. Update the allocation array to set the element at index of the outer
looping variable equal to variable id b. Reduce available memory of the current block size (i.e.
index id) by the processsize (i.e. index of the outer looping variable) c. break out of the inner loop
ii. Update the value of variable id to set the next index in array blockSize by adding 1 to variable id
then modulus the total by the number of blocks g. Call function displayProcess passing arguments
allocation, processes, and processSizeWrite function firstFit to do the following a. Return type void
b. Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e.
blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One-
dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter
contains the number of processes, data type integer (i.e. processes) c. Declare a one-dimensional
array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is
parameter processes d. Call function memset, passing arguments i. Array allocation ii. -1 (i.e.
INVALID) iii. sizeof(allocation) e. Using a looping construct, loop through the number of processes
i. Using a looping construct, loop the number of blocks 1. If the current block size (i.e. index of the
inner looping variable ) is greater than or equal to the current process size (i.e. index of outer
looping variable) a. Update the allocation array to set the element at index of the outer looping
variable equal to the inner looping variable b. Reduce available memory of the current block size
(i.e. index of the inner looping variable) by the process size (i.e. index of the outer looping
variable) c. break out of the inner loop f. Call function displayProcess passing arguments
allocation, processes, and processSizeWrite function bestFit to do the following a. Return type
void b. Parameter list includes i. One-dimensional array, data type integer, contains the block
sizes (i.e. blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii.
One-dimensional array, data type integer, contains the process sizes (i.e. processSize) iv.
Parameter contains the number of processes, data type integer (i.e. processes) c. Declare a one-
dimensional array, data type integer, to store the block id that a process is allocated to (i.e.
allocation), size is parameter processes d. Call function memset, passing arguments i. Array
allocation ii. -1 (i.e. INVALID) iii. sizeof(allocation) e. Using a looping construct, loop through the
number of processes i. Declare a variable, data type integer, to store the current best fit value (i.e.
bestIdx) initialized to -1 (i.e. INVALID) ii. Using a looping construct, loop the number of blocks 1. If
the current block size (i.e. index of the inner looping variable ) is greater than or equal to the
current process size (i.e. index of outer looping variable) a. If the value of bestIdx is equal to -1
(i.e. INVALID) i. Set variable bestIdx equal to the current block (i.e. the inner looping variable) b.
Else if the value of the block size at index bestIdx is greater than the value of the block size at
index of the inner looping variable i. Set variable bestidx equal to the current block (i.e. the inner
looping variable) iii. If the value of variable bestIdx is not equal to -1 (i.e. INVALID) 1. Update the
allocation array to set the element at index of the outer looping variable equal to variable bestIdx2.
Reduce available memory of the current block size (i.e. index bestIdx) by the process size (i.e.
index of the outer looping variable) f. Call function displayProcess passing arguments allocation,
processes, and processSizeWrite function worstFit to do the following a. Return type void b.
Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e.
blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One-
dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter
contains the number of processes, data type integer (i.e. processes) c. Declare a one-dimensional
array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is
parameter processes d. Call function memset, passing arguments i. Array allocation ii. -1 (i.e.
INVALID) iii. sizeof(allocation) e. Using a looping construct, loop through the number of processes
i. Declare a variable, data type integer, to store the current worst fit value (i.e. wstIdx) initialized to
-1 (i.e. INVALID) ii. Using a looping construct, loop the number of blocks 1. If the current block size
(i.e. index of the inner looping variable ) is greater than or equal to the current process size (i.e.
index of outer looping variable) a. If the value of wstIdx is equal to -1 (i.e. INVALID) i. Set variable
wstIdx equal to the current block (i.e. the inner looping variable) b. Else if the value of the block
size at index wstIdx is less than the value of the block size at index of the inner looping variable i.
Set variable wstIdx equal to the current block (i.e. the inner looping variable)iii. If the value of
variable wstIdx is not equal to -1 (i.e. INVALID) 1. Update the allocation array to set the element at
index of the outer looping variable equal to variable wstIdx 2. Reduce available memory of the
current block size (i.e. index wstIdx) by the process size (i.e. index of the outer looping variable) f.
Call function displayProcess passing arguments allocation, processes, and processSize Write
function displayProcess to do the following a. Return type void b. Parameter list includes i. One-
dimensional array, data type integer, that stores the block number allocations (i.e. allocation) ii.
Parameter that contains the number of processes, data type integer (i.e. processes) iii. One-
dimensional array, data type integer, that stores the processes (i.e. processSize) c. Write a
looping construct to loop through the processes (i.e. processSize) i. Display to the console the
process number (i.e use the looping variable plus 1 ) ii. Display to the console the process size
(i.e. processSize array at the current looping index) iii. Display to the console the memory block
assigned based on the following logic 1. If the value stored at the current index of array
processSize if -1 (i.e. INVALID), output Not Allocated 2. Else, output the current allocation (i.e.
allocation)Select the OS program to run, enter the number of your selection. 1. Memory
Management 2. File Management 3. Multithreading 0 . ExitFigure 2 memoryManagement function
outputFigure 3 nextFit function output ********** First Fit ********** Figure 4 firstFit function
outputFigure 5 bestFit function outputFigure 6 worstFit function output

More Related Content

Similar to Please modify the following code in C Make sure your code m.pdf

Similar to Please modify the following code in C Make sure your code m.pdf (20)

Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arrays
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Arrays
ArraysArrays
Arrays
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Lecture_01.2.pptx
Lecture_01.2.pptxLecture_01.2.pptx
Lecture_01.2.pptx
 
Python array
Python arrayPython array
Python array
 
Array
ArrayArray
Array
 
C# p9
C# p9C# p9
C# p9
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Dynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptxDynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptx
 
Qtp day 3
Qtp day 3Qtp day 3
Qtp day 3
 
6.array
6.array6.array
6.array
 
memory allocation by Novodita
memory allocation by Novoditamemory allocation by Novodita
memory allocation by Novodita
 
memory allocation.pptx
memory allocation.pptxmemory allocation.pptx
memory allocation.pptx
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 

More from ankit11134

please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdfankit11134
 
Please read below instruction and please give me answer 1.pdf
Please read below instruction and please give me answer   1.pdfPlease read below instruction and please give me answer   1.pdf
Please read below instruction and please give me answer 1.pdfankit11134
 
Please read Sections 13 of the following paper Yufei Tao.pdf
Please read Sections 13 of the following paper  Yufei Tao.pdfPlease read Sections 13 of the following paper  Yufei Tao.pdf
Please read Sections 13 of the following paper Yufei Tao.pdfankit11134
 
Please provide all necessary steps b Let 2XEX+VarX.pdf
Please provide all necessary steps b Let 2XEX+VarX.pdfPlease provide all necessary steps b Let 2XEX+VarX.pdf
Please provide all necessary steps b Let 2XEX+VarX.pdfankit11134
 
Please provide a 150200 word response per question and incl.pdf
Please provide a 150200 word response per question and incl.pdfPlease provide a 150200 word response per question and incl.pdf
Please provide a 150200 word response per question and incl.pdfankit11134
 
Please only write java classes according to diagram below I.pdf
Please only write java classes according to diagram below I.pdfPlease only write java classes according to diagram below I.pdf
Please only write java classes according to diagram below I.pdfankit11134
 
Please mention Chicago style REFERENCES How Tourism Works A.pdf
Please mention Chicago style REFERENCES How Tourism Works A.pdfPlease mention Chicago style REFERENCES How Tourism Works A.pdf
Please mention Chicago style REFERENCES How Tourism Works A.pdfankit11134
 
Please present complete solution The data in the table below.pdf
Please present complete solution The data in the table below.pdfPlease present complete solution The data in the table below.pdf
Please present complete solution The data in the table below.pdfankit11134
 
Please pick a relevant company or make one up Consider the .pdf
Please pick a relevant company or make one up Consider the .pdfPlease pick a relevant company or make one up Consider the .pdf
Please pick a relevant company or make one up Consider the .pdfankit11134
 
Please help with the concept map for eukaryotic transcriptio.pdf
Please help with the concept map for eukaryotic transcriptio.pdfPlease help with the concept map for eukaryotic transcriptio.pdf
Please help with the concept map for eukaryotic transcriptio.pdfankit11134
 
Please match using only the given options Match the definiti.pdf
Please match using only the given options Match the definiti.pdfPlease match using only the given options Match the definiti.pdf
Please match using only the given options Match the definiti.pdfankit11134
 
Please match each component of the logic model presented her.pdf
Please match each component of the logic model presented her.pdfPlease match each component of the logic model presented her.pdf
Please match each component of the logic model presented her.pdfankit11134
 
please make feedbackcomment or response to this post Pro.pdf
please make feedbackcomment or response to this post   Pro.pdfplease make feedbackcomment or response to this post   Pro.pdf
please make feedbackcomment or response to this post Pro.pdfankit11134
 
please make feedbackcomment or response to this post Being.pdf
please make feedbackcomment or response to this post Being.pdfplease make feedbackcomment or response to this post Being.pdf
please make feedbackcomment or response to this post Being.pdfankit11134
 
Please make a lab report with the following Linux command li.pdf
Please make a lab report with the following Linux command li.pdfPlease make a lab report with the following Linux command li.pdf
Please make a lab report with the following Linux command li.pdfankit11134
 
Please label the image given characteristics Basement me.pdf
Please label the image given characteristics   Basement me.pdfPlease label the image given characteristics   Basement me.pdf
Please label the image given characteristics Basement me.pdfankit11134
 
Please include formulas This problem is based on a real acqu.pdf
Please include formulas This problem is based on a real acqu.pdfPlease include formulas This problem is based on a real acqu.pdf
Please include formulas This problem is based on a real acqu.pdfankit11134
 
Please help Two firms engage in simultaneousmove quantity .pdf
Please help Two firms engage in simultaneousmove quantity .pdfPlease help Two firms engage in simultaneousmove quantity .pdf
Please help Two firms engage in simultaneousmove quantity .pdfankit11134
 
Please include all code and scripts will thumbs up Model o.pdf
Please include all code and scripts will thumbs up Model o.pdfPlease include all code and scripts will thumbs up Model o.pdf
Please include all code and scripts will thumbs up Model o.pdfankit11134
 
Please Include explanation 4 Describe the languages denot.pdf
Please Include explanation 4 Describe the languages denot.pdfPlease Include explanation 4 Describe the languages denot.pdf
Please Include explanation 4 Describe the languages denot.pdfankit11134
 

More from ankit11134 (20)

please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
 
Please read below instruction and please give me answer 1.pdf
Please read below instruction and please give me answer   1.pdfPlease read below instruction and please give me answer   1.pdf
Please read below instruction and please give me answer 1.pdf
 
Please read Sections 13 of the following paper Yufei Tao.pdf
Please read Sections 13 of the following paper  Yufei Tao.pdfPlease read Sections 13 of the following paper  Yufei Tao.pdf
Please read Sections 13 of the following paper Yufei Tao.pdf
 
Please provide all necessary steps b Let 2XEX+VarX.pdf
Please provide all necessary steps b Let 2XEX+VarX.pdfPlease provide all necessary steps b Let 2XEX+VarX.pdf
Please provide all necessary steps b Let 2XEX+VarX.pdf
 
Please provide a 150200 word response per question and incl.pdf
Please provide a 150200 word response per question and incl.pdfPlease provide a 150200 word response per question and incl.pdf
Please provide a 150200 word response per question and incl.pdf
 
Please only write java classes according to diagram below I.pdf
Please only write java classes according to diagram below I.pdfPlease only write java classes according to diagram below I.pdf
Please only write java classes according to diagram below I.pdf
 
Please mention Chicago style REFERENCES How Tourism Works A.pdf
Please mention Chicago style REFERENCES How Tourism Works A.pdfPlease mention Chicago style REFERENCES How Tourism Works A.pdf
Please mention Chicago style REFERENCES How Tourism Works A.pdf
 
Please present complete solution The data in the table below.pdf
Please present complete solution The data in the table below.pdfPlease present complete solution The data in the table below.pdf
Please present complete solution The data in the table below.pdf
 
Please pick a relevant company or make one up Consider the .pdf
Please pick a relevant company or make one up Consider the .pdfPlease pick a relevant company or make one up Consider the .pdf
Please pick a relevant company or make one up Consider the .pdf
 
Please help with the concept map for eukaryotic transcriptio.pdf
Please help with the concept map for eukaryotic transcriptio.pdfPlease help with the concept map for eukaryotic transcriptio.pdf
Please help with the concept map for eukaryotic transcriptio.pdf
 
Please match using only the given options Match the definiti.pdf
Please match using only the given options Match the definiti.pdfPlease match using only the given options Match the definiti.pdf
Please match using only the given options Match the definiti.pdf
 
Please match each component of the logic model presented her.pdf
Please match each component of the logic model presented her.pdfPlease match each component of the logic model presented her.pdf
Please match each component of the logic model presented her.pdf
 
please make feedbackcomment or response to this post Pro.pdf
please make feedbackcomment or response to this post   Pro.pdfplease make feedbackcomment or response to this post   Pro.pdf
please make feedbackcomment or response to this post Pro.pdf
 
please make feedbackcomment or response to this post Being.pdf
please make feedbackcomment or response to this post Being.pdfplease make feedbackcomment or response to this post Being.pdf
please make feedbackcomment or response to this post Being.pdf
 
Please make a lab report with the following Linux command li.pdf
Please make a lab report with the following Linux command li.pdfPlease make a lab report with the following Linux command li.pdf
Please make a lab report with the following Linux command li.pdf
 
Please label the image given characteristics Basement me.pdf
Please label the image given characteristics   Basement me.pdfPlease label the image given characteristics   Basement me.pdf
Please label the image given characteristics Basement me.pdf
 
Please include formulas This problem is based on a real acqu.pdf
Please include formulas This problem is based on a real acqu.pdfPlease include formulas This problem is based on a real acqu.pdf
Please include formulas This problem is based on a real acqu.pdf
 
Please help Two firms engage in simultaneousmove quantity .pdf
Please help Two firms engage in simultaneousmove quantity .pdfPlease help Two firms engage in simultaneousmove quantity .pdf
Please help Two firms engage in simultaneousmove quantity .pdf
 
Please include all code and scripts will thumbs up Model o.pdf
Please include all code and scripts will thumbs up Model o.pdfPlease include all code and scripts will thumbs up Model o.pdf
Please include all code and scripts will thumbs up Model o.pdf
 
Please Include explanation 4 Describe the languages denot.pdf
Please Include explanation 4 Describe the languages denot.pdfPlease Include explanation 4 Describe the languages denot.pdf
Please Include explanation 4 Describe the languages denot.pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Please modify the following code in C Make sure your code m.pdf

  • 1. Please modify the following code in C. Make sure your code matches the output. Here is the initial code for OSManagement: " #include <stdio.h> #include <stdlib.h> #include <string.h> #define EXIT 0 #define INVALID -1 #define MEMORY 1 #define FILES 2 #define THREAD 3 #define FIRST 0 #define BEST 1 #define WORST 2 #define NEXT 3 int displayMenu(); void clearScreen(); int main() { int choice = -1; while (choice != EXIT) { choice = displayMenu(); switch (choice) { case MEMORY: // to be implemented in future assignments break; case FILES: // to be implemented in future assignments break; case THREAD: // to be implemented in future assignments break; case EXIT: exit(0); break; default: printf("Invalid choice. Please try again.n"); } } return 0; } int displayMenu() { int choice = -1; while (choice == -1) {
  • 2. printf("OS Management Menu:n"); printf("1. Memory Managementn"); printf("2. File Managementn"); printf("3. Multi-Threaded Programmingn"); printf("0. Exitn"); printf("Enter your choice: "); scanf("%d", &choice); if (choice < 0 || choice > 3) { printf("Invalid choice. Please try again.n"); choice = -1; } } clearScreen(); return choice; } void clearScreen() { printf("Press ENTER key to continue..."); char c; scanf("%c", &c); system("cls"); // comment out for Mac or Linux // system("clear"); // comment out for Windows }" Tasksv. Write decision making logic based on the value of the looping variable (i.e. algorithm) 1. When algorithm is equal to FIRST, call function firstFit, passing arguments blockSize, blocks, processSize, and processes 2. When algorithm is equal to BEST, call function bestFit, passing arguments blockSize, blocks, processSize, and processes 3. When algorithm is equal to WORST, call function worstFit, passing arguments blockSize, blocks, processSize, and processes 4. When algorithm is equal to NEXT, call function nextFit, passing arguments blockSize, blocks, processSize, and processesWrite function nextFit to do the following a. Return type void b. Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e. blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One- dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter contains the number of processes, data type integer (i.e. processes) c. Declare a one-dimensional array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is parameter processes d. Declare a variable, data type integer, to store the block allocation for a process, initialize to 0 (i.e. id) e. Call function memset, passing arguments i. Array allocation ii. -1 (i.e. INVALID) iii. sizeof(allocation) f. Using a looping construct, loop through the number of processes i. Using a looping construct, loop while id is less than the number of blocks 1. If the current block size (i.e. index id) is greater than or equal to the current process size (i.e. index of outer looping variable) a. Update the allocation array to set the element at index of the outer looping variable equal to variable id b. Reduce available memory of the current block size (i.e. index id) by the processsize (i.e. index of the outer looping variable) c. break out of the inner loop
  • 3. ii. Update the value of variable id to set the next index in array blockSize by adding 1 to variable id then modulus the total by the number of blocks g. Call function displayProcess passing arguments allocation, processes, and processSizeWrite function firstFit to do the following a. Return type void b. Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e. blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One- dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter contains the number of processes, data type integer (i.e. processes) c. Declare a one-dimensional array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is parameter processes d. Call function memset, passing arguments i. Array allocation ii. -1 (i.e. INVALID) iii. sizeof(allocation) e. Using a looping construct, loop through the number of processes i. Using a looping construct, loop the number of blocks 1. If the current block size (i.e. index of the inner looping variable ) is greater than or equal to the current process size (i.e. index of outer looping variable) a. Update the allocation array to set the element at index of the outer looping variable equal to the inner looping variable b. Reduce available memory of the current block size (i.e. index of the inner looping variable) by the process size (i.e. index of the outer looping variable) c. break out of the inner loop f. Call function displayProcess passing arguments allocation, processes, and processSizeWrite function bestFit to do the following a. Return type void b. Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e. blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One-dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter contains the number of processes, data type integer (i.e. processes) c. Declare a one- dimensional array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is parameter processes d. Call function memset, passing arguments i. Array allocation ii. -1 (i.e. INVALID) iii. sizeof(allocation) e. Using a looping construct, loop through the number of processes i. Declare a variable, data type integer, to store the current best fit value (i.e. bestIdx) initialized to -1 (i.e. INVALID) ii. Using a looping construct, loop the number of blocks 1. If the current block size (i.e. index of the inner looping variable ) is greater than or equal to the current process size (i.e. index of outer looping variable) a. If the value of bestIdx is equal to -1 (i.e. INVALID) i. Set variable bestIdx equal to the current block (i.e. the inner looping variable) b. Else if the value of the block size at index bestIdx is greater than the value of the block size at index of the inner looping variable i. Set variable bestidx equal to the current block (i.e. the inner looping variable) iii. If the value of variable bestIdx is not equal to -1 (i.e. INVALID) 1. Update the allocation array to set the element at index of the outer looping variable equal to variable bestIdx2. Reduce available memory of the current block size (i.e. index bestIdx) by the process size (i.e. index of the outer looping variable) f. Call function displayProcess passing arguments allocation, processes, and processSizeWrite function worstFit to do the following a. Return type void b. Parameter list includes i. One-dimensional array, data type integer, contains the block sizes (i.e. blockSize) ii. Parameter contains the number of blocks, data type integer (i.e. blocks) iii. One- dimensional array, data type integer, contains the process sizes (i.e. processSize) iv. Parameter contains the number of processes, data type integer (i.e. processes) c. Declare a one-dimensional array, data type integer, to store the block id that a process is allocated to (i.e. allocation), size is parameter processes d. Call function memset, passing arguments i. Array allocation ii. -1 (i.e.
  • 4. INVALID) iii. sizeof(allocation) e. Using a looping construct, loop through the number of processes i. Declare a variable, data type integer, to store the current worst fit value (i.e. wstIdx) initialized to -1 (i.e. INVALID) ii. Using a looping construct, loop the number of blocks 1. If the current block size (i.e. index of the inner looping variable ) is greater than or equal to the current process size (i.e. index of outer looping variable) a. If the value of wstIdx is equal to -1 (i.e. INVALID) i. Set variable wstIdx equal to the current block (i.e. the inner looping variable) b. Else if the value of the block size at index wstIdx is less than the value of the block size at index of the inner looping variable i. Set variable wstIdx equal to the current block (i.e. the inner looping variable)iii. If the value of variable wstIdx is not equal to -1 (i.e. INVALID) 1. Update the allocation array to set the element at index of the outer looping variable equal to variable wstIdx 2. Reduce available memory of the current block size (i.e. index wstIdx) by the process size (i.e. index of the outer looping variable) f. Call function displayProcess passing arguments allocation, processes, and processSize Write function displayProcess to do the following a. Return type void b. Parameter list includes i. One- dimensional array, data type integer, that stores the block number allocations (i.e. allocation) ii. Parameter that contains the number of processes, data type integer (i.e. processes) iii. One- dimensional array, data type integer, that stores the processes (i.e. processSize) c. Write a looping construct to loop through the processes (i.e. processSize) i. Display to the console the process number (i.e use the looping variable plus 1 ) ii. Display to the console the process size (i.e. processSize array at the current looping index) iii. Display to the console the memory block assigned based on the following logic 1. If the value stored at the current index of array processSize if -1 (i.e. INVALID), output Not Allocated 2. Else, output the current allocation (i.e. allocation)Select the OS program to run, enter the number of your selection. 1. Memory Management 2. File Management 3. Multithreading 0 . ExitFigure 2 memoryManagement function outputFigure 3 nextFit function output ********** First Fit ********** Figure 4 firstFit function outputFigure 5 bestFit function outputFigure 6 worstFit function output