#include #include #include using namespace std; void OpenTheFile(ifstream & aFile); float GetBalance(ifstream & aFile); void GetATransaction(ifstream & aFile, float & amount, char & type); void ProcessTransaction(char type, float amount, float & balance); int main() { ifstream theFile; float totalBalance; char transType{'a'}; float transAmount{0.00}; OpenTheFile(theFile); totalBalance = GetBalance(theFile); GetATransaction(theFile, transAmount, transType); while( theFile) { // procss the transaction cout << "Got a transaction of " << transType << " " << transAmount << endl; ProcessTransaction(transType, transAmount, totalBalance); GetATransaction(theFile, transAmount, transType); } theFile.close(); cout << "The final balance is $" << totalBalance << endl; return 0; } void GetATransaction(ifstream & aFile, float & amount, char & type){ int transactionNumber; string date; char junk; aFile >> transactionNumber; aFile >> date; aFile >> type; aFile >> junk; aFile >> amount; } float GetBalance(ifstream & aFile){ char junk; float balance; // Get Balance // read the $ aFile >> junk; // read the balance aFile >> balance; // return the balance. return balance; } void OpenTheFile(ifstream & aFile){ // do // get the file name // open the file // while the file is not open aFile.open("finance.dep"); } void ProcessTransaction(char type, float amount, float & balance){ switch(type) { case 'D': balance += amount; break; case 'W': balance -= amount; break; default: cout << "Error in transaction type "<< type << endl; } }