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

Need comments added to code please. //Accounts.cpp #include <iostream> #include

ID: 666408 • Letter: N

Question

Need comments added to code please.

//Accounts.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include "certificateOfDeposit.h"
#include "highInterestChecking.h"
#include "highInterestSavings.h"
#include "serviceChargeChecking.h"

using namespace std;

void TestCheckingWithService()
{
serviceChargeChecking acct(123,"John Doe", 1000);

char input=0;
double amount;
cout << " Testing Checking with Service Charge" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "5 - Write a check" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':
      acct.printSummary();
      break;
    case '4':
      acct.printStatement();
      break;
    case '5':
      cout << "Enter amount: ";
      cin >> amount;
      acct.writeCheck(amount);
      break;
    case '6':
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }
    acct.printSummary();
    cout << endl;
}
}

void TestCheckingNoService()
{
noServiceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing Checking without Service Charge" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "5 - Write a check" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':
      acct.printSummary();
      break;
    case '4':
      acct.printStatement();
      break;
    case '5':
      cout << "Enter amount: ";
      cin >> amount;
      acct.writeCheck(amount);
      break;
    case '6':
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }
    acct.printSummary();
    cout << endl;
}

}

void TestCheckingHighInterest()
{
highInterestChecking acct(123,"John Doe", 1000);

char input=0;
double amount;
cout << " Testing Checking with High Interest" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "5 - Write a check" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':
      acct.printSummary();
      break;
    case '4':
      acct.printStatement();
      break;
    case '5':
      cout << "Enter amount: ";
      cin >> amount;
      acct.writeCheck(amount);
      break;
    case '6':
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }
    acct.printSummary();
    cout << endl;
}
}

void TestSavings()
{
savingsAccount acct(123,"John Doe", 1000);

char input=0;
double amount;
cout << " Testing Regular Savings" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':
      acct.printSummary();
      break;
    case '4':
      acct.printStatement();
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }
    acct.printSummary();
    cout << endl;
}
}

void TestSavingsHighInterest()
{
highInterestSavings acct(123,"John Doe", 8000);

char input=0;
double amount;
cout << " Testing High Interest Savings" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':
      acct.printSummary();
      break;
    case '4':
      acct.printStatement();
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }
    acct.printSummary();
    cout << endl;
}
}

void TestCertificateOfDeposit()
{
certificateOfDeposit acct(123,"John Doe", 10000, 6);

char input=0;
double amount;
cout << " Testing High Interest Savings" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':
      acct.printSummary();
      break;
    case '4':
      acct.printStatement();
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }
    acct.printSummary();
    cout << endl;
}
}

int main()
{
char input;
cout << " Welcome to the Bank Account Test Suite" << endl << endl;

cout << "What type of account do you want to test?" << endl;
cout << "1 - Checking with Service Charge" << endl;
cout << "2 - Checking without Service Charge" << endl;
cout << "3 - Checking with High Interest" << endl;
cout << "4 - Savings" << endl;
cout << "5 - Savings with High Interest" << endl;
cout << "6 - Certificate of Deposit" << endl;
cout << "Enter choice: ";
cin >> input;

switch (input)
{
case '1':
    TestCheckingWithService();
    break;
case '2':
    TestCheckingNoService();
    break;
case '3':
    TestCheckingHighInterest();
    break;
case '4':
    TestSavings();
    break;
case '5':
    TestSavingsHighInterest();
    break;
case '6':
    TestCertificateOfDeposit();
    break;
default:
    cout << "Invalid choice" << endl;
    break;
}
}

//bankAccount.h

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class bankAccount
{
public:
bankAccount(int acctNum, string name, double initialBalance)
{
    m_AcctNumber = acctNum;
    m_Name = name;
    m_Balance = initialBalance;
}

~bankAccount(void){}

string get_Name()
{
    return m_Name;
}

int get_AcctNumber()
{
    return m_AcctNumber;
}

double get_Balance()
{
    return m_Balance;
}

void deposit(double amount)
{
    m_Balance += amount;
    cout << "$" << amount << " has been deposited to your account" << endl;
}

virtual void withdraw(double amount) = 0;
virtual void printStatement() = 0;
virtual void printSummary()
{
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
    cout << endl << setw(25) << "" << "Account Summary" << endl << endl;
    cout << setw(25) << "Name: " << m_Name << endl;
    cout << setw(25) << "Account #: " << m_AcctNumber << endl;
    cout << setw(25) << "Current Balance: $" << m_Balance << endl;
}

protected:
string m_Name;
int m_AcctNumber;
double m_Balance;
};

