(File Matching Enhancement) It’s common to have several transaction records with the same record key, because a particular customer might make several purchases and cash payments during a business period. Rewrite your accounts receivable file-matching program of Exercise 8.7 to provide for the possibility of handling several transaction records with the same record key. Modify the test data of
Exercise 8.8 to include the following additional transaction records:
![14894|307x148](upload://53BiqZS2lvNjWzPaVFlu7Vjvt2u.png)
What will be an ideal response?
```
#include
#include
#include
#include
#include
using namespace std;
void printOutput( ofstream &, int, string, string, double );
int main()
{
// variables hold account information from input files
int masterAccount;
int transactionAccount;
double masterBalance;
double transactionBalance;
string masterFirstName;
string masterLastName;
// create file streams and open files
ifstream inOldmaster( "oldmast.txt" );
ifstream inTransaction( "trans.txt" );
ofstream outNewmaster( "newmast.txt" );
// terminate program if input master file cannot be opened
if ( !inOldmaster )
{
cerr << "Unable to open oldmast.txt\n";
exit( 1 );
} // end if
// terminate program if input transaction file cannot be opened
if ( !inTransaction )
{
cerr << "Unable to open trans.txt\n";
exit( 1 );
} // end if
// terminate program if output master file cannot be opened
if ( !outNewmaster )
{
cerr << "Unable to open newmast.txt\n";
exit( 1 );
} // end file
cout << "Processing....\n";
// get first transaction from input file
inTransaction >> transactionAccount >> transactionBalance;
// continue until end of transaction file is reached
while ( !inTransaction.eof() )
{
// get account information from input master file
inOldmaster >> masterAccount >> masterFirstName >> masterLastName
>> masterBalance;
// write master accounts to output master file until first account
// that made a transaction is reached
while ( masterAccount < transactionAccount && !inOldmaster.eof() )
{
printOutput( outNewmaster, masterAccount, masterFirstName,
masterLastName, masterBalance );
inOldmaster >> masterAccount >> masterFirstName >> masterLastName
>> masterBalance;
} // end inner while
// if transaction account does not have a matching input file
// inform user get next transaction information
if ( masterAccount > transactionAccount )
{
cout << "Unmatched transaction record for account "
<< transactionAccount << '\n';
inTransaction >> transactionAccount >> transactionBalance;
} // end if
// if transaction account does not have a matching input file
// inform user get next transaction information
else if ( masterAccount < transactionAccount )
{
cout << "Unmatched transaction record for account "
<< transactionAccount << '\n';
inTransaction >> transactionAccount >> transactionBalance;
} // end if
// process all transactions made by a master account holder
while ( masterAccount == transactionAccount &&
!inTransaction.eof() )
{
masterBalance += transactionBalance;
inTransaction >> transactionAccount >> transactionBalance;
} // end inner while
// display account information
printOutput( outNewmaster, masterAccount, masterFirstName,
masterLastName, masterBalance );
} // end outer while
// output remaining accounts to new master file
while ( !inOldmaster.eof() )
{
inOldmaster >> masterAccount >> masterFirstName
>> masterLastName >> masterBalance;
printOutput( outNewmaster, masterAccount, masterFirstName,
masterLastName, masterBalance );
} // end while
} // end main
// function to display account information
void printOutput( ofstream &oRef, int mAccount, string mfName,
string mlName, double mBalance )
{
// set output formats and display account information
cout << showpoint << fixed;
oRef << showpoint << fixed;
oRef << mAccount << ' ' << mfName << ' ' << mlName << ' '
<< setprecision( 2 ) << mBalance << '\n';
cout << mAccount << ' ' << mfName << ' ' << mlName << ' '
<< setprecision( 2 ) << mBalance << '\n';
cout << showpoint << fixed;
} // end function printOutput
```
Processing....
100 Alan Jones 375.31
300 Mary Smith 173.19
500 Sam Sharp 100.56
700 Suzy Green 150.26
Contents of oldmast.txt
100 Alan Jones 348.17
300 Mary Smith 27.19
500 Sam Sharp 0.00
700 Suzy Green -14.22
Contents of trans.txt
100 27.14
300 62.11
300 83.89
500 100.56
700 82.17
700 80.78
700 1.53
Contents of newmast.txt
100 Alan Jones 375.31
300 Mary Smith 173.19
500 Sam Sharp 100.56
700 Suzy Green 150.26
You might also like to view...
In what-if analysis, each set of assumptions is called a(n) ________
A) analysis B) range C) value set D) scenario
Which of the following commands is used on a UNIX host to generate information about each router hop along the path from a source to a destination?
a. ping -t b. tracert c. ping -r d. traceroute