Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BankAccount A txt file name BankTransIn.txt contain O Cash Johnny 1001 D 10010 5

ID: 3725194 • Letter: B

Question

BankAccount A txt file name BankTransIn.txt contain

O Cash Johnny 1001

D 10010 542

D 10011 1542

D 10012 5442 D 10013 7540 D 10017 5442 D 10016 7542 D 10011 1500 D 10012 5000 D 10013 7000 D 10017 6543 D 10016 7576 W 10017 1000 W 10016 65 W 10010 72 T 10017 54 10015 W 10017 20000 H 1001 O Williams Hank 1253 D 12530 10000 D 12531 10000 D 12532 10000 D 12533 10000 D 12534 10000 D 12535 10000 D 12536 10000 D 12537 10000 D 12538 10000 D 12539 10000 H 12534 W 12532 15000 H 1253 T 12539 765 43567 O Nelson Willie 9876 O Willis Bob 9876 1. The program will read in a string of transactions from a file into an in-memory queue. These transactions can open accounts, withdraw funds, deposit funds, transfer funds, or ask for the transaction history to be printed. 2) The program will next read from the queue and process the transac ons in order. 3. When the queue has been depleted the program will print out all open accounts and balances in those accounts. Each client account contains assets held in up to ten funds. A client account is represented by a rst and last name (two strings) and a unique 4 digit identifier. A fifth digit can be added to the digit id to represent the individual fund within the account as enumerated below: 0: Money Market 1: Prime Money Market 2: Long-Term Bond 3: Short-Term Bond 4: 500 Index Fund 5: Capital Value Fund 6: Growth Equity Fund 7: Growth Index Fund 8: Value Fund 9: Value Stock Index O: Open a client account with the appropriate funds D: Deposit assets into a fund W: Withdraw assets from a fund T: Transfer assets between funds (can be funds owned by a single client or transfers between clients) H: Display the history of all transac ons for a client account or for a single fund. Include errors in the output where appropriate. The final output will be look like Money Market: $470 D 10010 542 W 10010 72 Prime Money Market: $3042 D 10011 1542 D 10011 1500 Long-Term Bond: $10442 D 10012 5442 D 10012 5000 Short-Term Bond: $14540 D 10013 7540 D 10013 7000 Capital Value Fund: $54 T 10017 54 10015 Growth Equity Fund: $15053 D 10016 7542 D 10016 7576 W 10016 65 Growth Index Fund: $10931 D 10017 5442 D 10017 6543 W 10017 1000 T 10017 54 10015 W 10017 20000 (Failed) Transaction History for Hank Williams 500 Index Fund: $10000 D 12534 10000 Transaction History for Hank Williams by fund. Money Market: $10000 D 12530 10000 Prime Money Market: $10000 D 12531 10000 Long-Term Bond: $0 D 12532 10000 W 12532 10000 Short-Term Bond: $5000 D 12533 10000 W 12533 5000 500 Index Fund: $10000 D 12534 10000 Capital Value Fund: $10000 D 12535 10000 Growth Equity Fund: $10000 D 12536 10000 Growth Index Fund: $10000 D 12537 10000 Value Fund: $10000 D 12538 10000 Value Stock Index: $10000 D 12539 10000 ERROR: Account 4356 not found. Transferal refused. ERROR: Account 9876 is already open. Transaction refused. Processing Done. Final Balances Johnny Cash Account ID: 1001 Money Market: $470 Prime Money Market: $3042 Long-Term Bond: $10442 Short-Term Bond: $14540 500 Index Fund: $0 Capital Value Fund: $54 Growth Equity Fund: $15053 Growth Index Fund: $10931 Value Fund: $0 Value Stock Index: $0 Hank Williams Account ID: 1253 Money Market: $10000 Prime Money Market: $10000 Long-Term Bond: $0 Short-Term Bond: $5000 500 Index Fund: $10000 Capital Value Fund: $10000 Growth Equity Fund: $10000 Growth Index Fund: $10000 Value Fund: $10000 Value Stock Index: $10000 Willie Nelson Account ID: 9876 Money Market: $0 Prime Money Market: $0 Long-Term Bond: $0 Short-Term Bond: $0 500 Index Fund: $0 Capital Value Fund: $0 Growth Equity Fund: $0 Growth Index Fund: $0 Value Fund: $0 Value Stock Index: $0

