#define ALLOW_INSTRUCTOR_CODE /*************************************************************************** *************************************************************************** ****** BEFORE BEGINNING OR TURNING IN THIS EXERCISE IT IS EXTREMELY ****** ****** IMPORTANT THAT YOU READ, FULLY UNDERSTAND, AND ADHERE TO THE ****** ****** REQUIREMENTS STATED IN THE DOCUMENT TITLED, "ASSIGNMENT ****** ****** SUBMISSION REQUIREMENTS", DOWNLOADABLE FROM THE COURSE WEB ****** ****** SITE. ****** *************************************************************************** **************************************************************************/ /*************************************************************************** ************* C/C++ Programming 2: Assignment 8 - Exercise 1 ************* ******** BEGIN EXERCISE REQUIREMENT - THIS MUST BE A "C++" PROGRAM ******** *************************************************************************** (5 points) Write functions OpenFiles and MergeAndDisplay: OpenFiles syntax: ifstream *OpenFiles(char * const fileNames[], size_t count); Parameters: fileNames - a pointer to the first element in an array representing the names of text files to be opened. The array has the underlying format: char *fileNames[] = { "fileA", "fileB", etc. }; count - the number of elements in Synopsis: Dynamically creates an array of ifstream objects then uses them to open the files named in , in order. All opens are in the read-only text mode. If any open fails all previously opened files are closed, the dynamic allocation is deleted, an error message is output to cerr, and the program is terminated with an error exit code. If is zero an error message is output to cerr and the program is terminated with an error exit code. Return: a pointer to the first entry in the ifstream array if is non-zero and all opens succeed; otherwise, the function does not return. MergeAndDisplay syntax: void MergeAndDisplay(ifstream files[], size_t count); Parameters: files - a pointer to the first element in an array of ifstream objects, where each object represents a text file open in the text mode for reading. count - the number of elements in the array in Synopsis: Proceeding in order from the first file specified in , the first line in each is read and displayed, followed by the second line in each, follow by the third, etc. When the end of any file is reached that file is closed and the process continues using only the remaining open files, until all files have finally been closed. Empty lines are displayed as empty lines. Empty files are simply closed and ignored. Return: void * Specify the file name(s) on the command line. * Both functions must handle any arbitrary number of files. * Assume no line will contain more than 511 characters. * Do not attempt to store the entire contents of any file. * Do not attempt to read a file after reaching its EOF. * Use files "mFile1.txt" through "mFile5.txt", downloaded from the course web site to test your program with the following two command lines: mFile1.txt mFile2.txt mFile3.txt mFile4.txt mFile5.txt mFile3.txt mFile2.txt mFile1.txt Example: If the command line specifies: f1 f2 f3 and those files contain the following text: File Name: f1 f2 f3 Line 1: Hello from Bah bah black Now is Line 2: the sheep the Line 3: other side of time for all Line 4: good men and Line 5: the universe the display would be: Hello from Bah bah black Now is the sheep the other side of time for all good men and the universe Hint: * Place all input test files in the appropriate default location described in the "FILE LOCATION QUESTIONS AND ANSWERS" section of the "ASSIGNMENT SUBMISSION REQUIREMENTS" document. *************************************************************************** ************************ END EXERCISE REQUIREMENT ************************* **************************************************************************/ /*************************************************************************** * BEFORE PRINTING THIS ASSIGNMENT TO TURN IN, DELETE THIS COMMENT AND * EVERYTHING ABOVE IT. **************************************************************************/ /* * TODO: * REPLACE THIS COMMENT WITH YOUR TITLE BLOCK. */ /* * TODO: * REPLACE THIS COMMENT WITH YOUR C++ CODE, PLUS ANYTHING NECESSARY TO * SUPPORT MY TEST CODE BELOW. DO NOT INCLUDE ANY UNNEEDED HEADER FILES! */ /*************************************************************************** * BEFORE PRINTING THIS ASSIGNMENT TO TURN IN, DELETE THIS COMMENT AND * EVERYTHING BELOW IT. **************************************************************************/ /* ***** Change nothing below this comment without instructor permission. **** * Everything that follows was written to help test/verify your code. You * do not need to understand the details of my code to write yours! */ #ifdef ALLOW_INSTRUCTOR_CODE int main(int argc, char *argv[]) { ifstream *files = OpenFiles(&argv[1], size_t(argc - 1)); MergeAndDisplay(files, size_t(argc - 1)); delete[] files; return EXIT_SUCCESS; } #endif