#include // needed libraries #include // file handling library #include #include #include #include "bank.h" #include "bank2.h" Account x[ARRAYSIZE]; // create Account objects? Checking ch[ARRAYSIZE]; // create Account objects Savings sa[ARRAYSIZE]; // create Account objects Mmarket mm[ARRAYSIZE]; // create Account objects// driver, or call to driver void driver( void ) { inputOldMaster( ); inputDaily( ); } /************************************************************* ************************************************************** ** inputOldMaster * ** Gets input from c:\proj6\oldmast.dat file. * ** That is the old master file with yesterdays ending * ** balances for Fees Galore's 10 customers. * ** It fills the objects with data from oldmast.dat. * ** Nothing is received. * ** Just a zero is returned showing succesfull execution. * ************************************************************** **************************************************************/ int inputOldMaster (void) { // declaration of local variables int cnt = 0, // keeps count of item read success fullAcctNum, // main account number & type suffix acctNum, // just main account number acctType, tempAcctNum; // just the account type suffix float bal, // the account balance as in old file rate; // the interest rate //Account *p; // pointer // create objects of derived types /* !!!: Also, if at any time you should run into an invalid account number, right the account number and amount to an error file to be corrected and resubmitted at another time. (C:\proj6\errors.dat) */ // ifstream constructor opens file ifstream dataOld( "c:\\proj6\\oldmast.dat", ios::in ); if( !dataOld ) { cerr << "File could not be opened" << endl; exit( 1 ); } dataOld >> fullAcctNum >> bal >> rate; while( !dataOld.eof() ) { acctType = fullAcctNum % 10; acctNum = fullAcctNum / 10; rate = rate / 365; tempAcctNum = acctNum; switch( acctType ) { case 1: // set pointer, do checking { ch[cnt].set_acct_number( acctNum ); ch[cnt].set_balance( bal ); break; /* or { p = &Checking; p->set_acct_number( acctNum ); p->set_balance( bal ); break; } */ } case 2: // set pointer, do saving { sa[cnt].set_acct_number( acctNum ); sa[cnt].set_balance( bal ); sa[cnt].set_int_rate( rate ); break; /* or { p = &Savings; p-> } */ } case 3: // set pointer, do money market { mm[cnt].set_acct_number( acctNum ); mm[cnt].set_balance( bal ); mm[cnt].set_int_rate( rate ); break; /* or { p = &Mmarket; p-> } */ } default: // handle error "no such type" { // call to error handling // It opens file for append, and // puts this set of info there } } dataOld >> fullAcctNum >> bal >> rate; acctNum = fullAcctNum / 10; if (tempAcctNum != acctNum) { acctNum = tempAcctNum; cnt++; } } dataOld.close(); return (cnt - 1); } ////////////////////////////////////////////////////// /************************************************************* ************************************************************** ** Gets input from c:\proj6\dailytxn.dat file. ** ** This is the file with todays transactions. ** ** It fills the objects with data from dailytxn.dat. ** Or does it calculate and sum as it reads in data? I think dividing up tasks is better than trying to do everything at one time, but it may be easier to get info and sum it with each transaction. ** Nothing is received. ** ** Just a zero is returned showing succesfull execution. ** ************************************************************** **************************************************************/ int inputDaily (void) { // declaration of local variables int cnt = 0, // keeps count of item read success fullAcctNum, // main account number & type suffix acctNum, // just main account number acctType, tempAcctNum; // just the account type suffix //float tran, // the account transaction float bal, newBal, rate; //Account *p; // pointer /* !!!: Also, if at any time you should run into an invalid account number, right the account number and amount to an error file to be corrected and resubmitted at another time. (C:\proj6\errors.dat) */ // ifstream constructor opens file ifstream transactions( "c:\\proj6\\dailytxn.dat", ios::in ); if( !transactions ) { cerr << "File could not be opened" << endl; exit( 1 ); } transactions >> fullAcctNum >> bal; ofstream dataNew( "c:\\proj6\\newmast.dat", ios::out ); if( !dataNew ) { cerr << "File could not be opened" << endl; exit( 1 ); } while( !transactions.eof() ) { //if (fullAcctNum == 7996881) //cout << "Hello"; //cout << "While loop" << endl; acctType = fullAcctNum % 10; acctNum = fullAcctNum / 10; tempAcctNum = acctNum ; //if (acctNum == ch[cnt].get_acct_number() || acctNum == sa[cnt].get_acct_number() // || acctNum == mm[cnt].get_acct_number()) //{ switch( acctType ) { case 1: // set pointer, do checking ch[cnt].set_acct_number( acctNum ); ch[cnt].set_balance(ch[cnt].get_balance() + bal ); break; /* or { p = &Checking; p->set_acct_number( acctNum ); p->set_balance( bal ); break; } */ case 2: // set pointer, do saving sa[cnt].set_acct_number( acctNum ); sa[cnt].set_balance( sa[cnt].get_balance() + bal ); rate = sa[cnt].get_int_rate(); newBal += rate * sa[cnt].get_balance(); sa[cnt].set_balance (newBal); break; /* or { p = &Savings; p-> } */ case 3: // set pointer, do money market mm[cnt].set_acct_number( acctNum ); mm[cnt].set_balance( mm[cnt].get_balance() + bal ); rate = mm[cnt].get_int_rate( ); newBal += rate * mm[cnt].get_balance(); mm[cnt].set_balance (newBal); break; dataNew << (acctNum * 10) + acctType << newBal << rate * 365 << endl; /* or { p = &Mmarket; p-> } */ //default: // handle error "no such type" //{ // call to error handling // It opens file for append, and // puts this set of info there //} } //end switch // } //end if transactions >> fullAcctNum >> bal; acctNum = fullAcctNum / 10; if (tempAcctNum != acctNum) { acctNum = tempAcctNum; cnt++; // I don't know what good this is now, but // I hate to throw anything away. // Maybe what we need is how many accounts // of each type. Whatever is needed, it is // more complicated than before. } } //end while dataNew.close(); transactions.close(); return (cnt - 1); } //////////////////////////////////////////////////////