Explanation / Answer

//main.cpp

#include "Account.h"

#include "Bank.h"

#include "BSTree.h"

#include "Transaction.h"

#include "FundType.h"

#include <iostream>

using namespace std;

int main(int argc, _TCHAR* argv[])

{

string fileName = "BankTransIn.txt";

Bank ABCBank;

ABCBank.ReadTxtFile(fileName);

ABCBank.ProceedQue();

ABCBank.DisplayAllAccount();

cin.get();

return 0;

}

----------------------

//Account.cpp

#include "Account.h"

Account::Account()

{

firstName = "";

lastName = "";

ID = 0;

}

Account::Account(string incLastName, string incFirstName, int incID)

{

lastName = incLastName;

firstName = incFirstName;

ID = incID;

funds[0].setFundName("Money Market");

funds[1].setFundName("Prime Money Market");

funds[2].setFundName("Long-Term Bond");

funds[3].setFundName("Short-Term Bond");

funds[4].setFundName("500 Index Fund");

funds[5].setFundName("Capital Value Fund");

funds[6].setFundName("Growth Equity Fund");

funds[7].setFundName("Growth Index Fund");

funds[8].setFundName("Value Fund");

funds[9].setFundName("Value Stock Index");

}

Account::~Account()

{

}

string Account::getFirstName() const

{

return firstName;

}

string Account::getLastName() const

{

return lastName;

}

int Account::getID() const

{

return ID;

}

FundType* Account::getFund(const int &fundNum)

{

return &funds[fundNum];

}

int Account::getFundBalance(int fundNum)

{

return funds[fundNum].getBalance();

}

void Account::setFirstName(const string &incFName)

{

firstName = incFName;

return;

}

void Account::setLastName(const string &incLName)

{

lastName = incLName;

return;

}

void Account::setID(const int &incID)

{

ID = incID;

return;

}

void Account::DisplayAllFund() const

{

cout << this->getFirstName() << " " << this->getLastName() << " Account ID: " << this->getID() << endl;

cout << "    Money Market: $" << funds[0].getBalance() << endl;

cout << "    Prime Money Market: $" << funds[1].getBalance() << endl;

cout << "    Long-Term Bond: $" << funds[2].getBalance() << endl;

cout << "    Short-Term Bond: $" << funds[3].getBalance() << endl;

cout << "    500 Index Fund: $" << funds[4].getBalance() << endl;

cout << "    Capital Value Fund: $" << funds[5].getBalance() << endl;

cout << "    Growth Equity Fund: $" << funds[6].getBalance() << endl;

cout << "    Growth Index Fund: $" << funds[7].getBalance() << endl;

cout << "    Value Fund: $" << funds[8].getBalance() << endl;

cout << "    Value Stock Index; $" << funds[9].getBalance() << endl;

cout << endl;

}

void Account::DisplayFund(const int &incFundType) const

{

switch (incFundType)

{

case 0:

cout << "Money Market: " << funds[0].getBalance() << endl;

break;

case 1:

cout << "Prime Money Market: " << funds[1].getBalance() << endl;

break;

case 2:

cout << "Long-Term Bond: " << funds[2].getBalance() << endl;

break;

case 3:

cout << "Short-Term Bond: " << funds[3].getBalance() << endl;

break;

case 4:

cout << "500 Index Fund: " << funds[4].getBalance() << endl;

break;

case 5:

cout << "Capital Value Fund: " << funds[5].getBalance() << endl;

break;

case 6:

cout << "Growth Equity Fund: " << funds[6].getBalance() << endl;

break;

case 7:

cout << "Growth Index Fund: " << funds[7].getBalance() << endl;

break;

case 8:

cout << "Value Fund: " << funds[8].getBalance() << endl;

break;

case 9:

cout << "Value Stock Index; " << funds[9].getBalance() << endl;

break;

default:

cout << "Assinged Unknown Fund Type" << endl;

}

}

ostream& operator<<(ostream &outStream, const Account &rhs)

{

outStream << rhs.ID << ", " << rhs.firstName << ", " << rhs.lastName << endl;

return outStream;

}

bool Account::operator==(const Account &rhs) const

{

return ((this->ID) == (rhs.ID));

}

bool Account::operator!=(const Account &rhs) const

{

return !(*this == rhs);

}

