Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access with AI-Powered 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