Need this in C++
// Start
// Declarations
// InputFile inFile1;
// InputFile inFile2;
// OutputFile outFile1
;// num mClientNumber, fClientNumber
// string mClientName, fClientName
// bool atLeastOneFileNotAtEnd = true
// bool inFile1Written = false
// bool inFile2Written = false
// output "File merge processing starting"
// open inFile1 "MaleClients.rtf"
// open inFile2 "FemaleClients.rtf"
// open outFile1 "MergedClients.rtf"
// read mClientNumber and mClientName from inFile1
// read fClientNumber and fClientName from inFile2
// while ( atLeastOneFileNotAtEnd == true )
// if (inFile1 is EOF)// if (inFile2Written == false)
// output fClientNumber, fClientName to Outputfile
// inFile2Written = true// endif// else if (inFile2 is EOF)
// if (inFile1Written == false)
// output mClientNumber, mClientName to Outputfile
// inFile1Written = true
// endif
// else if (mClientNumber < fClientNumber)
// output mClientNumber, mClientName to Outputfile
// inFile1Written = true
// else
// output fClientNumber, fClientName to Outputfile
// inFile2Written = true
// endif
//
//
// if ((inFile1 not EOF) AND (inFile1Written == true))
// read mClientNumber and mClientName from inFile1
// inFile1Written = false
// endif
// if ((inFile2 not EOF) AND (inFile2Written == true))
// read fClientNumber and fClientName from inFile2
// inFile2Written = false
// endif
// if ((inFile is EOF) AND (inFile2 is EOF))
// atLeastOneFileNotAtEnd = false
// endif
// endwhile
// close inFile1
// close inFile2
// close outFile1
// output "Merging Complete"
// Stop
C++ PROGRAM
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()//main
{
ifstream inFile1;// InputFile inFile1
ifstream inFile2;// InputFile inFile2
ofstream outFile1;// OutputFile outFile1
int mClientNumber, fClientNumber;// num mClientNumber,
fClientNumber
string mClientName, fClientName;// string mClientName,
fClientName
bool atLeastOneFileNotAtEnd = true;
bool inFile1Written = false;
bool inFile2Written = false;
cout<<"File merge processing starting";
inFile1.open("MaleClients.rtf");
inFile2.open("FemaleClients.rtf");
outFile1.open ("MergedClients.rtf");
inFile1 >> mClientNumber; //Input
inFile1 >> mClientName;
inFile2 >> fClientNumber;
inFile2 >> fClientName;
while ( atLeastOneFileNotAtEnd == true ){//while loop
if(inFile1.eof()){
if (inFile2Written == false){
outFile1 << fClientNumber <<"
"<<fClientName<<"\n";
inFile2Written = true;
}
}
else if(inFile2.eof()){
if (inFile1Written == false){
outFile1 << mClientNumber <<"
"<<mClientName<<"\n";
inFile1Written = true;
}
}
else if (mClientNumber < fClientNumber){
outFile1 << mClientNumber <<"
"<<mClientName<<"\n";
inFile1Written = true;
}
else{
outFile1 << fClientNumber <<"
"<<fClientName<<"\n";
inFile2Written = true;
}
if ((!inFile1.eof()) && (inFile1Written == true)){
inFile1 >> mClientNumber;
inFile1 >> mClientName;
inFile1Written = false;
}
if ((!inFile2.eof()) && (inFile2Written == true)){
inFile2 >> fClientNumber;
inFile2 >> fClientName;
inFile2Written = false;
}
if ((inFile1.eof()) && (inFile2.eof())){
atLeastOneFileNotAtEnd = false;
}
}
inFile1.close(); //close
inFile2.close();
outFile1.close();
cout<<"\nMerging Complete";
return 0;
}
MaleClients.rtf
1 Harry
FemaleClients.rtf
3 Olivia
OUTPUT
Get Answers For Free
Most questions answered within 1 hours.