bool Account::operator>(const Account &rhs) const

{

return ((this->ID) > (rhs.ID));

}

bool Account::operator<(const Account &rhs) const

{

return ((this->ID) < (rhs.ID));

}

-------------------

//Account.h

#ifndef ACCOUNT_H

#define ACCOUNT_H

#include "FundType.h"

#include <iostream>

#include <vector>

#include <string>

using namespace std;

const int TOTAL_TYPES_OF_FUND = 10;

class Account

{

friend ostream& operator<<(ostream &outStream, const Account &rhs);

public:

Account();

Account(string incLastName, string incFirstName, int incId);

~Account();

string getFirstName() const;

string getLastName() const;

int getID() const;

FundType* getFund(const int &fundNum);

int getFundBalance(int fundNum);

void setFirstName(const string &incFirstName);

void setLastName(const string &incLastName);

void setID(const int &incID);

void DisplayAllFund() const;

void DisplayFund(const int &fund) const;

bool operator==(const Account &rhs) const;

bool operator!=(const Account &rhs) const;

bool operator>(const Account &rhs) const;

bool operator<(const Account &rhs) const;

private:

string firstName;

string lastName;

int ID;

FundType funds[TOTAL_TYPES_OF_FUND];

};

#endif

---------------------

//BSTree.cpp

#include "BSTree.h"

BSTree::BSTree()

{

}

BSTree::~BSTree()

{

Empty();

}

bool BSTree::Insert(Account *incAcct)

{

if (root == NULL)

{

Node *createdNode = new Node();

createdNode->pAcct = new Account(*incAcct);

createdNode->left = createdNode->right = NULL;

root = createdNode;

return true;

}

else

{

return insertHelper(this->root, incAcct);

}

return false;

}

bool BSTree::Retrieve(const int &targetId, Account *&incAcct) const

{

return retrieveHelper(this->root, targetId, incAcct);

}

void BSTree::Display() const

{

displayHelper(root);

return;

}

void BSTree::Empty()

{

emptyHelper(this->root);

root = NULL;

return;

}

bool BSTree::isEmpty() const

{

return (root == NULL);

}

bool BSTree::insertHelper(Node *incNode, Account *incAcct)

{

if (incAcct->getID() == incNode->pAcct->getID())

{

cerr << "ERROR: Account " << incNode->pAcct->getID() << " is already open. Transaction refused." << endl;

return false;

}

else if (incAcct->getID() < incNode->pAcct->getID())

{

if (incNode->left == NULL)

{

Node *createdNode = new Node();

createdNode->pAcct = new Account(*incAcct);

incNode->left = createdNode;

incNode->left->left = incNode->left->right = NULL;

return true;

}

else

{

return insertHelper(incNode->left, incAcct);

}

}

else if (incAcct->getID() > incNode->pAcct->getID())

{

if (incNode->right == NULL)

{

Node *createdNode = new Node();

createdNode->pAcct = new Account(*incAcct);

incNode->right = createdNode;

incNode->right->left = incNode->right->right = NULL;

return true;

}

else

{

return insertHelper(incNode->right, incAcct);

}

}

else

{

return false;

}

}

bool BSTree::retrieveHelper(const Node *incNode, const int &targetId, Account * &incAcct) const

{

if (incNode == NULL)

{

return false;

}

else if (targetId == incNode->pAcct->getID())

{

incAcct = incNode->pAcct;

return true;

}

else if (targetId < incNode->pAcct->getID())

{

retrieveHelper(incNode->left, targetId, incAcct);

}

else

{

retrieveHelper(incNode->right, targetId, incAcct);

}

}

void BSTree::displayHelper(Node *incNode) const

{

if (incNode == NULL)

{

return;

}

displayHelper(incNode->left);

incNode->pAcct->DisplayAllFund();

displayHelper(incNode->right);

}

void BSTree::emptyHelper(Node *incNode)

{

if (incNode == NULL)

{

return;

}

emptyHelper(incNode->left);

emptyHelper(incNode->right);

delete incNode->pAcct;

incNode->pAcct = NULL;

delete incNode;

incNode = NULL;

return;

}

----------------------

//BSTree.h

#ifndef BSTREE_H

#define BSTREE_H

#include "Account.h"

#include <iostream>

using namespace std;

class BSTree

