1. main.cpp
#include
#include
#include
#include
#include "Bank.hpp"
using namespace std;
int read_accts(Bank& bank, int max_accts)
{
int i = 0;
//ifstream infile("C:UsersSmart PCDesktopAssignment 3 (3110)myinput.txt");
ifstream infile("myinput");
string whiteSpace;
getline(infile, whiteSpace);
// check is file can be opened
if (infile)
{
// read only first max_accts accounts,
// in order to avoid overflow
for (i = 0; i> firstName;
// check is end of file reached
if (!infile.eof())
{
infile >> lastName;
infile >> ssn;
infile >> accountNumber;
infile >> accountType;
infile >> balance;
infile >> status;
infile >> transactions;
2. bank.addAccount(firstName, lastName, ssn, accountNumber, accountType, balance,
status);
int index = bank.findAccount(accountNumber);
Account* acc = bank.getAccount(index);
for(int i=0; i> transactionType;
infile >> amount;
if (acc)
acc->addTransaction(Transaction(transactionType, amount));
}
}
else {
break;
}
}
infile.close();
}
else {
cout << "cannot open inpout file" << endl;
}
return i;
}
*/
void menu()
{
cout << "Select one of the following:" << endl << endl;
cout << " W - Withdrawal" << endl;
cout << " D - Deposit" << endl;
cout << " N - New account" << endl;
cout << " B - Balance" << endl;
cout << " I - Account Info" << endl;
cout << " H - Account Info plus Account Transaction History" << endl;
cout << " C - Close Account (close but do not delete the account)" << endl;
3. cout << " R - Reopen a closed account" << endl;
cout << " X - Delete Account (close and delete the account from the database))" << endl;
cout << " Q - Quit" << endl;
}
void withdrawal(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index >= 0)
{
double amount;
cout << "Enter amount to withdraw: ";
cin >> amount;
// check is there possible to withdraw
if (amount>0)
{
// check is sufficient balance at account
if (bank.getAccount(index)->makeWithdrawal(amount))
{
cout << "Withdraw is completed." << endl;
}
else {
cout << "Error. Insuffucient funds." << endl;
}
}
else {
4. cout << "Error. Invalid amount, needed to entyer positiove number." << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void deposit(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index >= 0)
{
double amount;
cout << "Enter amount to deposit: ";
cin >> amount;
// check is there possible to withdraw
if (amount>0)
{
bank.getAccount(index)->makeDeposit(amount); //deposit operation
cout << "Deposit is completed." << endl;
5. }
else {
cout << "Error. Invalid amount, needed to entyer positiove number." << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void new_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index == -1)
{
double amount;
string firstName;
string lastName;
string SSN;
string accountType;
cout << "Enter first name: ";
cin >> firstName;
6. cout << "Enter last name: ";
cin >> lastName;
do
{
cout << "Enter Social Security Number: ";
cin >> SSN;
// SSN is 9 digits, check for validity
if (SSN.length() == 9)
{
break;
}
else {
cout << "Error. Invalid SSN, needed to enter 9 digits. Pleasy try again." << endl;
}
} while (true);
do
{
cout << "Enter Account type (C - Checking, S - Saving, D - CD) : ";
cin >> accountType;
// check for validity
if (accountType == "C" || accountType == "S" || accountType == "D")
{
break;
}
else {
cout << "Error. Invalid Account type. Please try again" << endl;
}
} while (true);
do
{
cout << "Enter amount to deposit: ";
cin >> amount;
7. // check for validity
if (amount>0)
{
break;
}
else {
cout << "Error. Invalid amount, needed to entyer positiove number." << endl;
}
} while (true);
if (bank.openAccount(firstName, lastName, SSN, requested_account, accountType,
amount))
cout << "Account is opened." << endl;
else
cout << "Error. Cannot open account." << endl;
}
else {
cout << "Error. Account number "" << requested_account << "" already exists."
<< endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void close_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
8. index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
if (!acc->isClosed())
{
acc->close();
cout << "Account number "" << requested_account << "" has been closed. "<<
endl;
} else {
cout << "Error. Account number "" << requested_account << "" is already
closed." << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void reopen_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
9. Account* acc = bank.getAccount(index);
if (index >= 0)
{
if (acc->isClosed())
{
acc->open();
cout << "Account number "" << requested_account << "" has been reopened.
"<< endl;
} else {
cout << "Error. Account number "" << requested_account << "" is already
opened." << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void delete_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index >= 0)
10. {
if (bank.deleteAccount(index))
cout << "Account is closed." << endl;
else
cout << "Error. Cannot close account." << endl;
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void balance(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
acc->addTransaction(Transaction("banance"));
cout << "Balance is: " << fixed << setprecision(2) << acc->getBalance() << endl;
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
11. }
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void account_info(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
acc->addTransaction(Transaction("getinfo"));
if (acc->getAccountType() == "S")
cout << "Saving ";
else if (acc->getAccountType() == "C")
cout << "Checking ";
else if (acc->getAccountType() == "D")
cout << "CD ";
cout << " Account #" << acc->getAccountNumber() << endl;
cout << " Depositor info:" << endl;
cout << " First name: " << acc->getDepositor().getName().getFirstname() << endl;
cout << " Last name: " << acc->getDepositor().getName().getLastname() << endl;
cout << " SSN: " << acc->getDepositor().getSSN() << endl;
12. cout << " Balance is: " << fixed << setprecision(2) << acc->getBalance() << endl;
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void account_info_tr(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
acc->addTransaction(Transaction("getinfo_tr"));
if (acc->getAccountType() == "S")
cout << "Saving ";
else if (acc->getAccountType() == "C")
cout << "Checking ";
else if (acc->getAccountType() == "D")
cout << "CD ";
13. cout << " Account #" << acc->getAccountNumber() << endl;
cout << " Depositor info:" << endl;
cout << " First name: " << acc->getDepositor().getName().getFirstname() << endl;
cout << " Last name: " << acc->getDepositor().getName().getLastname() << endl;
cout << " SSN: " << acc->getDepositor().getSSN() << endl;
cout << " Balance is: " << fixed << setprecision(2) << acc->getBalance() << endl;
int trCount = acc->getTransactionCount();
cout << endl << "Transaction List: [" << trCount << " trsnsaction(s)]" << endl;
for(int j=0; jgetTransaction(j).getTransactionType();
cout << "t";
if (acc->getTransaction(j).getAmount()>0)
{
cout << acc->getTransaction(j).getAmount();
}
cout << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
/*
This function prints a table of the complete account information for every active account.
*/
void print_accts(Bank& bank)
{
ofstream outfile("myoutput.txt");
if (outfile)
27. string whiteSpace;
getline(infile, whiteSpace);
// check is file can be opened
if (infile)
{
// read only first max_accts accounts,
// in order to avoid overflow
for (i = 0; i> firstName;
// check is end of file reached
if (!infile.eof())
{
infile >> lastName;
infile >> ssn;
infile >> accountNumber;
infile >> accountType;
infile >> balance;
infile >> status;
infile >> transactions;
bank.addAccount(firstName, lastName, ssn, accountNumber, accountType, balance,
status);
int index = bank.findAccount(accountNumber);
Account* acc = bank.getAccount(index);
for(int i=0; i> transactionType;
infile >> amount;
if (acc)
acc->addTransaction(Transaction(transactionType, amount));
}
}
else {
break;
28. }
}
infile.close();
}
else {
cout << "cannot open inpout file" << endl;
}
return i;
}
*/
void menu()
{
cout << "Select one of the following:" << endl << endl;
cout << " W - Withdrawal" << endl;
cout << " D - Deposit" << endl;
cout << " N - New account" << endl;
cout << " B - Balance" << endl;
cout << " I - Account Info" << endl;
cout << " H - Account Info plus Account Transaction History" << endl;
cout << " C - Close Account (close but do not delete the account)" << endl;
cout << " R - Reopen a closed account" << endl;
cout << " X - Delete Account (close and delete the account from the database))" << endl;
cout << " Q - Quit" << endl;
}
void withdrawal(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
29. index = bank.findAccount(requested_account);
if (index >= 0)
{
double amount;
cout << "Enter amount to withdraw: ";
cin >> amount;
// check is there possible to withdraw
if (amount>0)
{
// check is sufficient balance at account
if (bank.getAccount(index)->makeWithdrawal(amount))
{
cout << "Withdraw is completed." << endl;
}
else {
cout << "Error. Insuffucient funds." << endl;
}
}
else {
cout << "Error. Invalid amount, needed to entyer positiove number." << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void deposit(Bank& bank)
{
int index, requested_account;
30. //prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index >= 0)
{
double amount;
cout << "Enter amount to deposit: ";
cin >> amount;
// check is there possible to withdraw
if (amount>0)
{
bank.getAccount(index)->makeDeposit(amount); //deposit operation
cout << "Deposit is completed." << endl;
}
else {
cout << "Error. Invalid amount, needed to entyer positiove number." << endl;
}
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void new_acct(Bank& bank)
31. {
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index == -1)
{
double amount;
string firstName;
string lastName;
string SSN;
string accountType;
cout << "Enter first name: ";
cin >> firstName;
cout << "Enter last name: ";
cin >> lastName;
do
{
cout << "Enter Social Security Number: ";
cin >> SSN;
// SSN is 9 digits, check for validity
if (SSN.length() == 9)
{
break;
}
else {
cout << "Error. Invalid SSN, needed to enter 9 digits. Pleasy try again." << endl;
}
} while (true);
32. do
{
cout << "Enter Account type (C - Checking, S - Saving, D - CD) : ";
cin >> accountType;
// check for validity
if (accountType == "C" || accountType == "S" || accountType == "D")
{
break;
}
else {
cout << "Error. Invalid Account type. Please try again" << endl;
}
} while (true);
do
{
cout << "Enter amount to deposit: ";
cin >> amount;
// check for validity
if (amount>0)
{
break;
}
else {
cout << "Error. Invalid amount, needed to entyer positiove number." << endl;
}
} while (true);
if (bank.openAccount(firstName, lastName, SSN, requested_account, accountType,
amount))
cout << "Account is opened." << endl;
else
cout << "Error. Cannot open account." << endl;
33. }
else {
cout << "Error. Account number "" << requested_account << "" already exists."
<< endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void close_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
if (!acc->isClosed())
{
acc->close();
cout << "Account number "" << requested_account << "" has been closed. "<<
endl;
} else {
cout << "Error. Account number "" << requested_account << "" is already
closed." << endl;
}
}
34. else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void reopen_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
if (acc->isClosed())
{
acc->open();
cout << "Account number "" << requested_account << "" has been reopened.
"<< endl;
} else {
cout << "Error. Account number "" << requested_account << "" is already
opened." << endl;
}
}
else {
35. cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void delete_acct(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
if (index >= 0)
{
if (bank.deleteAccount(index))
cout << "Account is closed." << endl;
else
cout << "Error. Cannot close account." << endl;
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
36. void balance(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid
if (requested_account != 0)
{
index = bank.findAccount(requested_account);
Account* acc = bank.getAccount(index);
if (index >= 0)
{
acc->addTransaction(Transaction("banance"));
cout << "Balance is: " << fixed << setprecision(2) << acc->getBalance() << endl;
}
else {
cout << "Error. Account number "" << requested_account << "" is not found." <<
endl;
}
}
else {
cout << "Error. Invalid account number." << endl;
}
}
void account_info(Bank& bank)
{
int index, requested_account;
//prompt for account number
cout << endl << "Enter the account number: ";
cin >> requested_account;
// account #0 is not valid