For C++ Write a function named arrayToFile. The function should accept three arg
ID: 653218 • Letter: F
Question
For C++
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 the data from the same file. After the data are read from the file into the array, display the array
Explanation / Answer
# include # include # include using namespace std; const int SIZE = 10; bool arrayToFile(fstream&, int*, int); bool fileToArray(fstream&, int*, int); int main() { int arr[SIZE] = { 10, 8, 9, 7, 6, 4, 5, 3, 2, 1 }, arrTest[SIZE]; fstream file; if (arrayToFile(file, arr, SIZE)) { if (fileToArray(file, arr, SIZE)) { for (int n = 0; nRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.