{

public:

BSTree();

~BSTree();

bool Insert(Account *);

bool Retrieve(const int &, Account *&) const;

void Display() const;

void Empty();

bool isEmpty() const;

private:

struct Node

{

Account *pAcct = NULL;

Node *right = NULL;

Node *left = NULL;

};

Node *root = NULL;

bool insertHelper(Node *incNode, Account *incAcct);

bool retrieveHelper(const Node *incNode, const int &targetId, Account *&incAcct) const;

void displayHelper(Node *incNode) const;

void emptyHelper(Node *incNode);

};

#endif

----------------

//Bank.cpp

#include "Bank.h"

Bank::Bank()

{

}

Bank::~Bank()

{

}

void Bank::ReadTxtFile(string file)

{

ifstream inFile;

inFile.open(file);

if (inFile.is_open())

{

while (!inFile.eof())

{

Transaction Request;

inFile >> Request;

requestList.push(Request);

}

inFile.close();

return;

}

else

{

cerr << "Error occurred in read in text file!!!" << endl;

return;

}

}

void Bank::ProceedQue()

{

while (requestList.size() != 0)

{

string curTransactionType = requestList.front().getTransactionType();

if (curTransactionType == "O")

{

openAccount(requestList.front());

}

if (curTransactionType == "D")

{

deposit(requestList.front());

}

if (curTransactionType == "W")

{

withdraw(requestList.front());

}

if (curTransactionType == "T")

{

transfer(requestList.front());

}

if (curTransactionType == "H")

{

history(requestList.front());

}

requestList.pop();

}

return;

}

void Bank::DisplayAllAccount() const

{

cout << endl;

cout << "Processing Done. Final Balances " << endl;

this->acctInfoTree.Display();

return;

}

bool Bank::openAccount(Transaction &incTransaction)

{

Account *curAcct = NULL;

int curMainAcctID = incTransaction.getMainAcctID();

bool acctAvailable = acctInfoTree.Retrieve(curMainAcctID, curAcct);

if (acctAvailable)

{

cerr << "ERROR: Account " << curMainAcctID << " is already opened. Opening account refused." << endl;

return false;

}

else

{

if (incTransaction.getMainAcctID() >= 1000 && incTransaction.getMainAcctID() <= 9999)

{

Account createdAccount(incTransaction.getLastName(), incTransaction.getFirstName(), incTransaction.getMainAcctID());

this->acctInfoTree.Insert(&createdAccount);

return true;

}

else

{

cerr << "ERROR: Account ID have to be 4 digit. Opening account refused." << endl;

return false;

}

}

}

bool Bank::deposit(Transaction &incTransaction)

{

Account *curAcct = NULL;

int curMainAcctID = incTransaction.getMainAcctID();

int curMainFundTypeID = incTransaction.getMainFundTypeID();

bool acctAvailable = acctInfoTree.Retrieve(curMainAcctID, curAcct);

if (acctAvailable && incTransaction.getAmount() >= 0 && incTransaction.getMainFundTypeID() >= 0)

{

curAcct->getFund(incTransaction.getMainFundTypeID())->Deposit(incTransaction.getAmount());

curAcct->getFund(incTransaction.getMainFundTypeID())->AddHistory(incTransaction);

return true;

}

else

{

if (incTransaction.getAmount() < 0)

{

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

cerr << "ERROR: $" << incTransaction.getAmount() << " is not possible amount to make transaction. Deposit refused. " << endl;

return false;

}

else if (incTransaction.getMainFundTypeID() < 0)

{

cerr << "ERROR: Fund ID have not been found. Deposit refused." << endl;

return false;

}

else

{

cerr << "ERROR: Account " << curMainAcctID << " was not found. Deposit refused. " << endl;

return false;

}

}

}

bool Bank::withdraw(Transaction &incTransaction)

