int newAccount(BankAccount account[], int max_accounts, int num_accts){ BankAccount * b; //make sure there is space left if(num_accts+1 <= max_accounts){ b = &account[num_accts]; string fname, lname, type; int SSN; double acctbalance; cout << endl << "Please enter first name: "; cin >> fname; cout << endl << "Please enter last name: "; cin >> lname; cout << endl << "Please enter SSN (Social Security Number): "; cin >> SSN; cout << endl << "Please enter Account Type: "; cin >> type; cout << endl << "Please enter Account starting Balance: "; cin >> acctbalance; b->setFirstName(fname); b->setLastName(lname); b->setSSN(SSN); //increment the account number int greatest = 0; BankAccount * g; for(int i=0; i < num_accts; i++){ g = &account[i]; if(g->getAccountNumber() > greatest){ greatest = g->getAccountNumber(); } } greatest++; b->setAccountNumber(greatest); b->setAccountType(type); b->setAccountBalance(acctbalance); num_accts++; return num_accts; }
//Account Functions -------------------------------------------------------------------------------------------------------- int read_accts(BankAccount account[], int max_accounts){ //start counter int count = 0; //temporary variables string fname, lname, type; int SSN; double acctbalance; //count how moany entries are in the file. while(!File.eof() && count < max_accounts){ File >> fname >> lname >> SSN >> type >> acctbalance; count++; } //loop back to top of file. File.clear(); File.seekg(0, ios::beg); //counter for our current account int i = 0; //create pointer for changing the values at the direct address in memory BankAccount * b; //loop trhough file and save and set values while(!File.eof() && i < count){ //set our current account into our pointer variable b = &account[i]; //define our file format File >> fname >> lname >> SSN >> type >> acctbalance; //set all of our values b->setFirstName(fname); b->setLastName(lname); b->setSSN(SSN); b->setAccountNumber(i); b->setAccountType(type); b->setAccountBalance(acctbalance); i++; } return count; }