//certificateOfDeposit.h

#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"

using namespace std;

class certificateOfDeposit :
public bankAccount
{
public:
certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon)
    : bankAccount(acctNum, name, initialBalance)
{
    m_MaturityMonths = matMon;
    m_CurrentMonth = 1;
    m_InterestRate = 4.75;
}

~certificateOfDeposit(void){}

void withdraw(double amount)
{
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }
    m_Balance -= amount;
}

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();
    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl ;
    cout << setw(25) << "Maturity Months: " << m_MaturityMonths << endl ;
    cout << setw(25) << "Current Month: " << m_CurrentMonth << endl;
    cout << endl << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}

void printStatement()
{
    printSummary();
    cout << "A full implementation would also print a Certificate of Deposite Account Statement here." << endl;
}

private:
double m_InterestRate;
int m_MaturityMonths;
int m_CurrentMonth;
};

//checkingAccount.h

#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"

using namespace std;

class checkingAccount :
public bankAccount
{
public:
checkingAccount(int acctNum, string name, double initialBalance)
    : bankAccount(acctNum, name, initialBalance)
{
}
~checkingAccount(void){}

virtual void writeCheck(double amount) = 0;

void withdraw(double amount)
{
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }
    if (m_Balance - amount < m_MinimumBalance)
    {
      cout << "Declined: Minimum balance requirement prohibits this withdrawal" << endl;
      return;
    }
    m_Balance -= amount;
}

void printStatement()
{
    printSummary();
    cout << endl << "A full implementation would also print details of a Checking Account Statement here." << endl << endl;
}

protected:
double m_InterestRate;
int m_ChecksRemaining;
double m_MinimumBalance;
};

//highInterestChecking.h

#include <iostream>
#include <iomanip>
#include <string>
#include "noServiceChargeChecking.h"

using namespace std;

class highInterestChecking :
public noServiceChargeChecking
{
public:
highInterestChecking(int acctNum, string name, double initialBalance)
    : noServiceChargeChecking(acctNum, name, initialBalance)
{
    // The only difference between the base class noServiceChargeChecking
    // is the values of interest and minimum balance.
    // So no additional functionality needed for this one.

    m_InterestRate = 5.0; // Higher interest rate
    m_ChecksRemaining = -1; // -1 indicates no limit
    m_MinimumBalance = 1000; // Minimum balance
}

~highInterestChecking(void){}
};

//highInterestSavings.h

#include <iostream>
#include <iomanip>
#include <string>
#include "savingsAccount.h"

using namespace std;

class highInterestSavings :
public savingsAccount
{
public:
highInterestSavings(int acctNum, string name, double initialBalance)
    : savingsAccount(acctNum, name, initialBalance)
{
    m_MinimumBalance = 5000;
}

~highInterestSavings(void){}

void withdraw(double amount)
{
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

    if (m_Balance - amount < m_MinimumBalance)
    {
      cout << "Declined: Minimum balance requirement prohibits this withdrawal" << endl;
      return;
    }

    m_Balance -= amount;
}

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();

    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl;
    cout << setw(25) << "Minimum Balance: $" << m_MinimumBalance << endl << endl;
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}


protected:
double m_MinimumBalance;

};

//noServiceChargeChecking.h

#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"

using namespace std;

class noServiceChargeChecking :
public checkingAccount
{
public:
noServiceChargeChecking(int acctNum, string name, double initialBalance)
    : checkingAccount(acctNum, name, initialBalance)
{
    m_InterestRate = 2.5; // Some interest rate
    m_ChecksRemaining = -1; // -1 indicates no limit
    m_MinimumBalance = 500; // Minimum balance

}

~noServiceChargeChecking(void){}

void writeCheck(double amount)
{
    if (m_Balance - amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

    m_Balance -= amount; // Assume check is cashed immediately...
}

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();
    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl;
    cout << setw(25) << "Minimum Balance: $" << m_MinimumBalance << endl;
    cout << setw(25) << "Unlimited checks   " << endl;
    cout << setw(25) << "No monthly service fee   "<< endl;
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}

};

//savingsAccount.h

#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"

using namespace std;

