Assignment: Write a program that merges the numbers in two files and writes all the numbers into a third file. your program takes input from two different files and writes it output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to largest. after the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. your program should define a function that is called with the two input - file streams and the out - put file stream as three arguments.
Okay, here is my code.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int list1[25]; //array for the first list
int list2[25]; //array for the second list
int i;
fstream input1; //declaring the two files that data is coming from
fstream input2;
//fstream outputFile;
input1.open("MERGER1.dat");
input2.open("MERGER2.dat");
//outputFile.open("output.dat");
i = 0;
while(!input1.eof()) //.eof means end of file and this collects data from the file while it is not the end of file
{
input1 >> list1[i];
i++; //used to increment the array counter
}
for(int i = 0; i < 25; i++) //outputs the numbers from the file to check that they were inputted correctly
{
if(list1[i] > 0)
cout << list1[i] << " ";
}
cout << endl;
i = 0;
while(!input2.eof()) //same as above but for the second list
{
input2 >> list2[i];
i++;
}
cout << endl;
for(int i = 0; i < 25; i++)//same as about
{
if(list2[i] > 0)
cout << list2[i] << " ";
}
cout << endl;
I'm confused about where the two files (which contain lists of numbers) need to be placed in order to be read and if they need to be renamed or something. If anyone can tell me exactly what needs to be in this program, that would help immensely.