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 user-entered 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: 6
Lets initialize elements of array with user-entered data
Enter an integer: 1
Enter an integer: 2
Enter an integer: 3
Enter an integer: 4
Enter an integer: 5
Enter an integer: 6
Now writing the elements to a file.
Reading from the file, the elements of the array are: 123456
The elements of the array after reallocation are: 123
Would you like to enter another array? Y
Enter the number of elements in the array: 10
Lets initialize elements of array with user-entered data
Enter an integer: 10
Enter an integer: 20
Enter an integer: 30
Enter an integer: 40
Enter an integer: 50
Enter an integer: 60
Enter an integer: 70
Enter an integer: 80
Enter an integer: 90
Enter an integer: 100
Now writing the elements to a file.
Reading from the file, the elements of the array are: 102030405060708090100
The elements of the array after reallocation are: 1020304050
Would you like to enter another array? N
...Program finished with exit code 0
Press ENTER to exit console.

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 Programming Questions!