class savingsAccount :
public bankAccount
{
public:
savingsAccount(int acctNum, string name, double initialBalance)
    : bankAccount(acctNum, name, initialBalance)
{
    m_InterestRate = 3.99;
}

~savingsAccount(void)
{
}

void withdraw(double amount)
{
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }
    m_Balance -= amount;
}

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();
    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl << endl;
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}

void printStatement()
{
    printSummary();
    cout << "A full implementation would also print a Savings Account Statement here." << endl;
}


protected:
double m_InterestRate;

};

//serviceChargeChecking.h

#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"

using namespace std;

const int MAX_CHECKS=5;
const double SVC_CHARGE=10.0l;

class serviceChargeChecking :
public checkingAccount
{
public:
serviceChargeChecking(int acctNum, string name, double initialBalance)
    : checkingAccount(acctNum, name, initialBalance)
{
    m_InterestRate = 0; // No interest
    m_ChecksRemaining = MAX_CHECKS; // Limit of 5 checks
    m_MinimumBalance = 0; // No minimum balance
}

~serviceChargeChecking(void){}

void writeCheck(double amount)
{
    if (m_ChecksRemaining == 0)
    {
      cout << "Declined: No more checks remaining this month" << endl;
      return;
    }
  
    if (m_Balance - amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

    m_ChecksRemaining--;
    m_Balance -= amount; // Assume check is cashed immediately...

    }

    void printSummary()
    {
      // Use the root base class to print common info
      bankAccount::printSummary();
      cout << setw(25) << "Checks remaining: " << m_ChecksRemaining << endl;
      cout << setw(25) << "Monthly service fee: $" << SVC_CHARGE << endl;
      cout << setw(25) << "No interest " << endl;
      cout << setw(25) << "No Minimum Balance " << endl;
      cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
    }
};

Explanation / Answer

Answer:

/******* CODE WITH COMMENTS*********/

//Accounts.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include "certificateOfDeposit.h"
#include "highInterestChecking.h"
#include "highInterestSavings.h"
#include "serviceChargeChecking.h"

using namespace std;

//FUNCTION PERFORMS OPERATION ON serviceChargeChecking

void TestCheckingWithService()
{

//CREATE serviceChargeChecking OBJECT
serviceChargeChecking acct(123,"John Doe", 1000);

char input=0;
double amount;
cout << " Testing Checking with Service Charge" << endl << endl;

cout << "Current account overview:" << endl;

//PRINT ACCOUNT SUMMARY
acct.printSummary();
cout << endl;

while (input != 'x')
{

/****MENU LIST*******/
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "5 - Write a check" << endl;
    cout << "x - Exit Test Suite" << endl;

/***** SELECT FROM LIST*******/
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':

//WITHDRAW AMOUNT FROM serviceChargeChecking
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':

//DEPOSIT AMOUNT TO serviceChargeChecking
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':

//PRINT THE ACCOUNT SUMMARY
      acct.printSummary();
      break;
    case '4':

//PRINT THE ACCOUNT STATEMENT
      acct.printStatement();
      break;
    case '5':

//WITHDRAW AMOUNT BY USING CHECK LEAFS
      cout << "Enter amount: ";
      cin >> amount;
      acct.writeCheck(amount);
      break;
    case '6':
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }

//PRINT ACCOUNT SUMMARY
    acct.printSummary();
    cout << endl;
}
}

FUNCTION PERFORMS OPERATIONS ON noServiceChargeChecking

void TestCheckingNoService()
{

//CREATE noServiceChargeChecking OBJECT
noServiceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << " Testing Checking without Service Charge" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{

/******MENU LIST********/
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "5 - Write a check" << endl;
    cout << "x - Exit Test Suite" << endl;

//SELECT FROM A MENU
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':

//WITHDRAW AMOUNT FROM noServiceChargeChecking
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':

//DEPOSIT AMOUNT TO noServiceChargeChecking
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':

//PRINT ACCOUNT SUMMARY
      acct.printSummary();
      break;
    case '4':

//PRINT THE ACCOUNT STATEMENT
      acct.printStatement();
      break;
    case '5':

//WITHDRAW AMOUNT BY USING CHECK LEAF
      cout << "Enter amount: ";
      cin >> amount;
      acct.writeCheck(amount);
      break;
    case '6':
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }

//PRINT ACCOUNT SUMMARY
    acct.printSummary();
    cout << endl;
}

}

