Answered step by step
Verified Expert Solution
Question
1 Approved Answer
pls do in C++ Please fill in the code in all places where there have a ToDo comment. Hints - Start with the simiplest function,
pls do in C++
Please fill in the code in all places where there have a ToDo comment. Hints - Start with the simiplest function, e.g., the one to search the content of an array. The suggested order to write the function is: 1. Function to search for a value in an unordered array, return index 2. Function to say if an array is in sorted order 3. Function to find the insert position for a new element (assume sorted) 4. Function to remove an element from the array while maintaining order: after removing, the array should have no holes. 5. Function to fill an array with positive integers 6. Function to insert an element into the given position in the array, the array should have an additional element (if there is room!) - Write one function, test it to make sure it really works, and then move on to next function. - Write comments to 1) document your algorithms and design, 2) make your code readable, 3) debug code. \#include using namespace std; const int CAPACITY=20 I/ displayArray - display the array on a single line separated by blanks. I/ @param: int array[] is an array of integers I/ @param: int numberOfElements void displayArray(int array[], int numElements); I/ToDo: Declare a function fillArray that fills an int array with values entered I/ by the user. Stop reading when the user inputs 1 or you reach CAPACITY. // fillArray - read a list of positive integers ending with -1 or until CAPACITY I/ @param: int array[] is an array of integers /I @param: int\& numberElements has the number of Elements in the array I/ @returns void. //ToDo: Declare a function isArraySorted that determines if an array is in order I/ isArraysorted - goes thru the elements checking to see if they are in order I/ @param: int array[] is an array I/ @param: int numElements I/ @returns: true if the array is in sorted order, false otherwise //ToDo: Declare a function that finds the insert position for a given value //in an ordered array. I/ findlnsertPosition - looks thru an ordered array to find the position of I/ the value to insert. All values before are less than the target value. II The value after should be greater than the target value. [No need to sort] I/ @param: int array[] is an ordered array II @param: int numElements I/ @param: int value to insert I/ @return index of the position where the element should be inserted I/ToDo: Declare a function that searches for an element in the given arry I/ searchElement - searches for the element in the given array. II @param int array[] is an unordered array of integers I/ @param int numberOfElements II @param int element I/ @returns index of element or 1 if not found. I/ToDo: Declare a function that removes (i.e., deletes) the element I/ removeElement - removes the element of the given index from the given array. I/ @param: int array[] is an unordered array of integers I/ @param: int\& numberElements I/ @param: int position of element to delete I/ @returns: true if delete was successful, false otherwise I/ToDo: Delcare a function that inserts the element in the given position // insertElement - removes the element of the given index from the given array. I/ @param: int array[] is an unordered array of integers I/ @param: int\& numberElements I/ @param: int position to insert into // @param: int target to insert. I/ @returns: true if insert was successful, false otherwise int main() \{ II The numArray can be partially filled, we use variable numArrayElems I/ to keep track of how many numbers have been stored in the array. int numArray[CAPACITY]; I/ an int array with a given CAPACITY int numArrayElems=0; I/ the array is initially empty, i.e., contains 0 elements II 1. ToDo: Call your fillArray function to read in a sequence of integer values, II separated by space, and ending with 1. Store the values in the numArray array I/ and the number of elements in numArrayElems. // Display the contents of the array afterwards I/ 2. ToDo: Read in a value from the user. Call your findPosition function I/ to get the position to insert, then call insertElement to insert the value // into the position of the array. I/ Display the contents of the array afterwards coutStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started