SlideShare a Scribd company logo
1 of 4
Download to read offline
Please modify the following code in C.
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
}"
v. 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 processes Write 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 (1.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 block:Size by adding 1 to variable id
then modulus the total by the number of blocks g. Call function displayProcess passing arguments
allocation, processes, and processSize Write 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 (1.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 (1.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. INTALID) 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 bestId x 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 processSize Write 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 wrtIdx 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 (1.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 process Size 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)

More Related Content

Similar to Please modify the following code in C Here is the initial c.pdf

01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptxDwijBaxi
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
memory allocation by Novodita
memory allocation by Novoditamemory allocation by Novodita
memory allocation by NovoditaSHRISTEERAI1
 
memory allocation.pptx
memory allocation.pptxmemory allocation.pptx
memory allocation.pptxSHRISTEERAI1
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arraysDivyaR219113
 
Dynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptxDynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptxssuser688516
 
Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog Pushpa Yakkala
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
Lecture_01.2.pptx
Lecture_01.2.pptxLecture_01.2.pptx
Lecture_01.2.pptxRockyIslam5
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentationNimrita Koul
 
Lecture2 process structure and programming
Lecture2   process structure and programmingLecture2   process structure and programming
Lecture2 process structure and programmingMohammed Farrag
 
Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01Lalit009kumar
 

Similar to Please modify the following code in C Here is the initial c.pdf (20)

Database Sizing
Database SizingDatabase Sizing
Database Sizing
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
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
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arrays
 
Dynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptxDynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptx
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog
 
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
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Python array
Python arrayPython array
Python array
 
Arrays
ArraysArrays
Arrays
 
Lecture_01.2.pptx
Lecture_01.2.pptxLecture_01.2.pptx
Lecture_01.2.pptx
 
C# p9
C# p9C# p9
C# p9
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentation
 
Lecture2 process structure and programming
Lecture2   process structure and programmingLecture2   process structure and programming
Lecture2 process structure and programming
 
Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01
 
Arrays
ArraysArrays
Arrays
 

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

_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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

_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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
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
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
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
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Please modify the following code in C Here is the initial c.pdf

  • 1. Please modify the following code in C. 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 }" v. 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 processes Write 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 (1.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 block:Size by adding 1 to variable id then modulus the total by the number of blocks g. Call function displayProcess passing arguments allocation, processes, and processSize Write 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 (1.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 (1.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. INTALID) 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 bestId x 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 processSize Write 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 wrtIdx 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 (1.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 process Size 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)