//FUNCTION THAT TEST THE highInterestChecking ACCOUNT

void TestCheckingHighInterest()
{
//CREATE highInterestChecking OBJECT

highInterestChecking acct(123,"John Doe", 1000);

char input=0;
double amount;
cout << " Testing Checking with High Interest" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{

/******MENU LIST********/
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "5 - Write a check" << endl;
    cout << "x - Exit Test Suite" << endl;

//SELECT FROM A MENU
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':

//WITHDRAW AMOUNT FROM highInterestChecking
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':

//DEPOSIT AMOUNT TO highInterestChecking
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':

//PRINT ACCOUNT SUMMARY
      acct.printSummary();
      break;
    case '4':

//PRINT MONTHLY STATEMENT
      acct.printStatement();
      break;
    case '5':

//WITHDRAW AMOUNT BY USING CHECK LEAF
      cout << "Enter amount: ";
      cin >> amount;
      acct.writeCheck(amount);
      break;
    case '6':
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }

//PRINT ACCOUNT SUMMARY
    acct.printSummary();
    cout << endl;
}
}

//FUNCTION THAT TEST THE savingsAccount ACCOUNT

void TestSavings()
{

//CREATE savingsAccount OBJECT
savingsAccount acct(123,"John Doe", 1000);

char input=0;
double amount;
cout << " Testing Regular Savings" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{

/******MENU LIST********/
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "x - Exit Test Suite" << endl;

//SELECT FROM A MENU
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':

//WITHDRAW AMOUNT FROM savingsAccount
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':

//DEPOSIT AMOUNT TO savingsAccount
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':

//PRINT ACCOUNT SUMMARY
      acct.printSummary();
      break;
    case '4':

//PRINT MONTHLY STATEMENT
      acct.printStatement();
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }

//PRINT ACCOUNT SUMMARY
    acct.printSummary();
    cout << endl;
}
}

//FUNCTION THAT TEST THE highInterestSavings ACCOUNT

void TestSavingsHighInterest()
{

//CREATE highInterestSavings OBJECT
highInterestSavings acct(123,"John Doe", 8000);

char input=0;
double amount;
cout << " Testing High Interest Savings" << endl << endl;

cout << "Current account overview:" << endl;
acct.printSummary();
cout << endl;

while (input != 'x')
{

/******MENU LIST********/
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "x - Exit Test Suite" << endl;

//SELECT FROM A MENU
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':

//WITHDRAW AMOUNT FROM ACCOUNT
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':

//DEPOSIT AMOUNT TO ACCOUNT
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':

//PRINT ACCOUNT SUMMARY
      acct.printSummary();
      break;
    case '4':

//PRINT MONTHLY STATEMENT
      acct.printStatement();
      break;
    case 'x':
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }

//PRINT ACCOUNT SUMMARY
    acct.printSummary();
    cout << endl;
}
}

//FUNCTION THAT TEST THE certificateOfDeposit ACCOUNT

void TestCertificateOfDeposit()
{

//CREATE certificateOfDeposit OBJECT

certificateOfDeposit acct(123,"John Doe", 10000, 6);

char input=0;
double amount;
cout << " Testing High Interest Savings" << endl << endl;

cout << "Current account overview:" << endl;

//PRINT THE ACCOUNT SUMMARY
acct.printSummary();
cout << endl;

while (input != 'x')
{

/****menu list********/
    cout << "Select a transaction:" << endl;
    cout << "1 - Make a Withdrawal" << endl;
    cout << "2 - Make a Deposit" << endl;
    cout << "3 - Print Summary" << endl;
    cout << "4 - Print Monthly Statement" << endl;
    cout << "x - Exit Test Suite" << endl;
    cout << "Enter choice: ";
    cin >> input;

    switch (input)
    {
    case '1':

//withdraw AMOUNT FROM ACCOUNT
      cout << "Enter amount: ";
      cin >> amount;
      acct.withdraw(amount);
      break;
    case '2':

//DEPOSIT AMOUNT TO ACCOUNT
      cout << "Enter amount: ";
      cin >> amount;
      acct.deposit(amount);
      break;
    case '3':

//PRINT THE ACCOUNT SUMMARY
      acct.printSummary();
      break;
    case '4':

//PRINT THE ACCOUNT STATEMENT
      acct.printStatement();
      break;
    case 'x':

//EXIT ROM THE LOOP
      break;
    default:
      cout << "Invalid choice" << endl;
      break;
    }

// PRINT THE ACCOUNT SUMMARY
    acct.printSummary();
    cout << endl;
}
}

