Question
Design an algorithm that will sort and merge two lists of integer values. The program will read the two integer lists from two different files
Design an algorithm that will sort and merge two lists of integer values.
- The program will read the two integer lists from two different files. Make sure there are not any duplicate values within the same file. However, the same values can be in both files.
- The program will use two arrays, one to store each list of integers. Note: This problem can be solved with two arrays. Do not use more than two arrays in your solution.
- The number of values in the files can vary. However, the program should not read more than twenty integer values.
- Display a welcome message and then prompt the user for the two input filenames and an output filename. Display error message(s) if you cannot open any of the files.
- If all of the files open successfully, then perform the following:
- Read the files and store the values in the arrays.
- Sort each array so the values are in ascending order (low-to-high).
- Using both arrays, write a single list of numbers in ascending order to the output file. Do not write duplicate values to the output file. Display a message that the list was successfully created.
- Close all the files before the program exits.
- Your program should use the following functions listed in the table below. Do not change the assigned tasks of the functions, and do not add, delete, or change the functions parameter variables. In addition, the parameters listed in red, are passed by-reference. *Note: Arrays are always passed by-reference.
- You can create any additional functions that you feel are helpful.
Function Prototypes and Tasks |
void displayProgramInfo(); Displays the program welcome message, program name, program information, etc. This function is called at the beginning of the main function. |
int readData(ifstream& inFile, int numData[], int size); Reads an input file and copies the list of integers into the numData array. The size parameter is the size of the array. Returns the number of values read from the file. This function is called from main. |
void sortData(int numData[], int size); Sorts the numData array into ascending order. The size parameter is the size of the array. This function is called from main. |
void writeData(ofstream& outFile, const int numData1[],const int numData2[], int size1, int size2); Writes the merged list of integers to the output file. This function is also called from main. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started