{

Account *curAcct = NULL;

int curMainAcctID = incTransaction.getMainAcctID();

int curMainFundTypeID = incTransaction.getMainFundTypeID();

bool acctAvailable = acctInfoTree.Retrieve(curMainAcctID, curAcct);

if (acctAvailable && incTransaction.getAmount() >= 0 && incTransaction.getMainFundTypeID() >= 0)

{

if (curAcct->getFund(curMainFundTypeID)->getBalance() < incTransaction.getAmount())

{

if (curMainFundTypeID == 0 || curMainFundTypeID == 2)

{

int sumTwoBalance = curAcct->getFund(curMainFundTypeID)->getBalance() + curAcct->getFund(curMainFundTypeID + 1)->getBalance();

int remainAmount = incTransaction.getAmount() - curAcct->getFund(curMainFundTypeID)->getBalance();

if (sumTwoBalance < incTransaction.getAmount())

{

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

cerr << "ERROR: Not enough fund to Withdraw " << incTransaction.getAmount() << " from " << curAcct->getFund(curMainFundTypeID)->getFundName() << "." << endl;

return false;

}

else

{

curAcct->getFund(curMainFundTypeID)->setBalance(0);

curAcct->getFund(curMainFundTypeID + 1)->Withdraw(remainAmount);

incTransaction.setAmount(incTransaction.getAmount() - remainAmount);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

incTransaction.setAmount(remainAmount);

incTransaction.setMainFundTypeID(incTransaction.getMainFundTypeID() + 1);

curAcct->getFund(curMainFundTypeID + 1)->AddHistory(incTransaction);

return true;

}

}

else if (curMainFundTypeID == 1 || curMainFundTypeID == 3)

{

int sumTwoBalance = curAcct->getFund(curMainFundTypeID)->getBalance() + curAcct->getFund(curMainFundTypeID - 1)->getBalance();

int remainAmount = incTransaction.getAmount() - curAcct->getFund(curMainFundTypeID)->getBalance();

if (sumTwoBalance < incTransaction.getAmount())

{

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

cerr << "ERROR: Not enough fund to Withdraw " << incTransaction.getAmount() << " from " << curAcct->getFund(curMainFundTypeID)->getFundName() << "." << endl;

return false;

}

else

{

curAcct->getFund(curMainFundTypeID)->setBalance(0);

curAcct->getFund(curMainFundTypeID - 1)->Withdraw(remainAmount);

incTransaction.setAmount(incTransaction.getAmount() - remainAmount);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

incTransaction.setAmount(remainAmount);

incTransaction.setMainFundTypeID(incTransaction.getMainFundTypeID() - 1);

curAcct->getFund(curMainFundTypeID - 1)->AddHistory(incTransaction);

return true;

}

}

else

{

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

cerr << "ERROR: Not enough fund to Withdraw " << incTransaction.getAmount() << " from " << curAcct->getFund(curMainFundTypeID)->getFundName() << "." << endl;

return false;

}

}

else

{

curAcct->getFund(curMainFundTypeID)->Withdraw(incTransaction.getAmount());

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

return true;

}

}

else

{

if (incTransaction.getAmount() < 0)

{

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

cerr << "ERROR: $" << incTransaction.getAmount() << " is not possible amount to make transaction. Witdraw refused. " << endl;

return false;

}

else if (incTransaction.getMainFundTypeID() < 0)

{

cerr << "ERROR: Fund ID have not been found. Withdraw refused." << endl;

return false;

}

else

{

cerr << "ERROR: Account " << curMainAcctID << " was not found. Withdraw refused. " << endl;

return false;

}

}

}

bool Bank::transfer(Transaction &incTransaction)