/*****MAIN METHOD*******/

int main()
{
char input;

/*******MENU LIST*********/
cout << " Welcome to the Bank Account Test Suite" << endl << endl;

cout << "What type of account do you want to test?" << endl;
cout << "1 - Checking with Service Charge" << endl;
cout << "2 - Checking without Service Charge" << endl;
cout << "3 - Checking with High Interest" << endl;
cout << "4 - Savings" << endl;
cout << "5 - Savings with High Interest" << endl;
cout << "6 - Certificate of Deposit" << endl;

//GET CHOICE FROM THE USER
cout << "Enter choice: ";
cin >> input;

switch (input)
{
case '1':

//CALL TestCheckingWithService() TO PERFORM OPERATION ON CHECKING ACCOUNT WITH SERVICE CHARGE
    TestCheckingWithService();
    break;
case '2':

//CALL TestCheckingNoService() TO PERFORM OPERATION ON CHECKING ACCOUNT WITH NO SERVICE CHARGE
    TestCheckingNoService();
    break;
case '3':

//CALL TestCheckingHighInterest()TO PERFORM OPERATION ON CHECKING ACCOUNT WITH HIGH INTERSET RATE
    TestCheckingHighInterest();
    break;
case '4':

//PERFORMS OPERATIONS ON SAVINGS ACCOUNT i.e. DEPOSIT, WITHDRAWAL
    TestSavings();
    break;
case '5':

//CALL TestSavingsHighInterest()TO PERFORM OPERATION ON SAVINGS ACCOUNT WITH HIGH INTERSET RATE
    TestSavingsHighInterest();
    break;
case '6':
    TestCertificateOfDeposit();
    break;
default:

//INVALID CHOICE
    cout << "Invalid choice" << endl;
    break;
}
}//END MAIN

//bankAccount.h

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//SUPERCLASS bankAccount

class bankAccount
{
public:

//CONSTRUCTOR THAT SETS ACCOUNT NUMBER, NAME , INITIAL BALANCE
bankAccount(int acctNum, string name, double initialBalance)
{
    m_AcctNumber = acctNum;
    m_Name = name;
    m_Balance = initialBalance;
}

//DESTRUCTOR

~bankAccount(void){}

//RETURN ACCOUNT HOLDER NAME

string get_Name()
{
    return m_Name;
}

//RETURN THE ACCOUNT NUMBER

int get_AcctNumber()
{
    return m_AcctNumber;
}

//RETURN THE BALANCE IN THE ACCOUNT NUMBER

double get_Balance()
{
    return m_Balance;
}

//DEPOSIT AMOUNT TO THE ACCOUNT

void deposit(double amount)
{
    m_Balance += amount;
    cout << "$" << amount << " has been deposited to your account" << endl;
}

//VIRTUAL FUNCTION withdraw(double amount)

virtual void withdraw(double amount) = 0;

//VIRTUAL FUNCTION printStatement()
virtual void printStatement() = 0;
//PRINT THE ACCOUNT SUMMARY

virtual void printSummary()
{
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
    cout << endl << setw(25) << "" << "Account Summary" << endl << endl;
    cout << setw(25) << "Name: " << m_Name << endl;
    cout << setw(25) << "Account #: " << m_AcctNumber << endl;
    cout << setw(25) << "Current Balance: $" << m_Balance << endl;
}

//PROTECTED VARIABLES THAT ARE USED BY DERIVED CLASS

protected:

//ACCOUNT HOLDER NAME, ACCOUNT NUMBER, BALANCE
string m_Name;
int m_AcctNumber;
double m_Balance;
};

//CLASS certificateOfDeposit DERIVED FROM bankAccount

//certificateOfDeposit.h

#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"

using namespace std;

class certificateOfDeposit :
public bankAccount
{
public:

//CONSTRUCTOR certificateOfDeposit() SETS THE ACCOUNT HOLDER NAME, ACCOUNT NUMBER, BALANCE USING BASE CLASS CONSTRUCTOR
certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon)
    : bankAccount(acctNum, name, initialBalance)
{
    m_MaturityMonths = matMon;
    m_CurrentMonth = 1;
    m_InterestRate = 4.75;
}

