Please help
C++ only
It is suggested to use functions to comply with program modularization. Part of the task is read/write external files; two input files were provided (currentData.csv & newData.csv) with approximately 100 records. Your task is to create an application that will compare the two input files and write to three output files (toAdd.csv, toDel.csv & final.csv). The output files should contain only records according to the following criteria:
a. If a record in newData.cvs is not in currentData.cvs then new record should be written to toAdd.csv file
b. If a record in currentData.csv doesn’t exist in newData.csv then record should be written to toDel.csv file
c. Merge necessary files to obtain an updated version of new currentData.csv in such way that records in toAdd.csv and toDel.csv files are removed or added respectively to create a new version of currentData.csv file that you could name the file final.csv.
The suggested key field to be used for finding and comparing each file record is the ID field.
newData.csv:
https://docs.google.com/document/d/1nqdMz0D164gGVCBm_ega-QzaQwaUww4XxldcTwgkv8s/edit?usp=sharing
currentData.csv:
https://docs.google.com/document/d/1Fx-OIqRySvUxjSqfS_Wr2_a4OSYhlfCdMv_s-_yUY58/edit?usp=sharing
this is what i have so far:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream inFile1("newData");
ifstream inFile2("CurrentData");
ofstream outFile12("outdata12.csv");
if(!inFile1.is_open() || !inFile2.is_open())
{
cout << "ERROR READ: File Open" << '\n';
}
if(!outFile12.is_open())
{
cout << "ERROR WRITE: File Write" << '\n';
}
string firstname1;
string lastname1;
string ID1;
string email1;
string firstname2;
string lastname2;
string ID2;
string email2;
int i=0;
while(!inFile1.eof() && !inFile2.eof())
{ getline(inFile1,firstname1,',');
getline(inFile1,lastname1,',');
getline(inFile1,ID1,',');
getline(inFile1,email1,'\n');
getline(inFile2,firstname2,',');
getline(inFile2,lastname2,',');
getline(inFile2,ID2,',');
getline(inFile2,email2,'\n');
if( inFile1.eof() )
{ cout<<"EOF was found in file data1";
break;
} //Jumps to read EOF
if( inFile2.eof() )
{ cout<<"EOF was found in file data2";
break;
} //Jumps to read EOF
//if( inFile2.eof() ) break;
cout<< ".";
outFile12 <<"Record: " <<i++<<'\n';
outFile12 << "Name: "<<firstname1<< " "<<lastname1 << '\n';
outFile12 << "ID: "<<ID1 << '\n';
outFile12 << "Email: "<<email1 << '\n';
outFile12 << "-------------------" <<'\n';
outFile12 << "Name: "<<firstname2<< " "<<lastname2 << '\n';
outFile12 << "ID: "<<ID2 << '\n';
outFile12 << "Email: "<<email2 << '\n';
outFile12 << "-------------------" <<'\n';
}
inFile1.close();
inFile2.close();
outFile12.close();
}