I need to know how to input the following code into the complier for C++ code. I
ID: 3852006 • Letter: I
Question
I need to know how to input the following code into the complier for C++ code. It is for PLD Chapter 7 question #6.
// Start
// Declarations
// InputFile masterFile;
// InputFile transactionFile;
// OutputFile newMasterFile;
// num mClientNumber, mtotalClientCost, tClientNumber, titemClientCost
// string mClientfName, mClientlName
// output "Master File Updating Starting"
// open masterFile "Master.rtf"
// open transactionFile "Transaction.rtf"
// open newMasterFile "newMaster.rtf"
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// read tClientNumber, titemClientCost from transactionFile
// while ( transactionFile not EOF )
// while (( masterFile not EOF) and (mClientNumber < tClientNumber))
// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// endwhile
// if (masterFile is EOF)
// output "Error Client ID: ", tClientNumber, " not in Master File."
// else if (mClientNumber == tClientNumber) then
// mtotalClientCost = mtotalClientCost + titemClientCost
// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// else if (mClientNumber > tClientNumber) then
// output "Error Client ID: ", tClientNumber, " not in Master File."
// endif
// read tClientNumber, titemClientCost from transactionFile
// endwhile
// while (masterFile not EOF)
// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// endwhile
// output "Master File Updating Complete"
// close masterFile
// close transactionFile
// close newMasterFile
// Stop
Explanation / Answer
Answer for the given Question:
converted into c++ pogram in below code as given in the problem statement. Please provide the file paths and specify the how the file lines are seperated. Please make sure those things
#include<iostream>
#include<fstream>
#include<ostream>
using namespace std;
int main()
{
ifstream masterFile;
ifstream transactionFile;
ofstream newMasterFile;
int mClientNumber, mtotalClientCost, tClientNumber, titemClientCost;
string mClientfName, mClientlName;
cout<< "Master File Updating Starting"<<endl;
masterFile.open("Master.rtf");
transactionFile.open("Transaction.rtf");
newMasterFile.open("newMaster.rtf");
cout<<"Read the mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile"<<endl;
cout<<"Read the tClientNumber, titemClientCost from transactionFile"<<endl;
masterFile>>mClientNumber>>mClientfName>>mClientlName>>mtotalClientCost;
transactionFile>>tClientNumber>>titemClientCost;
while ( !transactionFile.eof())
{
while (( !masterFile.eof()) and (mClientNumber < tClientNumber))
{
newMasterFile<<mClientNumber<<mClientfName<<mClientlName<<mtotalClientCost;
masterFile>>mClientNumber>>mClientfName>>mClientlName>>mtotalClientCost;
}
if (!masterFile.eof())
{
masterFile<<tClientNumber;
}
else if (mClientNumber == tClientNumber)
{
mtotalClientCost = mtotalClientCost + titemClientCost
newMasterFile<<mClientNumber<<mClientfName<<mClientlName<<mtotalClientCost<<endl;
masterFile>>mClientNumber>>mClientfName>>mClientlName>>mtotalClientCost;
}
else if (mClientNumber > tClientNumber)
{
masterFile<<tClientNumber;
}
transactionFile>>tClientNumber>>titemClientCost;
}
while (!masterFile.eof())
{
newMasterFile<<mClientNumber<<mClientfName<<mClientlName<<mtotalClientCost;
masterFile>> mClientNumber>>mClientfName>>mClientlName>>mtotalClientCost;
}
masterFile.close();
transactionFile.close();
newMasterFile.close();
}