{

Account *curAcct = NULL;

Account *curSecondAcct = NULL;

int curMainAcctID = incTransaction.getMainAcctID();

int curMainFundTypeID = incTransaction.getMainFundTypeID();

int curSecondAcctID = incTransaction.getSecondAcctID();

int curSecondFundTypeID = incTransaction.getSecondFundTypeID();

bool acctAvailable = acctInfoTree.Retrieve(curMainAcctID, curAcct);

bool secondAcctAvailable = acctInfoTree.Retrieve(curSecondAcctID, curSecondAcct);

int remainAmount = incTransaction.getAmount() - curAcct->getFund(curMainFundTypeID)->getBalance();

if (acctAvailable && secondAcctAvailable && (incTransaction.getAmount() > 0) && (incTransaction.getMainFundTypeID() >= 0))

{

if (curAcct->getFund(curMainFundTypeID)->getBalance() < incTransaction.getAmount())

{

if (curMainFundTypeID == 0 || curMainFundTypeID == 2)

{

if (remainAmount < (curAcct->getFund(curMainFundTypeID + 1)->getBalance()))

{

curAcct->getFund(curMainFundTypeID)->Withdraw(incTransaction.getAmount() - remainAmount);

curAcct->getFund(curMainFundTypeID + 1)->Withdraw(remainAmount);

curSecondAcct->getFund(curSecondFundTypeID)->Deposit(incTransaction.getAmount());

incTransaction.setAmount(incTransaction.getAmount() - remainAmount);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

incTransaction.setAmount(remainAmount);

incTransaction.setMainFundTypeID(incTransaction.getMainFundTypeID() + 1);

curAcct->getFund(curMainFundTypeID + 1)->AddHistory(incTransaction);

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

return true;

}

}

else if (curMainFundTypeID == 1 || curMainFundTypeID == 3)

{

if ((remainAmount < (curAcct->getFund(curMainFundTypeID - 1)->getBalance())))

{

curAcct->getFund(curMainFundTypeID)->Withdraw(incTransaction.getAmount() - remainAmount);

curAcct->getFund(curMainFundTypeID - 1)->Withdraw(remainAmount);

curSecondAcct->getFund(curSecondFundTypeID)->Deposit(incTransaction.getAmount());

incTransaction.setAmount(incTransaction.getAmount() - remainAmount);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

incTransaction.setAmount(remainAmount);

incTransaction.setMainFundTypeID(incTransaction.getMainFundTypeID() - 1);

curAcct->getFund(curMainFundTypeID - 1)->AddHistory(incTransaction);

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

return true;

}

}

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

if (curMainAcctID != curSecondAcctID)

{

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

}

cerr << "ERROR: Account ID " << curMainAcctID << " " << curAcct->getFund(curMainFundTypeID)->getFundName()

<< " have insufficient balance to make Transfer to Account ID " << curSecondAcctID << " "

<< curAcct->getFund(curSecondFundTypeID)->getFundName() << ". Transfer refused." << endl;

return false;

}

else

{

curAcct->getFund(curMainFundTypeID)->Withdraw(incTransaction.getAmount());

curSecondAcct->getFund(curSecondFundTypeID)->Deposit(incTransaction.getAmount());

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

if (curMainAcctID != curSecondAcctID)

{

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

}

else if (curMainFundTypeID != curSecondFundTypeID)

{

curAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

}

return true;

}

}

else

{

if (incTransaction.getAmount() < 0)

{

incTransaction.setValidTrans(false);

curAcct->getFund(curMainFundTypeID)->AddHistory(incTransaction);

if (curMainAcctID != curSecondAcctID)

{

curSecondAcct->getFund(curSecondFundTypeID)->AddHistory(incTransaction);

}

cerr << "ERROR: $" << incTransaction.getAmount() << " is not possible amount to make transaction. Transfer refused. " << endl;

return false;

}

else if (incTransaction.getMainFundTypeID() < 0 || incTransaction.getSecondFundTypeID() < 0)

{

cerr << "ERROR: Fund ID have not been found. Transfer refused." << endl;

return false;

}

else if (!acctAvailable)

{

cerr << "ERROR: Account " << curMainAcctID << " was not found. Transfer refused. " << endl;

return false;

}

else

{

cerr << "ERROR: Account " << curSecondAcctID << " was not found. Transfer refused. " << endl;

return false;

}

}

}

bool Bank::history(Transaction &incTransaction)

{

Account *curAcct = NULL;

int curMainAcctID = incTransaction.getMainAcctID();

int curMainFundTypeID = incTransaction.getMainFundTypeID();

bool acctAvailable = acctInfoTree.Retrieve(curMainAcctID, curAcct);

if (acctAvailable)

{

if (curMainFundTypeID < 0)

{

cout << "Transaction History for " << curAcct->getFirstName() << " " << curAcct->getLastName() << " by fund." << endl;

for (int j = 0; j < TOTAL_TYPES_OF_FUND; j++)

{

if (!(curAcct->getFund(j)->isHistoryEmpty()))

{

cout << curAcct->getFund(j)->getFundName() << ": $" << curAcct->getFundBalance(j) << endl;

curAcct->getFund(j)->DisplayHistory();

}

}

return true;

}

else

{

cout << "Transaction History for " << curAcct->getFirstName() << " " << curAcct->getLastName()

<< " " << curAcct->getFund(curMainFundTypeID)->getFundName() << ": $" << curAcct->getFundBalance(curMainFundTypeID) << endl;

curAcct->getFund(curMainFundTypeID)->DisplayHistory();

return true;

}

}

else

{

cerr << "ERROR: Account " << curMainAcctID << " was not found. Process history refused. " << endl;

return false;

}

}