//DESTRUCTOR

~certificateOfDeposit(void){}

//IMPLEMENTING BASE CLASS withdraw(double amount)

void withdraw(double amount)
{

//if m_balace is less than amount , tells the user insufficient balance. Not possible to withdraw
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

//otherwise withdraw amount
    m_Balance -= amount;
}

//PRINT THE ACCOUNT SUMMARY

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();
    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl ;
    cout << setw(25) << "Maturity Months: " << m_MaturityMonths << endl ;
    cout << setw(25) << "Current Month: " << m_CurrentMonth << endl;
    cout << endl << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}

void printStatement()
{
    printSummary();
    cout << "A full implementation would also print a Certificate of Deposite Account Statement here." << endl;
}

//PRIVATE VARIABLES for interest rate, maturity months, current month

private:
double m_InterestRate;
int m_MaturityMonths;
int m_CurrentMonth;
};

//CLASS checkingAccount DERIVED FROM bankAccount

//checkingAccount.h

#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"

using namespace std;

class checkingAccount :
public bankAccount
{
public:

//CONSTRUCTOR THAT SETS BASIC DETAILS NAME, ACCOUNT NUMBER, BALANCE USING bankAccount CONSTRUCTOR
checkingAccount(int acctNum, string name, double initialBalance)
    : bankAccount(acctNum, name, initialBalance)
{
}

//DESTRUCTOR
~checkingAccount(void){}

//VIRTUAL METHOD writeCheck(double amount)

virtual void writeCheck(double amount) = 0;

//IMPLEMENTING bankAccount withdraw(double amount)

void withdraw(double amount)
{

//if m_balace is less than amount , tells the user insufficient balance. Not possible to withdraw

    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

//if withdrawal amount makes m_balance to less than m_MinimumBalance then prints the error message : Minimum balance requirement prohibits this withdrawal
    if (m_Balance - amount < m_MinimumBalance)
    {
      cout << "Declined: Minimum balance requirement prohibits this withdrawal" << endl;
      return;
    }

//otherwise makes withdrawal of specified amount
    m_Balance -= amount;
}

//print the ACCOUNT STATEMENT

void printStatement()
{
    printSummary();
    cout << endl << "A full implementation would also print details of a Checking Account Statement here." << endl << endl;
}

//PROTECTED VARIABLES FOR interest rate, no of check leafs, minimum balance that should be maintained

protected:
double m_InterestRate;
int m_ChecksRemaining;
double m_MinimumBalance;
};

//CLASS highInterestChecking DERIVED FROM noServiceChargeChecking

//highInterestChecking.h

#include <iostream>
#include <iomanip>
#include <string>
#include "noServiceChargeChecking.h"

using namespace std;

class highInterestChecking :
public noServiceChargeChecking
{
public:

//SETS THE ACCOUNT NUMBER, NAME AND BALANCE
highInterestChecking(int acctNum, string name, double initialBalance)
    : noServiceChargeChecking(acctNum, name, initialBalance)
{
    // The only difference between the base class noServiceChargeChecking
    // is the values of interest and minimum balance.
    // So no additional functionality needed for this one.

    m_InterestRate = 5.0; // Higher interest rate
    m_ChecksRemaining = -1; // -1 indicates no limit
    m_MinimumBalance = 1000; // Minimum balance
}

~highInterestChecking(void){}
};

//CLASS highInterestSavings DERIVED FROM savingsAccount

//highInterestSavings.h

#include <iostream>
#include <iomanip>
#include <string>
#include "savingsAccount.h"

using namespace std;

class highInterestSavings :
public savingsAccount
{
public:

//SETS THE ACCOUNT NUMBER, NAME, INITIAL BALANCE
highInterestSavings(int acctNum, string name, double initialBalance)
    : savingsAccount(acctNum, name, initialBalance)
{
    m_MinimumBalance = 5000;
}

//DESTRUCTOR

~highInterestSavings(void){}

//IMPLEMENTING BASE CLASS withdraw(double amount)

void withdraw(double amount)
{
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

    if (m_Balance - amount < m_MinimumBalance)
    {
      cout << "Declined: Minimum balance requirement prohibits this withdrawal" << endl;
      return;
    }

    m_Balance -= amount;
}

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();

    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl;
    cout << setw(25) << "Minimum Balance: $" << m_MinimumBalance << endl << endl;
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}


protected:

