Question: Write a C++ console program that demonstrates the resizing of an array. Arrays are fixed in size, but we can resize them using a work-around.

 Write a C++ console program that demonstrates the resizing of an

Write a C++ console program that demonstrates the resizing of an array. Arrays are fixed in size, but we can resize them using a work-around. First we allocate a new, larger memory space, and then copy the old array values into the new memory. Write a function named increaseSize that defines parameters for an array, it's size and it's new size. The return value is a pointer to the newly allocated array. The function must validate that the new size is larger than the old size and return NULL if it is not. Don't forget to free the old memory after copying over the values In main, begin by creating an array of size 10 and filling it with random values from the range [1, 10]. Next, utilize the increaseSize function to receive back an array of size 20. Fill the rest of the array with random values from a similar range and then print out the average of the 20 elements. Note:.Do not use square bracket notation [ in this program, except for when using the new operator. Use only pointer notation to manipulate the array

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!