#include #include #include using namespace std; void OpenTheFile(ifstream & aFile); float GetStartingBalance(ifstream & aFile); void GetTransaction(ifstream & aFile, char & type, float & amount); void ProcessTransaction(char type, float amount, float & balance); int main() { ifstream theFile; float balance{0}; float value; char transactionType; OpenTheFile(theFile); balance = GetStartingBalance(theFile); GetTransaction(theFile, transactionType, value); // while there are valid transactions while (theFile) { cout <<" Just got transaction " << transactionType << " " << value << endl; // Process the transaction ProcessTransaction(transactionType, value, balance); GetTransaction(theFile, transactionType, value); } theFile.close(); cout << "The final balance is $" << balance << endl; return 0; } void ProcessTransaction(char type, float amount, float & balance){ switch(type) { case 'D': balance += amount; break; case 'W': balance -= amount; break; default: cout << "There is an error in the transaction" << endl; } return; } void GetTransaction(ifstream & aFile, char & type, float & amount){ int tNumber; string date; char junk; // get the transaction number as an int aFile >> tNumber; // get the date as a string aFile >> date; // get the type as a char aFile >> type; // get the $ as a char aFile >> junk; // get the amount as a float. aFile >> amount; return; } float GetStartingBalance(ifstream & aFile){ char junk; float bal; // read in the $ // read in the balance // return the balance aFile >> junk; aFile >> bal; return bal; } void OpenTheFile(ifstream & aFile){ // do // get a file name // open the file // while the file is not open. aFile.open("finance.dep"); }