//******************************************************************* // // Program: Chequebook // // Author: yourname here // // Description: Gets monthly transactions from a transaction file; // updates account; // reports the results on cheque.out // // Date: November 2x, 1999 // // Course Information: CS 1711, Lab 7 // // Filename: cheque.cpp // //******************************************************************* #include // MORE IS NEEDED HERE // Function: initFiles // // Purpose: opens the stream from file trans.dat, and to write // to cheque.out reports on error // and reports `Files open...' to terminal on success // // Parameters: transtr - the file of transactions // outstr - the output file void openFiles(ifstream& transtr, ofstream& outstr); // Function: firstLine // // Purpose: reads the first line of input. // // Parameters: transtr - the file of transactions // month - month of transactions // numtrans - number this month // init_balance - starting balance void firstLine(ifstream& transtr, int& month, int& numtrans, double& init_balance); // Function: getTransaction // // Purpose: reads a transaction line from the input // // Parameters: transtr - the file of transactions // transType - debit or credit // date - of this transaction // amount - of this transaction // closes the stream files and reports to the user void closeFiles(ifstream& transtr, ofstream& outstr); // You know what this function does!! void printMonth(ofstream& outstr, int m); void main() { ifstream transtr; ofstream outstr; int i, numtrans, month; double balance; Transaction currTrans; openFiles(transtr,outstr); firstLine(transtr,month,numtrans,balance); // NOW DECLARE AN ACCOUNT WITH THE BALANCE GIVEN ON THE FIRST DAY OF THE MONTH // We put the month on outstr.... printMonth(outstr,month); // and write the transactions after updating the account... for (i=1; i <= numtrans; i = i + 1) { // GET A TRANSACTION FROM transtr // UPDATE THE ACCOUNT // WRITE THE TRANSACTION TO outstr USING ACCESS FUNCTIONS FOR THE TRANSACTION AND ACCOUNT // ADD APPROPRIATE FORMATTING } // WRITE THE CLOSING LINE TO outsr // then finish up closeFiles(transtr,outstr); } void openFiles(ifstream& transtr, ofstream& outstr) { transtr.open("trans.dat"); outstr.open("cheque.out"); cout << "Processing complete..." << endl; } void firstLine(ifstream& transtr, int& month, int& numTrans, double& initBalance) { transtr >> month >> numTrans >> initBalance; } void closeFiles(ifstream& transtr, ofstream& outstr) { transtr.close(); outstr.close(); } void printMonth(ofstream& outstr, int m) { switch(m) { case 1: outstr << "January" << endl; break; case 2: outstr << "February" << endl; break; case 3: outstr << "March" << endl; break; case 4: outstr << "April" << endl; break; case 5: outstr << "May" << endl; break; case 6: outstr << "June" << endl; break; case 7: outstr << "July" << endl; break; case 8: outstr << "August" << endl; break; case 9: outstr << "September" << endl; break; case 10: outstr << "October" << endl; break; case 11: outstr << "November" << endl; break; case 12: outstr << "December" << endl; break; } }