//PROTECTED VARIABLES m_MinimumBalance
double m_MinimumBalance;

};

//noServiceChargeChecking.h

#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"

using namespace std;

//CLASS noServiceChargeChecking DERIVED FROM checkingAccount

class noServiceChargeChecking :
public checkingAccount
{
public:

//CONSRTRUCTOR noServiceChargeChecking SETS THE NAME, ACCOUNT NUMBER, BALANCE
noServiceChargeChecking(int acctNum, string name, double initialBalance)
    : checkingAccount(acctNum, name, initialBalance)
{
    m_InterestRate = 2.5; // Some interest rate
    m_ChecksRemaining = -1; // -1 indicates no limit
    m_MinimumBalance = 500; // Minimum balance

}

~noServiceChargeChecking(void){}

//IMPLEMENTING BASE CLASS writeCheck(double amount)

void writeCheck(double amount)
{
    if (m_Balance - amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

    m_Balance -= amount; // Assume check is cashed immediately...
}

//PRINT THE ACCOUNT SUMMARY

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();
    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl;
    cout << setw(25) << "Minimum Balance: $" << m_MinimumBalance << endl;
    cout << setw(25) << "Unlimited checks   " << endl;
    cout << setw(25) << "No monthly service fee   "<< endl;
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}

};

//savingsAccount.h

#include <iostream>
#include <iomanip>
#include <string>
#include "bankAccount.h"

using namespace std;

//CLASS savingsAccount DERIVED FROM bankAccount

class savingsAccount :
public bankAccount
{
public:

//CONSTRUCTOR savingsAccount THAT SETS NAME, ACCOUNT NUMBER, BALANCE AND INTEREST RATE
savingsAccount(int acctNum, string name, double initialBalance)
    : bankAccount(acctNum, name, initialBalance)
{
    m_InterestRate = 3.99;
}

//DESTRUCTOR

~savingsAccount(void)
{
}

//IMPLEMENTING withdraw(double amount)

void withdraw(double amount)
{
    if (m_Balance-amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }
    m_Balance -= amount;
}

//PRINT THE SUMMARY

void printSummary()
{
    // Use the root base class to print common info
    bankAccount::printSummary();
    cout << setw(25) << "Interest rate: " << m_InterestRate << "%" << endl << endl;
    cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
}
//PRINT THE MONTHLY STATEMENT
void printStatement()
{
    printSummary();
    cout << "A full implementation would also print a Savings Account Statement here." << endl;
}


protected:
double m_InterestRate;

};

//CLASS serviceChargeChecking DERIVED FROM checkingAccount
//serviceChargeChecking.h

#include <iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"

using namespace std;

const int MAX_CHECKS=5;
const double SVC_CHARGE=10.0l;

class serviceChargeChecking :
public checkingAccount
{
public:

//CONSTRUCTOR THAT SETS NAME, ACCOUNT NUMBER, BALANC, INTEREST RATE, NO OF CHECKS LEAFS, MINIMUM BALANCE
serviceChargeChecking(int acctNum, string name, double initialBalance)
    : checkingAccount(acctNum, name, initialBalance)
{
    m_InterestRate = 0; // No interest
    m_ChecksRemaining = MAX_CHECKS; // Limit of 5 checks
    m_MinimumBalance = 0; // No minimum balance
}
//DESTRUCTOR
~serviceChargeChecking(void){}

//IMPLEMENTS writeCheck(double amount) THAT GIVES CHECKS

void writeCheck(double amount)
{
    if (m_ChecksRemaining == 0)
    {
      cout << "Declined: No more checks remaining this month" << endl;
      return;
    }
  
    if (m_Balance - amount < 0)
    {
      cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
      return;
    }

//REDUCE NO OF CHECK LEAFS BY 1

    m_ChecksRemaining--;
    m_Balance -= amount; // Assume check is cashed immediately...

    }

//PRINT THE SUMMARY

    void printSummary()
    {
      // Use the root base class to print common info
      bankAccount::printSummary();
      cout << setw(25) << "Checks remaining: " << m_ChecksRemaining << endl;
      cout << setw(25) << "Monthly service fee: $" << SVC_CHARGE << endl;
      cout << setw(25) << "No interest " << endl;
      cout << setw(25) << "No Minimum Balance " << endl;
      cout << setw(60) << setfill('-') << "" << setfill(' ') << endl;
    }
};

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