SlideShare a Scribd company logo
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;
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;
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 {
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;
}
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;
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;
// 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)
{
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);
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)
{
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;
}
}
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;
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 ";
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)
{
for (int i = 0; i < bank.getAccounsNumber(); i++)
{
Account* acc = bank.getAccount(i);
outfile << acc->getDepositor().getName().getFirstname();
outfile << "t";
outfile << acc->getDepositor().getName().getLastname();
outfile << "t";
outfile << acc->getDepositor().getSSN();
outfile << "t";
outfile << acc->getAccountNumber();
outfile << "t";
// save as char
outfile << acc->getAccountType();
outfile << "t";
outfile << fixed << setprecision(2) << acc->getBalance();
outfile << "t";
outfile << fixed << setprecision(2) << (acc->isClosed() ? 0 : 1);
outfile << "t";
outfile << fixed << setprecision(2) << acc->getTransactionCount();
outfile << endl;
for(int j=0; jgetTransactionCount(); j++)
{
Transaction tr = acc->getTransaction(j);
outfile << tr.getTransactionType();
outfile << "t";
outfile << tr.getAmount();
outfile << endl;
}
}
outfile.close();
}
else {
cout << "Cannot open output file";
}
}
int main()
{
string choice;
Bank bank;
int accountsNumber = 0;
bool stop = false;
accountsNumber = read_accts(bank, MAX_NUM);
print_accts(bank);
do
{
cout << endl;
menu();
cout << "Your choice: ";
cin >> choice;
if (choice == "Q" || choice == "q")
{
stop = true;
}
else if (choice == "W" || choice == "w")
{
withdrawal(bank);
}
else if (choice == "D" || choice == "d")
{
deposit(bank);
}
else if (choice == "N" || choice == "n")
{
new_acct(bank);
}
else if (choice == "B" || choice == "b")
{
balance(bank);
}
else if (choice == "I" || choice == "i")
{
account_info(bank);
}
else if (choice == "H" || choice == "h")
{
account_info_tr(bank);
}
else if (choice == "C" || choice == "c")
{
close_acct(bank);
}
else if (choice == "R" || choice == "r")
{
reopen_acct(bank);
}
else if (choice == "X" || choice == "x")
{
delete_acct(bank);
}
else
{
cout << "Invalid choice, please try again." << endl;
}
} while (!stop);
print_accts(bank);
system("pause");
return 0;
}
Account.cpp
#include "Account.hpp"
#include "Transaction.hpp"
Account::Account(void)
{
transactionCount = 0;
capacity = 101;
transactions = new Transaction[capacity];
}
Account::~Account(void)
{
delete[] transactions;
}
Account::Account(Depositor& depositor, double balance, int accountNumber, string
accountType, int status)
{
_depositor = depositor;
_balance = balance;
_accountNumber = accountNumber;
_accountType = accountType;
_status = status;
transactionCount = 0;
capacity = 101;
transactions = new Transaction[capacity];
}
Account::Account(const Account& account)
{
_depositor = account._depositor;
_balance = account._balance;
_accountNumber = account._accountNumber;
_accountType = account._accountType;
_status = account._status;
capacity = account.capacity;
transactionCount = account.transactionCount;
transactions = new Transaction[capacity];
for(int i=0; i=capacity-1)
{
capacity = capacity * 2;
Transaction* newTransaction = new Transaction[capacity];
for(int i=0; i_balance)
{
return false;
}
else
{
addTransaction(Transaction("withdraw", amount));
_balance -= amount;
return true;
}
}
void Account::open()
{
addTransaction(Transaction("open"));
_status = 1;
}
void Account::close()
{
addTransaction(Transaction("close"));
_status = 0;
}
bool Account::isClosed()
{
return _status==0;
}
Account.hpp
#ifndef Account_hpp
#define Account_hpp
#include
#include "Depositor.hpp"
#include "Transaction.hpp"
class Account
{
Depositor _depositor;
double _balance;
int _accountNumber;
string _accountType;
int _status;
int capacity;
int transactionCount;
Transaction* transactions;
public:
Account(void);
Account(Depositor& depositor, double balance, int accountNumber, string accountType, int
status);
Account(const Account& account);
~Account(void);
void addTransaction(Transaction transaction);
int getTransactionCount();
Transaction getTransaction(int index);
void open();
void close();
bool isClosed();
double getBalance();
Depositor& getDepositor();
int getAccountNumber();
string getAccountType();
void makeDeposit(double amount);
bool makeWithdrawal(double amount);
};
#endif /* Account_hpp */
Bank.cpp
#include "Bank.hpp"
Bank::Bank(void)
{
accountsNumber = 0;
}
Bank::~Bank(void)
{
}
int Bank::getAccounsNumber()
{
return accountsNumber;
}
bool Bank::openAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance)
{
if (addAccount(firstName, lastName, ssn, accountNumber, accountType, balance, 1))
{
int index = findAccount(accountNumber);
if (index>=0)
{
_accounts[index]->open();
}
return true;
}
return false;
}
bool Bank::addAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance, int status)
{
if (accountsNumbergetAccountNumber() == accountNumber)
return i;
}
return -1;
}
int Bank::findAccountSSN(string ssn)
{
for (int i = 0; igetDepositor().getSSN() == ssn)
return i;
}
return -1;
}
Account* Bank::getAccount(int index)
{
return _accounts[index];
}
bool Bank::deleteAccount(int index)
{
if (index >= 0 && index
#define MAX_NUM 100
#include "Account.hpp"
class Bank
{
Account* _accounts[MAX_NUM];
int accountsNumber;
public:
Bank(void);
~Bank(void);
bool openAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance);
bool addAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance, int status);
int findAccount(int accountNumber);
int findAccountSSN(string ssn);
Account* getAccount(int index);
bool deleteAccount(int index);
int getAccounsNumber();
};
#endif /* Bank_hpp */
Depositor.cpp
#include "Depositor.hpp"
Depositor::Depositor(void)
{
}
Depositor::~Depositor(void)
{
}
Depositor::Depositor(const Depositor& depositor)
{
_ssn = depositor._ssn;
_name = depositor._name;
}
Depositor::Depositor(Name& name, string ssn)
{
_ssn = ssn;
_name = name;
}
Name& Depositor::getName()
{
return _name;
}
string Depositor::getSSN()
{
return _ssn;
}
Depositor.hpp
#ifndef Depositor_hpp
#define Depositor_hpp
#include
#include "Name.hpp"
class Depositor
{
string _ssn;
Name _name;
public:
Depositor(void);
Depositor(const Depositor& depositor);
Depositor(Name& name, string ssn);
~Depositor(void);
Name& getName();
string getSSN();
};
#endif /* Depositor_hpp */
Name.cpp
#include "Name.hpp"
Name::Name(void)
{
}
Name::~Name(void)
{
}
Name::Name(const Name& name)
{
_firstName = name._firstName;
_lastName = name._lastName;
}
Name::Name(string firstName, string lastName)
{
_firstName = firstName;
_lastName = lastName;
}
string Name::getFirstname()
{
return _firstName;
}
string Name::getLastname()
{
return _lastName;
}
Name.hpp
#ifndef Name_hpp
#define Name_hpp
#include
#include
using namespace std;
class Name
{
string _firstName;
string _lastName;
public:
Name(void);
Name(const Name& name);
Name(string firstName, string lastName);
~Name(void);
string getFirstname();
string getLastname();
};
#endif /* Name_hpp */
Transaction.cpp
#include "Transaction.hpp"
Transaction::Transaction()
{
}
Transaction::Transaction(string transactionType, double amount)
{
_transactionType = transactionType;
_amount = amount;
}
Transaction::Transaction(string transactionType)
{
_transactionType = transactionType;
_amount = 0.0;
}
Transaction::Transaction(const Transaction& transaction)
{
_transactionType = transaction._transactionType;
_amount = transaction._amount;
}
Transaction::~Transaction(void)
{
}
string Transaction::getTransactionType()
{
return _transactionType;
}
double Transaction::getAmount()
{
return _amount;
}
Transaction.hpp
#include "Transaction.hpp"
Transaction::Transaction()
{
}
Transaction::Transaction(string transactionType, double amount)
{
_transactionType = transactionType;
_amount = amount;
}
Transaction::Transaction(string transactionType)
{
_transactionType = transactionType;
_amount = 0.0;
}
Transaction::Transaction(const Transaction& transaction)
{
_transactionType = transaction._transactionType;
_amount = transaction._amount;
}
Transaction::~Transaction(void)
{
}
string Transaction::getTransactionType()
{
return _transactionType;
}
double Transaction::getAmount()
{
return _amount;
}
Solution
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;
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;
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 {
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;
}
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;
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;
// 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)
{
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);
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)
{
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;
}
}
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;
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 ";
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)
{
for (int i = 0; i < bank.getAccounsNumber(); i++)
{
Account* acc = bank.getAccount(i);
outfile << acc->getDepositor().getName().getFirstname();
outfile << "t";
outfile << acc->getDepositor().getName().getLastname();
outfile << "t";
outfile << acc->getDepositor().getSSN();
outfile << "t";
outfile << acc->getAccountNumber();
outfile << "t";
// save as char
outfile << acc->getAccountType();
outfile << "t";
outfile << fixed << setprecision(2) << acc->getBalance();
outfile << "t";
outfile << fixed << setprecision(2) << (acc->isClosed() ? 0 : 1);
outfile << "t";
outfile << fixed << setprecision(2) << acc->getTransactionCount();
outfile << endl;
for(int j=0; jgetTransactionCount(); j++)
{
Transaction tr = acc->getTransaction(j);
outfile << tr.getTransactionType();
outfile << "t";
outfile << tr.getAmount();
outfile << endl;
}
}
outfile.close();
}
else {
cout << "Cannot open output file";
}
}
int main()
{
string choice;
Bank bank;
int accountsNumber = 0;
bool stop = false;
accountsNumber = read_accts(bank, MAX_NUM);
print_accts(bank);
do
{
cout << endl;
menu();
cout << "Your choice: ";
cin >> choice;
if (choice == "Q" || choice == "q")
{
stop = true;
}
else if (choice == "W" || choice == "w")
{
withdrawal(bank);
}
else if (choice == "D" || choice == "d")
{
deposit(bank);
}
else if (choice == "N" || choice == "n")
{
new_acct(bank);
}
else if (choice == "B" || choice == "b")
{
balance(bank);
}
else if (choice == "I" || choice == "i")
{
account_info(bank);
}
else if (choice == "H" || choice == "h")
{
account_info_tr(bank);
}
else if (choice == "C" || choice == "c")
{
close_acct(bank);
}
else if (choice == "R" || choice == "r")
{
reopen_acct(bank);
}
else if (choice == "X" || choice == "x")
{
delete_acct(bank);
}
else
{
cout << "Invalid choice, please try again." << endl;
}
} while (!stop);
print_accts(bank);
system("pause");
return 0;
}
Account.cpp
#include "Account.hpp"
#include "Transaction.hpp"
Account::Account(void)
{
transactionCount = 0;
capacity = 101;
transactions = new Transaction[capacity];
}
Account::~Account(void)
{
delete[] transactions;
}
Account::Account(Depositor& depositor, double balance, int accountNumber, string
accountType, int status)
{
_depositor = depositor;
_balance = balance;
_accountNumber = accountNumber;
_accountType = accountType;
_status = status;
transactionCount = 0;
capacity = 101;
transactions = new Transaction[capacity];
}
Account::Account(const Account& account)
{
_depositor = account._depositor;
_balance = account._balance;
_accountNumber = account._accountNumber;
_accountType = account._accountType;
_status = account._status;
capacity = account.capacity;
transactionCount = account.transactionCount;
transactions = new Transaction[capacity];
for(int i=0; i=capacity-1)
{
capacity = capacity * 2;
Transaction* newTransaction = new Transaction[capacity];
for(int i=0; i_balance)
{
return false;
}
else
{
addTransaction(Transaction("withdraw", amount));
_balance -= amount;
return true;
}
}
void Account::open()
{
addTransaction(Transaction("open"));
_status = 1;
}
void Account::close()
{
addTransaction(Transaction("close"));
_status = 0;
}
bool Account::isClosed()
{
return _status==0;
}
Account.hpp
#ifndef Account_hpp
#define Account_hpp
#include
#include "Depositor.hpp"
#include "Transaction.hpp"
class Account
{
Depositor _depositor;
double _balance;
int _accountNumber;
string _accountType;
int _status;
int capacity;
int transactionCount;
Transaction* transactions;
public:
Account(void);
Account(Depositor& depositor, double balance, int accountNumber, string accountType, int
status);
Account(const Account& account);
~Account(void);
void addTransaction(Transaction transaction);
int getTransactionCount();
Transaction getTransaction(int index);
void open();
void close();
bool isClosed();
double getBalance();
Depositor& getDepositor();
int getAccountNumber();
string getAccountType();
void makeDeposit(double amount);
bool makeWithdrawal(double amount);
};
#endif /* Account_hpp */
Bank.cpp
#include "Bank.hpp"
Bank::Bank(void)
{
accountsNumber = 0;
}
Bank::~Bank(void)
{
}
int Bank::getAccounsNumber()
{
return accountsNumber;
}
bool Bank::openAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance)
{
if (addAccount(firstName, lastName, ssn, accountNumber, accountType, balance, 1))
{
int index = findAccount(accountNumber);
if (index>=0)
{
_accounts[index]->open();
}
return true;
}
return false;
}
bool Bank::addAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance, int status)
{
if (accountsNumbergetAccountNumber() == accountNumber)
return i;
}
return -1;
}
int Bank::findAccountSSN(string ssn)
{
for (int i = 0; igetDepositor().getSSN() == ssn)
return i;
}
return -1;
}
Account* Bank::getAccount(int index)
{
return _accounts[index];
}
bool Bank::deleteAccount(int index)
{
if (index >= 0 && index
#define MAX_NUM 100
#include "Account.hpp"
class Bank
{
Account* _accounts[MAX_NUM];
int accountsNumber;
public:
Bank(void);
~Bank(void);
bool openAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance);
bool addAccount(string firstName, string lastName, string ssn, int accountNumber, string
accountType, double balance, int status);
int findAccount(int accountNumber);
int findAccountSSN(string ssn);
Account* getAccount(int index);
bool deleteAccount(int index);
int getAccounsNumber();
};
#endif /* Bank_hpp */
Depositor.cpp
#include "Depositor.hpp"
Depositor::Depositor(void)
{
}
Depositor::~Depositor(void)
{
}
Depositor::Depositor(const Depositor& depositor)
{
_ssn = depositor._ssn;
_name = depositor._name;
}
Depositor::Depositor(Name& name, string ssn)
{
_ssn = ssn;
_name = name;
}
Name& Depositor::getName()
{
return _name;
}
string Depositor::getSSN()
{
return _ssn;
}
Depositor.hpp
#ifndef Depositor_hpp
#define Depositor_hpp
#include
#include "Name.hpp"
class Depositor
{
string _ssn;
Name _name;
public:
Depositor(void);
Depositor(const Depositor& depositor);
Depositor(Name& name, string ssn);
~Depositor(void);
Name& getName();
string getSSN();
};
#endif /* Depositor_hpp */
Name.cpp
#include "Name.hpp"
Name::Name(void)
{
}
Name::~Name(void)
{
}
Name::Name(const Name& name)
{
_firstName = name._firstName;
_lastName = name._lastName;
}
Name::Name(string firstName, string lastName)
{
_firstName = firstName;
_lastName = lastName;
}
string Name::getFirstname()
{
return _firstName;
}
string Name::getLastname()
{
return _lastName;
}
Name.hpp
#ifndef Name_hpp
#define Name_hpp
#include
#include
using namespace std;
class Name
{
string _firstName;
string _lastName;
public:
Name(void);
Name(const Name& name);
Name(string firstName, string lastName);
~Name(void);
string getFirstname();
string getLastname();
};
#endif /* Name_hpp */
Transaction.cpp
#include "Transaction.hpp"
Transaction::Transaction()
{
}
Transaction::Transaction(string transactionType, double amount)
{
_transactionType = transactionType;
_amount = amount;
}
Transaction::Transaction(string transactionType)
{
_transactionType = transactionType;
_amount = 0.0;
}
Transaction::Transaction(const Transaction& transaction)
{
_transactionType = transaction._transactionType;
_amount = transaction._amount;
}
Transaction::~Transaction(void)
{
}
string Transaction::getTransactionType()
{
return _transactionType;
}
double Transaction::getAmount()
{
return _amount;
}
Transaction.hpp
#include "Transaction.hpp"
Transaction::Transaction()
{
}
Transaction::Transaction(string transactionType, double amount)
{
_transactionType = transactionType;
_amount = amount;
}
Transaction::Transaction(string transactionType)
{
_transactionType = transactionType;
_amount = 0.0;
}
Transaction::Transaction(const Transaction& transaction)
{
_transactionType = transaction._transactionType;
_amount = transaction._amount;
}
Transaction::~Transaction(void)
{
}
string Transaction::getTransactionType()
{
return _transactionType;
}
double Transaction::getAmount()
{
return _amount;
}

More Related Content

PDF
#include iostream #include BankAccountClass.cpp #include .pdf
PDF
This what Im suppose to do and this is what I have so far.In thi.pdf
PPTX
C programming
DOC
Cbse class-xii-computer-science-project
DOC
Cbse class-xii-computer-science-projec
PDF
C++ coding for Banking System program
PDF
Banks offer various types of accounts, such as savings, checking, cer.pdf
PDF
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
#include iostream #include BankAccountClass.cpp #include .pdf
This what Im suppose to do and this is what I have so far.In thi.pdf
C programming
Cbse class-xii-computer-science-project
Cbse class-xii-computer-science-projec
C++ coding for Banking System program
Banks offer various types of accounts, such as savings, checking, cer.pdf
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf

Similar to main.cpp #include iostream #include iomanip #include fs.pdf (20)

PDF
Please distinguish between the .h and .cpp file, create a fully work.pdf
DOC
Computer mai ns project
DOC
Computer mai ns project
PPTX
Bank Management System
PDF
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
PDF
Banks offer various types of accounts, such as savings, checking, cer.pdf
DOCX
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
PDF
Cbse computer science (c++) class 12 board project bank managment system
DOCX
User.DS_Store__MACOSXUser._.DS_Store__MACOSXUser._D.docx
PPTX
Computer science project
PDF
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
DOCX
bank management system
PDF
Rajeev oops 2nd march
DOCX
Write a banking program that simulates the operation of your local ba.docx
DOCX
Pratik Bakane C++
PDF
BankAccount.java A bank account has a balance that can be cha.pdf
PDF
A09
PDF
The java class Account that simultes the Account class.pdf
DOCX
project
PDF
public class NegativeAmountException extends Exception {    .pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
Computer mai ns project
Computer mai ns project
Bank Management System
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdf
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbse computer science (c++) class 12 board project bank managment system
User.DS_Store__MACOSXUser._.DS_Store__MACOSXUser._D.docx
Computer science project
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
bank management system
Rajeev oops 2nd march
Write a banking program that simulates the operation of your local ba.docx
Pratik Bakane C++
BankAccount.java A bank account has a balance that can be cha.pdf
A09
The java class Account that simultes the Account class.pdf
project
public class NegativeAmountException extends Exception {    .pdf

More from arwholesalelors (20)

PDF
Algebra, branch of mathematics in which arithmetical operations and .pdf
PDF
AccuracyData accuracy mentions to the degree with which data prop.pdf
PDF
#include algorithm #include vector #include iostream usi.pdf
PDF
A) I will look for LP (limited partner) such as Yale Investment fund.pdf
PDF
1. The Kepler space telescope detects planets and planet candidates .pdf
PDF
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
PDF
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
PDF
EtSH is the strongest acid, so EtS- is the weakest conjugate base. .pdf
PDF
Particulars Amount $ Share Holders Funds Com.pdf
PDF
The Nitro group is electron withdrawing, and ther.pdf
PDF
The Systems Development Life Cycle Moderate and large firms with uni.pdf
PDF
You are asked to determine DNA content of a liver tissue. Describe h.pdf
PDF
when we draw a vertical line it will cross the graph twice(that is m.pdf
PDF
We Know that      Baking powder and Baking soda isused as a leave.pdf
PDF
The fallowing program shows the simple transformation #define GLEW.pdf
PDF
Two types of malware -1. Virus A virus is a contagious program o.pdf
PDF
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
PDF
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
PDF
Scientific evidences I would give in support of evolution1. Paleo.pdf
PDF
Package scopeis the range of visibility for aparticular element or c.pdf
Algebra, branch of mathematics in which arithmetical operations and .pdf
AccuracyData accuracy mentions to the degree with which data prop.pdf
#include algorithm #include vector #include iostream usi.pdf
A) I will look for LP (limited partner) such as Yale Investment fund.pdf
1. The Kepler space telescope detects planets and planet candidates .pdf
1. When cell in S phase is fused with cell in G1 phase, the cell of .pdf
1. A Holds individuals accountable for their actions.2. E. A,B and.pdf
EtSH is the strongest acid, so EtS- is the weakest conjugate base. .pdf
Particulars Amount $ Share Holders Funds Com.pdf
The Nitro group is electron withdrawing, and ther.pdf
The Systems Development Life Cycle Moderate and large firms with uni.pdf
You are asked to determine DNA content of a liver tissue. Describe h.pdf
when we draw a vertical line it will cross the graph twice(that is m.pdf
We Know that      Baking powder and Baking soda isused as a leave.pdf
The fallowing program shows the simple transformation #define GLEW.pdf
Two types of malware -1. Virus A virus is a contagious program o.pdf
TlI -- Tl+ + I- Ksp = 8.9E-8 = [Tl+][I-]          (eqn. 1) PbI2 .pdf
The cells of the reproductive organs (Eg ovaries ad testes) undergo.pdf
Scientific evidences I would give in support of evolution1. Paleo.pdf
Package scopeis the range of visibility for aparticular element or c.pdf

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Pharma ospi slides which help in ospi learning
PDF
Basic Mud Logging Guide for educational purpose
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Computing-Curriculum for Schools in Ghana
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Structure & Organelles in detailed.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O7-L3 Supply Chain Operations - ICLT Program
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
Pharma ospi slides which help in ospi learning
Basic Mud Logging Guide for educational purpose
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Computing-Curriculum for Schools in Ghana
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Microbial disease of the cardiovascular and lymphatic systems
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Structure & Organelles in detailed.
Anesthesia in Laparoscopic Surgery in India
O7-L3 Supply Chain Operations - ICLT Program

main.cpp #include iostream #include iomanip #include fs.pdf

  • 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)
  • 14. { for (int i = 0; i < bank.getAccounsNumber(); i++) { Account* acc = bank.getAccount(i); outfile << acc->getDepositor().getName().getFirstname(); outfile << "t"; outfile << acc->getDepositor().getName().getLastname(); outfile << "t"; outfile << acc->getDepositor().getSSN(); outfile << "t"; outfile << acc->getAccountNumber(); outfile << "t"; // save as char outfile << acc->getAccountType(); outfile << "t"; outfile << fixed << setprecision(2) << acc->getBalance(); outfile << "t"; outfile << fixed << setprecision(2) << (acc->isClosed() ? 0 : 1); outfile << "t"; outfile << fixed << setprecision(2) << acc->getTransactionCount(); outfile << endl; for(int j=0; jgetTransactionCount(); j++) { Transaction tr = acc->getTransaction(j); outfile << tr.getTransactionType(); outfile << "t"; outfile << tr.getAmount(); outfile << endl; } } outfile.close(); } else { cout << "Cannot open output file";
  • 15. } } int main() { string choice; Bank bank; int accountsNumber = 0; bool stop = false; accountsNumber = read_accts(bank, MAX_NUM); print_accts(bank); do { cout << endl; menu(); cout << "Your choice: "; cin >> choice; if (choice == "Q" || choice == "q") { stop = true; } else if (choice == "W" || choice == "w") { withdrawal(bank); } else if (choice == "D" || choice == "d") { deposit(bank); } else if (choice == "N" || choice == "n") { new_acct(bank); } else if (choice == "B" || choice == "b")
  • 16. { balance(bank); } else if (choice == "I" || choice == "i") { account_info(bank); } else if (choice == "H" || choice == "h") { account_info_tr(bank); } else if (choice == "C" || choice == "c") { close_acct(bank); } else if (choice == "R" || choice == "r") { reopen_acct(bank); } else if (choice == "X" || choice == "x") { delete_acct(bank); } else { cout << "Invalid choice, please try again." << endl; } } while (!stop); print_accts(bank); system("pause"); return 0; } Account.cpp
  • 17. #include "Account.hpp" #include "Transaction.hpp" Account::Account(void) { transactionCount = 0; capacity = 101; transactions = new Transaction[capacity]; } Account::~Account(void) { delete[] transactions; } Account::Account(Depositor& depositor, double balance, int accountNumber, string accountType, int status) { _depositor = depositor; _balance = balance; _accountNumber = accountNumber; _accountType = accountType; _status = status; transactionCount = 0; capacity = 101; transactions = new Transaction[capacity]; } Account::Account(const Account& account) { _depositor = account._depositor; _balance = account._balance; _accountNumber = account._accountNumber; _accountType = account._accountType; _status = account._status; capacity = account.capacity; transactionCount = account.transactionCount;
  • 18. transactions = new Transaction[capacity]; for(int i=0; i=capacity-1) { capacity = capacity * 2; Transaction* newTransaction = new Transaction[capacity]; for(int i=0; i_balance) { return false; } else { addTransaction(Transaction("withdraw", amount)); _balance -= amount; return true; } } void Account::open() { addTransaction(Transaction("open")); _status = 1; } void Account::close() { addTransaction(Transaction("close")); _status = 0; } bool Account::isClosed() { return _status==0; } Account.hpp #ifndef Account_hpp #define Account_hpp #include
  • 19. #include "Depositor.hpp" #include "Transaction.hpp" class Account { Depositor _depositor; double _balance; int _accountNumber; string _accountType; int _status; int capacity; int transactionCount; Transaction* transactions; public: Account(void); Account(Depositor& depositor, double balance, int accountNumber, string accountType, int status); Account(const Account& account); ~Account(void); void addTransaction(Transaction transaction); int getTransactionCount(); Transaction getTransaction(int index); void open(); void close(); bool isClosed(); double getBalance(); Depositor& getDepositor(); int getAccountNumber(); string getAccountType(); void makeDeposit(double amount); bool makeWithdrawal(double amount); }; #endif /* Account_hpp */
  • 20. Bank.cpp #include "Bank.hpp" Bank::Bank(void) { accountsNumber = 0; } Bank::~Bank(void) { } int Bank::getAccounsNumber() { return accountsNumber; } bool Bank::openAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance) { if (addAccount(firstName, lastName, ssn, accountNumber, accountType, balance, 1)) { int index = findAccount(accountNumber); if (index>=0) { _accounts[index]->open(); } return true; } return false; } bool Bank::addAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance, int status) { if (accountsNumbergetAccountNumber() == accountNumber) return i; } return -1;
  • 21. } int Bank::findAccountSSN(string ssn) { for (int i = 0; igetDepositor().getSSN() == ssn) return i; } return -1; } Account* Bank::getAccount(int index) { return _accounts[index]; } bool Bank::deleteAccount(int index) { if (index >= 0 && index #define MAX_NUM 100 #include "Account.hpp" class Bank { Account* _accounts[MAX_NUM]; int accountsNumber; public: Bank(void); ~Bank(void); bool openAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance); bool addAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance, int status); int findAccount(int accountNumber); int findAccountSSN(string ssn); Account* getAccount(int index); bool deleteAccount(int index); int getAccounsNumber();
  • 22. }; #endif /* Bank_hpp */ Depositor.cpp #include "Depositor.hpp" Depositor::Depositor(void) { } Depositor::~Depositor(void) { } Depositor::Depositor(const Depositor& depositor) { _ssn = depositor._ssn; _name = depositor._name; } Depositor::Depositor(Name& name, string ssn) { _ssn = ssn; _name = name; } Name& Depositor::getName() { return _name; } string Depositor::getSSN() { return _ssn; } Depositor.hpp #ifndef Depositor_hpp #define Depositor_hpp #include #include "Name.hpp"
  • 23. class Depositor { string _ssn; Name _name; public: Depositor(void); Depositor(const Depositor& depositor); Depositor(Name& name, string ssn); ~Depositor(void); Name& getName(); string getSSN(); }; #endif /* Depositor_hpp */ Name.cpp #include "Name.hpp" Name::Name(void) { } Name::~Name(void) { } Name::Name(const Name& name) { _firstName = name._firstName; _lastName = name._lastName; } Name::Name(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; } string Name::getFirstname() {
  • 24. return _firstName; } string Name::getLastname() { return _lastName; } Name.hpp #ifndef Name_hpp #define Name_hpp #include #include using namespace std; class Name { string _firstName; string _lastName; public: Name(void); Name(const Name& name); Name(string firstName, string lastName); ~Name(void); string getFirstname(); string getLastname(); }; #endif /* Name_hpp */ Transaction.cpp #include "Transaction.hpp" Transaction::Transaction() { } Transaction::Transaction(string transactionType, double amount) {
  • 25. _transactionType = transactionType; _amount = amount; } Transaction::Transaction(string transactionType) { _transactionType = transactionType; _amount = 0.0; } Transaction::Transaction(const Transaction& transaction) { _transactionType = transaction._transactionType; _amount = transaction._amount; } Transaction::~Transaction(void) { } string Transaction::getTransactionType() { return _transactionType; } double Transaction::getAmount() { return _amount; } Transaction.hpp #include "Transaction.hpp" Transaction::Transaction() { } Transaction::Transaction(string transactionType, double amount) { _transactionType = transactionType; _amount = amount; } Transaction::Transaction(string transactionType) {
  • 26. _transactionType = transactionType; _amount = 0.0; } Transaction::Transaction(const Transaction& transaction) { _transactionType = transaction._transactionType; _amount = transaction._amount; } Transaction::~Transaction(void) { } string Transaction::getTransactionType() { return _transactionType; } double Transaction::getAmount() { return _amount; } Solution 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");
  • 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
  • 37. 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; 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;
  • 38. //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 "; 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(); }
  • 39. 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) { for (int i = 0; i < bank.getAccounsNumber(); i++) { Account* acc = bank.getAccount(i); outfile << acc->getDepositor().getName().getFirstname(); outfile << "t"; outfile << acc->getDepositor().getName().getLastname(); outfile << "t"; outfile << acc->getDepositor().getSSN(); outfile << "t"; outfile << acc->getAccountNumber(); outfile << "t"; // save as char outfile << acc->getAccountType();
  • 40. outfile << "t"; outfile << fixed << setprecision(2) << acc->getBalance(); outfile << "t"; outfile << fixed << setprecision(2) << (acc->isClosed() ? 0 : 1); outfile << "t"; outfile << fixed << setprecision(2) << acc->getTransactionCount(); outfile << endl; for(int j=0; jgetTransactionCount(); j++) { Transaction tr = acc->getTransaction(j); outfile << tr.getTransactionType(); outfile << "t"; outfile << tr.getAmount(); outfile << endl; } } outfile.close(); } else { cout << "Cannot open output file"; } } int main() { string choice; Bank bank; int accountsNumber = 0; bool stop = false; accountsNumber = read_accts(bank, MAX_NUM); print_accts(bank); do { cout << endl;
  • 41. menu(); cout << "Your choice: "; cin >> choice; if (choice == "Q" || choice == "q") { stop = true; } else if (choice == "W" || choice == "w") { withdrawal(bank); } else if (choice == "D" || choice == "d") { deposit(bank); } else if (choice == "N" || choice == "n") { new_acct(bank); } else if (choice == "B" || choice == "b") { balance(bank); } else if (choice == "I" || choice == "i") { account_info(bank); } else if (choice == "H" || choice == "h") { account_info_tr(bank); } else if (choice == "C" || choice == "c") { close_acct(bank); }
  • 42. else if (choice == "R" || choice == "r") { reopen_acct(bank); } else if (choice == "X" || choice == "x") { delete_acct(bank); } else { cout << "Invalid choice, please try again." << endl; } } while (!stop); print_accts(bank); system("pause"); return 0; } Account.cpp #include "Account.hpp" #include "Transaction.hpp" Account::Account(void) { transactionCount = 0; capacity = 101; transactions = new Transaction[capacity]; } Account::~Account(void) { delete[] transactions; } Account::Account(Depositor& depositor, double balance, int accountNumber, string accountType, int status)
  • 43. { _depositor = depositor; _balance = balance; _accountNumber = accountNumber; _accountType = accountType; _status = status; transactionCount = 0; capacity = 101; transactions = new Transaction[capacity]; } Account::Account(const Account& account) { _depositor = account._depositor; _balance = account._balance; _accountNumber = account._accountNumber; _accountType = account._accountType; _status = account._status; capacity = account.capacity; transactionCount = account.transactionCount; transactions = new Transaction[capacity]; for(int i=0; i=capacity-1) { capacity = capacity * 2; Transaction* newTransaction = new Transaction[capacity]; for(int i=0; i_balance) { return false; } else { addTransaction(Transaction("withdraw", amount)); _balance -= amount; return true;
  • 44. } } void Account::open() { addTransaction(Transaction("open")); _status = 1; } void Account::close() { addTransaction(Transaction("close")); _status = 0; } bool Account::isClosed() { return _status==0; } Account.hpp #ifndef Account_hpp #define Account_hpp #include #include "Depositor.hpp" #include "Transaction.hpp" class Account { Depositor _depositor; double _balance; int _accountNumber; string _accountType; int _status; int capacity; int transactionCount; Transaction* transactions; public: Account(void);
  • 45. Account(Depositor& depositor, double balance, int accountNumber, string accountType, int status); Account(const Account& account); ~Account(void); void addTransaction(Transaction transaction); int getTransactionCount(); Transaction getTransaction(int index); void open(); void close(); bool isClosed(); double getBalance(); Depositor& getDepositor(); int getAccountNumber(); string getAccountType(); void makeDeposit(double amount); bool makeWithdrawal(double amount); }; #endif /* Account_hpp */ Bank.cpp #include "Bank.hpp" Bank::Bank(void) { accountsNumber = 0; } Bank::~Bank(void) { } int Bank::getAccounsNumber() { return accountsNumber; }
  • 46. bool Bank::openAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance) { if (addAccount(firstName, lastName, ssn, accountNumber, accountType, balance, 1)) { int index = findAccount(accountNumber); if (index>=0) { _accounts[index]->open(); } return true; } return false; } bool Bank::addAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance, int status) { if (accountsNumbergetAccountNumber() == accountNumber) return i; } return -1; } int Bank::findAccountSSN(string ssn) { for (int i = 0; igetDepositor().getSSN() == ssn) return i; } return -1; } Account* Bank::getAccount(int index) { return _accounts[index]; } bool Bank::deleteAccount(int index) { if (index >= 0 && index
  • 47. #define MAX_NUM 100 #include "Account.hpp" class Bank { Account* _accounts[MAX_NUM]; int accountsNumber; public: Bank(void); ~Bank(void); bool openAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance); bool addAccount(string firstName, string lastName, string ssn, int accountNumber, string accountType, double balance, int status); int findAccount(int accountNumber); int findAccountSSN(string ssn); Account* getAccount(int index); bool deleteAccount(int index); int getAccounsNumber(); }; #endif /* Bank_hpp */ Depositor.cpp #include "Depositor.hpp" Depositor::Depositor(void) { } Depositor::~Depositor(void) { } Depositor::Depositor(const Depositor& depositor) { _ssn = depositor._ssn; _name = depositor._name;
  • 48. } Depositor::Depositor(Name& name, string ssn) { _ssn = ssn; _name = name; } Name& Depositor::getName() { return _name; } string Depositor::getSSN() { return _ssn; } Depositor.hpp #ifndef Depositor_hpp #define Depositor_hpp #include #include "Name.hpp" class Depositor { string _ssn; Name _name; public: Depositor(void); Depositor(const Depositor& depositor); Depositor(Name& name, string ssn); ~Depositor(void); Name& getName(); string getSSN(); }; #endif /* Depositor_hpp */
  • 49. Name.cpp #include "Name.hpp" Name::Name(void) { } Name::~Name(void) { } Name::Name(const Name& name) { _firstName = name._firstName; _lastName = name._lastName; } Name::Name(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; } string Name::getFirstname() { return _firstName; } string Name::getLastname() { return _lastName; } Name.hpp #ifndef Name_hpp #define Name_hpp #include #include using namespace std; class Name {
  • 50. string _firstName; string _lastName; public: Name(void); Name(const Name& name); Name(string firstName, string lastName); ~Name(void); string getFirstname(); string getLastname(); }; #endif /* Name_hpp */ Transaction.cpp #include "Transaction.hpp" Transaction::Transaction() { } Transaction::Transaction(string transactionType, double amount) { _transactionType = transactionType; _amount = amount; } Transaction::Transaction(string transactionType) { _transactionType = transactionType; _amount = 0.0; } Transaction::Transaction(const Transaction& transaction) { _transactionType = transaction._transactionType; _amount = transaction._amount; } Transaction::~Transaction(void) {
  • 51. } string Transaction::getTransactionType() { return _transactionType; } double Transaction::getAmount() { return _amount; } Transaction.hpp #include "Transaction.hpp" Transaction::Transaction() { } Transaction::Transaction(string transactionType, double amount) { _transactionType = transactionType; _amount = amount; } Transaction::Transaction(string transactionType) { _transactionType = transactionType; _amount = 0.0; } Transaction::Transaction(const Transaction& transaction) { _transactionType = transaction._transactionType; _amount = transaction._amount; } Transaction::~Transaction(void) { } string Transaction::getTransactionType() { return _transactionType; }