Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8)Array/File Functions Write a function named arrayToFile. The function should a

ID: 3643970 • Letter: 8

Question

8)Array/File Functions

Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file.

Write another function named fileToArray. This function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, read its contents into the array, and then close the file.

Write a complete program that demonstrates these functions by using the arrayToFile function to write an array to a file, and then using the fileToArray function to read from the same file. After the data is read from the file into the array, display the array

Explanation / Answer

#include #include using namespace std; // constant variables const int ARRAY_SIZE = 10; const int NAME_SIZE = 20; // function prototypes void arrayToFile(char[], int[], int); void fileToArray(char[], int[], int); int main() { int arrayContents[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int arrayContents2[ARRAY_SIZE]; int* intPointer2; int* intPointer; intPointer = arrayContents; intPointer2 = arrayContents2; char fileName[NAME_SIZE]; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote