Question: ( Dynamic Array Allocation ) Show me in steps how to Write a C + + program that dynamically allocates an array of integers. The
Dynamic Array Allocation Show me in steps how to Write a C program that dynamically allocates an array of integers. The size of the array should be input from a keyboard. The elements of the array should be assigned values input from the keyboard, and then stored to a file. Then read the elements from that file and display the array elements on the screen. Next reallocate the memory for the array to half of the current number of elements. Display the arrays remaining values to confirm they match the first half of the original arrays values.
Technology Requirements:
Prompt user to enter size of the array of integers to be dynamically created.
Use Calloc to dynamically allocate array.
Initialize elements of array with userentered data.
Write the array elements to a file.
Read the elements back into an array from the file and display the array elements on screen.
Reallocate to half the original size using realloc and sizeof.
Display array after cutting in half on the screen.
Loop to ask if user wants to enter another array.
If yes, loop to get size and repeat, else end the program.
Test Data:
This program dynamically allocates an array of integers.
Enter the number of elements in the array:
Lets initialize elements of array with userentered data
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Now writing the elements to a file.
Reading from the file, the elements of the array are:
The elements of the array after reallocation are:
Would you like to enter another array? Y
Enter the number of elements in the array:
Lets initialize elements of array with userentered data
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Enter an integer:
Now writing the elements to a file.
Reading from the file, the elements of the array are:
The elements of the array after reallocation are:
Would you like to enter another array? N
Program finished with exit code
Press ENTER to exit console.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