---------------------

//Bank.h

#ifndef BANK_H

#define BANK_H

#include "BSTree.h"

#include "Account.h"

#include "Transaction.h"

#include <iostream>

#include <fstream>

#include <queue>

using namespace std;

class Bank

{

public:

Bank();

~Bank();

void ReadTxtFile(string fileName);

void ProceedQue();

void DisplayAllAccount() const;

private:

queue<Transaction> requestList;

BSTree acctInfoTree;

bool openAccount(Transaction &incTransaction);

bool deposit(Transaction &incTransaction);

bool withdraw(Transaction &incTransaction);

bool transfer(Transaction &incTransaction);

bool history(Transaction &incTransaction);

};

#endif

----------------

//FundType.cpp

#include "FundType.h"

FundType::FundType()

{

fundName = "";

balance = 0;

}

FundType::FundType(string incFundName, int incBalance)

{

fundName = incFundName;

balance = incBalance;

}

FundType::~FundType()

{

}

string FundType::getFundName() const

{

return fundName;

}

int FundType::getBalance() const

{

return balance;

}

void FundType::setFundName(const string& incFunName)

{

fundName = incFunName;

return;

}

void FundType::setBalance(const int& incBalance)

{

balance = incBalance;

return;

}

void FundType::Deposit(const int &incAmount)

{

balance += incAmount;

return;

}

void FundType::Withdraw(const int &incAmount)

{

balance -= incAmount;

return;

}

void FundType::AddHistory(const Transaction &incTransaction)

{

history.push_back(incTransaction);

return;

}

void FundType::DisplayHistory() const

{

for (int i = 0; i < history.size(); i++)

{

cout << " " << history[i];

if (history[i].getValidTrans() == false)

{

cout << " (Failed)";

}

cout << endl;

}

return;

}

bool FundType::isHistoryEmpty() const

{

return !(history.size() > 0);

}

ostream& operator<<(ostream &outStream, const FundType &rhs)

{

outStream << rhs.getFundName() << ": $" << rhs.getBalance();

return outStream;

}

------------------

//FundType.h

#ifndef FUND_TYPE_H

#define FUND_TYPE_H

#include "Transaction.h"

#include <iostream>

#include <string>

#include <vector>

using namespace std;

class FundType

{

friend ostream& operator<<(ostream &outStream, const FundType &rhs);

public:

FundType();

FundType(string incFundName, int incBalance);

~FundType();

string getFundName() const;

int getBalance() const;

bool isHistoryEmpty() const;

void setFundName(const string& incFunName);

void setBalance(const int& incBalance);

void Deposit(const int &incAmount);

void Withdraw(const int &incAmount);

void AddHistory(const Transaction &incHistory);

void DisplayHistory() const;

private:

string fundName;

int balance;

vector<Transaction> history;

};

#endif

-------------------------

//Transaction.cpp

#include "Transaction.h"

Transaction::Transaction()

{

transactionType = "";

firstName = "";

lastName = "";

amount = 0;

mainAcctID = 0;

secondAcctID = 0;

mainFundTypeID = 0;

secondFundTypeID = 0;

validTrans = true;

}

Transaction::~Transaction()

{

}

string Transaction::getTransactionType() const

{

return transactionType;

}

string Transaction::getFirstName() const

{

return firstName;

}

string Transaction::getLastName() const

{

return lastName;

}

int Transaction::getMainAcctID() const

{

return mainAcctID;

}

int Transaction::getSecondAcctID() const

{

return secondAcctID;

}

int Transaction::getMainFundTypeID() const

{

return mainFundTypeID;

}

int Transaction::getSecondFundTypeID() const

{

return secondFundTypeID;

}

int Transaction::getAmount() const

{

return amount;

}

bool Transaction::getValidTrans() const

{

return validTrans;

}

void Transaction::setTransactionType(const string &incType)

{

transactionType = incType;

return;

}

void Transaction::setFirstName(const string &incFirstName)

{

firstName = incFirstName;

return;

}

void Transaction::setLastName(const string &incLastName)

{

lastName = incLastName;

return;

}

void Transaction::setMainAcctID(const int &incAcctID)

