Question: Write a function named createArray ( ) that creates a dynamic array of 1 0 0 0 integers. The calling function must supply a variable

Write a function named createArray() that creates a dynamic array of 1000 integers. The calling function must supply a variable for the length which is received as a pointer and is assigned the value of 1000 in the createArray() function. It is best to define this value as a constant outside the function. Initialize the array with random numbers in the range between 0 and 999 inclusive. Assign the callers pointer parameter to the length of the array and return a pointer to the dynamically created array.
Write a second function named writeBinary() that takes a parameter pointer to an integer array and its length as a second parameter. Open an output file binary.dat as binary and write to it the length of the array. Then write each integer in the array to the file and close the file.
Write a third function named readBinary() that opens the binary.dat file in binary mode. Its only parameter should be a reference to an integer in the main code which will store the length of the returned array. Read the first value from the file which is the length of an array to create. Assign this value to the reference parameter so the callers variable will be updated. Create a new dynamic array of integers using the length value for its size. In a loop, read each number from the file and save the value in the array, increasing the index for each. Return a pointer to the array from the function.
Finally, write a main function that calls the array creation function, supplying the address of a local integer variable as a parameter representing the length of the array. Receive back a pointer to the array with the length variable updated. Call the writeBinary() function passing a pointer to the array as the first parameter and its length as a second parameter. After it returns, delete the array created in the first function and set the integer pointer to nullptr.
Call the readBinary() function passing a reference to a local integer variable which will be the array length. The third function should return a pointer to a new array and update the variable with the length. Write a loop to iterate over each value in the array and print out its value separated by a space. Delete the dynamic array and terminate the program.
Use these function headers:
Use these function headers:

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!