Question: Code has to be typed in C++, Pointers and Arrays You will be writing two methods: int make SeparateMemory (int * numbers, int * sizes,

 Code has to be typed in C++, Pointers and Arrays You

will be writing two methods: int make SeparateMemory (int * numbers, int

Code has to be typed in C++, Pointers and Arrays

You will be writing two methods: int make SeparateMemory (int * numbers, int * sizes, int count, int* memorySlices[]); and void cleanupSeparateMemory(int *memoryslices[], int count); We'll go through these one-by-one. [Step 1]: You are to write make SeparateMemory(). We'll use the inclassTestsSimple () test case to explain it. The function is called with an array (numbers) that contains count integers, numbers [O)...numbers [count-1]. The number returned is the number of slices created. For example if count is 6, numbers might contain 5, 2, -143, 43, 5, and 6. The array sizes contains an array of integers that add up to count, for example it might contain 4 and 2 (adding up to 6). Your job is to create a bunch of dynamic arrays (2 in this case, since sizes has 2 elements) of sizes sizes [0], sizes[1] etc. and fill them with the numbers in numbers. So, for example, in the case above, you might fill memory slices with two dynamic addresses (say 1024 and 2048) and if we go to those memory locations, we would find 4 ints in a row at 1024 (5, 2, -143, 43), and the other 2 would be @2048. The memory goes into the 4th parameter, memorySlices (). The number returned is the number of slices created, 2. [Step 2): You are to write cleanup SeparateMemory. Given an array of pointers and a count (the size of the array, basically number of pointers), clean up the memory. A hint: The tests will run a small test (the one above) and a big, random test. One approach is to write your code specifically for the small test, then remove all repetition (use loops), and finally look at how you can generalize it, removing the hardcoded values for things in your parameter. You will be writing two methods: int make SeparateMemory (int * numbers, int * sizes, int count, int* memorySlices[]); and void cleanupSeparateMemory(int *memoryslices[], int count); We'll go through these one-by-one. [Step 1]: You are to write make SeparateMemory(). We'll use the inclassTestsSimple () test case to explain it. The function is called with an array (numbers) that contains count integers, numbers [O)...numbers [count-1]. The number returned is the number of slices created. For example if count is 6, numbers might contain 5, 2, -143, 43, 5, and 6. The array sizes contains an array of integers that add up to count, for example it might contain 4 and 2 (adding up to 6). Your job is to create a bunch of dynamic arrays (2 in this case, since sizes has 2 elements) of sizes sizes [0], sizes[1] etc. and fill them with the numbers in numbers. So, for example, in the case above, you might fill memory slices with two dynamic addresses (say 1024 and 2048) and if we go to those memory locations, we would find 4 ints in a row at 1024 (5, 2, -143, 43), and the other 2 would be @2048. The memory goes into the 4th parameter, memorySlices (). The number returned is the number of slices created, 2. [Step 2): You are to write cleanup SeparateMemory. Given an array of pointers and a count (the size of the array, basically number of pointers), clean up the memory. A hint: The tests will run a small test (the one above) and a big, random test. One approach is to write your code specifically for the small test, then remove all repetition (use loops), and finally look at how you can generalize it, removing the hardcoded values for things in your parameter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!