{

mainAcctID = incAcctID;

return;

}

void Transaction::setSecondAcctID(const int &incAcctID)

{

secondAcctID = incAcctID;

return;

}

void Transaction::setMainFundTypeID(const int &incFundID)

{

mainFundTypeID = incFundID;

return;

}

void Transaction::setSecondFundTypeID(const int &incFundID)

{

secondFundTypeID = incFundID;

return;

}

void Transaction::setAmount(const int &incAmount)

{

amount = incAmount;

return;

}

void Transaction::setValidTrans(const bool &incFact)

{

validTrans = incFact;

return;

}

ostream &operator<<(ostream &outStream, const Transaction &rhs)

{

if (rhs.getTransactionType() == "D" || rhs.getTransactionType() == "W")

{

outStream << rhs.getTransactionType() << " " << rhs.getMainAcctID() << rhs.getMainFundTypeID() << " " << rhs.getAmount();

}

else if (rhs.getTransactionType() == "T")

{

outStream << "T " << rhs.getMainAcctID() << rhs.getMainFundTypeID() << " " << rhs.getAmount() << " "

<< rhs.getSecondAcctID() << rhs.getSecondFundTypeID();

}

return outStream;

}

istream &operator>>(istream &inStream, Transaction &rhs)

{

string newTranType;

inStream >> newTranType;

rhs.transactionType = newTranType;

int fromAcctID = 0;

int toAcctID = 0;

if (newTranType == "O")

{

inStream >> rhs.lastName >> rhs.firstName >> rhs.mainAcctID;

}

else if (newTranType == "D" || newTranType == "W")

{

inStream >> fromAcctID >> rhs.amount;

if (fromAcctID >= 10000 && fromAcctID <= 99999)

{

rhs.mainAcctID = fromAcctID / 10;

rhs.mainFundTypeID = fromAcctID % 10;

}

else

{

rhs.mainAcctID = fromAcctID;

rhs.mainFundTypeID = -1;

}

}

else if (newTranType == "T")

{

inStream >> fromAcctID >> rhs.amount >> toAcctID;

if (fromAcctID >= 10000 && fromAcctID <= 99999)

{

rhs.mainAcctID = fromAcctID / 10;

rhs.mainFundTypeID = fromAcctID % 10;

}

else

{

rhs.mainAcctID = fromAcctID;

rhs.mainFundTypeID = -1;

}

if (toAcctID >= 10000 && toAcctID <= 99999)

{

rhs.secondAcctID = toAcctID / 10;

rhs.secondFundTypeID = toAcctID % 10;

}

else

{

rhs.secondAcctID = toAcctID;

rhs.mainFundTypeID = -1;

}

}

else if (newTranType == "H")

{

inStream >> fromAcctID;

if (fromAcctID >= 10000 && fromAcctID <= 99999)

{

rhs.mainAcctID = fromAcctID / 10;

rhs.mainFundTypeID = fromAcctID % 10;

}

else

{

rhs.mainAcctID = fromAcctID;

rhs.mainFundTypeID = -1;

}

}

return inStream;

}

-----------------------

//Transaction.h

#ifndef TRANSACTION_H

#define TRANSACTION_H

#include <iostream>

#include <vector>

#include <string>

using namespace std;

class Transaction

{

friend ostream &operator<<(ostream &outStream, const Transaction &rhs);

friend istream &operator>>(istream &inStream, Transaction &rhs);

public:

Transaction();

~Transaction();

string getTransactionType() const;

string getFirstName() const;

string getLastName() const;

int getMainAcctID() const;

int getSecondAcctID() const;

int getMainFundTypeID() const;

int getSecondFundTypeID() const;

int getAmount() const;

bool getValidTrans() const;

void setTransactionType(const string &incType);

void setFirstName(const string &incFirstName);

void setLastName(const string &incLastName);

void setMainAcctID(const int &incAcctID);

void setSecondAcctID(const int &incAcctID);

void setMainFundTypeID(const int &incFundID);

void setSecondFundTypeID(const int &incFundID);

void setAmount(const int &incAmount);

void setValidTrans(const bool &incFact);

private:

string transactionType;

string firstName;

string lastName;

int mainAcctID;

int secondAcctID;

int mainFundTypeID;

int secondFundTypeID;

int amount;

bool validTrans;

};

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote