(File Matching Test Data) After writing the program of Exercise 8.7, write a simple pro- gram to create some test data for checking out the program. Use the following sample account data:
![14892|413x326](upload://e64l7QZyJpYg9gj0l1Oiv7rpH1d.png)
```
#include
#include
#include
#include
#include
using namespace std;
int main()
{
const int ITEMS = 4;
// account number
const int accountNumbers[ ITEMS ] = { 100, 300, 500, 700 };
// names of account holders
const string names[ ITEMS ] =
{ "Alan Jones", "Mary Smith", "Sam Sharp", "Suzy Green" };
// balances of account holders
const double balances[ ITEMS ] = { 348.17, 27.19, 0.00, -14.22 };
// account transactions
const double transactionAmounts[ ITEMS ] =
{ 27.14, 62.11, 100.56, 82.17 };
// intialize output streams and open output files
ofstream outOldMaster( "oldMast.txt" );
ofstream outTransaction( "trans.txt" );
// terminate program if master output file cannot be opened
if ( !outOldMaster )
{
cerr << "Unable to open oldmast.txt\n";
exit( 1 );
} // end if
// terminate application if output transactions file cannot be opened
if ( !outTransaction )
{
cerr << "Unable to open trans.txt\n";
exit( 1 );
} // end if
// write data to "oldmast.txt"
cout << fixed << showpoint << "Contents of \"oldmast.txt\":\n";
// create random master account balances and write to file
outOldMaster << fixed << showpoint;
for ( int i = 0; i < ITEMS; ++i )
{
outOldMaster << accountNumbers[ i ] << ' ' << names[ i ] << ' '
<< setprecision( 2 ) << balances[ i ] << '\n';
cout << accountNumbers[ i ] << ' ' << names[ i ] << ' '
<< setprecision( 2 ) << balances[ i ] << '\n';
} // end for
// write data to "trans.txt"
cout << "\nContents of \"trans.txt\":\n";
outTransaction << fixed << showpoint;
// create random transactions and write to file
for ( int i = 0; i < ITEMS; ++i )
{
outTransaction << accountNumbers[ i ] << ' ' << setprecision( 2 )
<< transactionAmounts[ i ] << '\n';
cout << accountNumbers[ i ] << ' ' << setprecision( 2 )
<< transactionAmounts[ i ] << '\n';
} // end for
} // end main
```
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
500 100.56
700 82.17
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
500 100.56
700 82.17
You might also like to view...
A crosstab query can be used if you want to calculate statistics and group the results by two sets of data
Indicate whether the statement is true or false
Choose the item below that is not a valid value for the input element's type attribute
a. radio b. url c. e-mail d. text