You are given a C++ source file (Program6_Skeleton.cpp) with five missing/incomp
ID: 3647448 • Letter: Y
Question
You are given a C++ source file (Program6_Skeleton.cpp) with five missing/incomplete statements. Your task is to complete the code in this file such that it runs successfully. You are to replace all underlines with your code. You are also given two input files (oldmast.txt and trans.txt) and one output file (newmast.txt). The two input files contain data; the output file is empty. If your run is successful, the output file will contain the data shown in the sample output screen below.
oldmast.txt - 100 Ajax Orange 543.89 300 Sue Green 22.88 400 Clint White -6.32 500 Aias Blue 888.71 700 Tom Black 76.09 900 Marisal Pink 100.55
trans.txt - 100 134.17 300 627.19 400 1000.54 445 55.55 500 7.09 700 -99.66 900 100.00
Program skeleton - // Program 6: Chapter 8 Exercise 8.7 // This is not a full programming exercise. // Your job is to insert the missing five statements in the locations indicated below, // get the program to produce the results shown in the assignment sheet. #include #include #include #include #include // exit function prototype using namespace std; void printOutput( ofstream&, int, string, string, double ); // prototype int main() { int masterAccount; // holds account from old master file int transactionAccount; // holds account from transactions file double masterBalance; // holds balance from old master file double transactionBalance; // holds balance from transactions file string masterFirstName; // first name from master file string masterLastName; // last name from master file // file streams for input and output files (two IN/one OUT...complete the three statements below: ifstream _____________________________; // delete underlines when inserting your code ifstream _____________________________; ofstream _____________________________; // terminate application if old master file cannot be opened if ( !inOldMaster ) { cerr << "Unable to open oldmast.txt "; exit( 1 ); } // end if // terminate application if transactions file cannot be opened if ( !inTransaction ) { cerr << "Unable to open trans.txt "; exit( 1 ); } // end if // terminate application if new master file cannot be opened if ( !outNewMaster ) { cerr << "Unable to open newmast.txt "; exit( 1 ); } // end if // display account currently being processed.....insert one statement here cout << "Processing... "; ______________________________________________; // delete underline when inserting your code // read from master file until end of transactions file reached while ( !inTransaction.eof() ) { inOldMaster >> masterAccount >> masterFirstName >> masterLastName >> masterBalance; // display accounts from master file until // number of new account is reached..........insert two less than conditions that need to be met here while ( masterAccount < ____________________ && ______________________) // delete underlines when inserting your code here { printOutput( outNewMaster, masterAccount, masterFirstName, masterLastName, masterBalance ); inOldMaster >> masterAccount >> masterFirstName >> masterLastName >> masterBalance; } // end while // tell user if account from transactions file does not match // account from master file if ( masterAccount > transactionAccount ) { cout << "Unmatched transaction record for account " << transactionAccount << ' '; // get account and balance from transactions file inTransaction >> transactionAccount >> transactionBalance; } // end if // if matching account found, update balance and output account info if ( masterAccount == transactionAccount ) { masterBalance += transactionBalance; printOutput( outNewMaster, masterAccount, masterFirstName, masterLastName, masterBalance ); } // end if // get next account and balance from transactions file inTransaction >> transactionAccount >> transactionBalance; } // end 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 output void printOutput( ofstream &oRef, int mAccount, string mfName, string mlName, double mBalance ) { // set output format cout << fixed << showpoint; oRef << fixed << showpoint; // display account number, name and balance oRef << mAccount << ' ' << mfName << ' ' << mlName << ' ' << setprecision( 2 ) << mBalance << ' '; cout << mAccount << ' ' << mfName << ' ' << mlName << ' ' << setprecision( 2 ) << mBalance << ' '; } // end function printOutput
The program must run once
Explanation / Answer
please rate - thanks
sample run
besides the fact that you posted a mess the program has bugs. I've highlighed my corrections for those.
// Program 6: Chapter 8 Exercise 8.7
// This is not a full programming exercise.
// Your job is to insert the missing five statements in the locations indicated below,
// get the program to produce the results shown in the assignment sheet.
#include <iostream>
#include <fstream>
#include <iomanip>
// exit function prototype
using namespace std;
void printOutput( ofstream&, int, string, string, double );
// prototype
int main()
{ int masterAccount;
// holds account from old master file
int transactionAccount;
// holds account from transactions file
double masterBalance;
// holds balance from old master file
double transactionBalance;
// holds balance from transactions file
string masterFirstName;
// first name from master file
string masterLastName;
// last name from master file
// file streams for input and output files (two IN/one OUT...complete the three statements below:
ifstream inOldMaster;
// delete underlines when inserting your code
ifstream inTransaction;
ofstream outNewMaster;
//files never opened
inTransaction.open("trans.txt");
inOldMaster.open("oldMast.txt");
outNewMaster.open("newMast.txt");
// terminate application if old master file cannot be opened
if ( !inOldMaster )
{ cerr << "Unable to open oldmast.txt ";
exit( 1 ); }
// end if
// terminate application if transactions file cannot be opened
if ( !inTransaction )
{ cerr << "Unable to open trans.txt "; exit( 1 ); }
// end if
// terminate application if new master file cannot be opened
if ( !outNewMaster ) { cerr << "Unable to open newmast.txt "; exit( 1 ); }
// end if
// display account currently being processed.....insert one statement here
cout << "Processing... ";
// delete underline when inserting your code
// read from master file until end of transactions file reached
//transaction information never initioalized before being used
inTransaction >> transactionAccount >> transactionBalance;
while ( !inTransaction.eof() )
{ inOldMaster >> masterAccount >> masterFirstName >> masterLastName >> masterBalance;
// display accounts from master file until
// number of new account is reached..........insert two less than conditions that need to be met here
//only 1 needed
while ( masterAccount < transactionAccount )
// delete underlines when inserting your code here
{ printOutput( outNewMaster, masterAccount, masterFirstName, masterLastName, masterBalance );
inOldMaster >> masterAccount >> masterFirstName >> masterLastName >> masterBalance;
}
// end while
// tell user if account from transactions file does not match
// account from master file
//the way you have it, first time through transactionAccount not initialized
if ( masterAccount > transactionAccount )
{ cout << "Unmatched transaction record for account " << transactionAccount << ' ';
// get account and balance from transactions file
inTransaction >> transactionAccount >> transactionBalance; }
// end if
// if matching account found, update balance and output account info
if ( masterAccount == transactionAccount )
{ masterBalance += transactionBalance;
printOutput( outNewMaster, masterAccount, masterFirstName, masterLastName, masterBalance ); }
// end if
// get next account and balance from transactions file
inTransaction >> transactionAccount >> transactionBalance; }
// end while
// output remaining accounts to new master file
while ( !inOldMaster.eof() )
{ inOldMaster >> masterAccount >> masterFirstName >> masterLastName >> masterBalance;
printOutput( outNewMaster, masterAccount, masterFirstName, masterLastName, masterBalance ); }
// end while
system("pause");
}
// end main
// function to display output
void printOutput( ofstream &oRef, int mAccount, string mfName, string mlName, double mBalance )
{ // set output format
cout << fixed << showpoint; oRef << fixed << showpoint;
// display account number, name and balance
oRef << mAccount << ' ' << mfName << ' ' << mlName
<< ' ' << setprecision( 2 ) << mBalance << ' '; cout << mAccount
<< ' ' << mfName << ' ' << mlName << ' ' << setprecision( 2 ) << mBalance << ' '; }
// end function printOutput
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.