Question

C++

Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another type of account that is used to save money for the long term is certificate of deposit (CD). In this programming exercise, you use abstract classes and pure virtual functions to design classes to manipulate various types of accounts. For simplicity, assume that the bank offers three types of accounts: savings, checking, and certificate of deposit, as described next.

Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance and has a higher interest rate.

Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no monthly service charge, a minimum balance requirement, unlimited check writing and lower interest; and a third with no monthly service charge, a higher minimum requirement, a higher interest rate, and unlimited check writing.

Certificate of deposit (CD): In an account of this type, money is left for some time, and these accounts draw higher interest rates than savings or checking accounts. Suppose that you purchase a CD for six months. Then we say that the CD will mature in six months. The penalty for early withdrawal is stiff.

Figure 12-25 shows the inheritance hierarchy of these bank accounts.

Note that the classes bankAccount and checkingAccount are abstract. That is, we cannot instantiate objects of these classes. The other classes in Figure 12-25 are not abstract.

bankAccoun checkingåccount ceificateofpeposit savingsAccount rt serviceChargeChecking noServiceChargeChecking highInterestSavings highInterestCh ecking

bankAccount: Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name, accountNumber, and balance should be declared in the abstract class bankAccount. Some operations common to all types of accounts are retrieve account owner’s name, account number, and account balance; make deposits; withdraw money; and create monthly statements. So include functions to implement these operations. Some of these functions will be pure virtual.

checkingAccount: A checking account is a bank account. Therefore, it inherits all the properties of a bank account. Because one of the objectives of a checking account is to be able to write checks, include the pure virtual function writeCheck to write a check.

serviceChargeChecking: A service charge checking account is a checking account. Therefore, it inherits all the properties of a checking account. For simplicity, assume that this type of account does not pay any interest, allows the account holder to write a limited number of checks each month, and does not require any minimum balance. Include appropriate named constants, instance variables, and functions in this class.

noServiceChargeChecking: A checking account with no monthly service charge is a checking account. Therefore, it inherits all the properties of a checking account. Furthermore, this type of account pays interest, allows the account holder to write checks, and requires a minimum balance.

highInterestChecking: A checking account with high interest is a checking account with no monthly service charge. Therefore, it inherits all the properties of a no service charge checking account. Furthermore, this type of account pays higher interest and requires a higher minimum balance than the no service charge checking account.

savingsAccount: A savings account is a bank account. Therefore, it inherits all the properties of a bank account. Furthermore, a savings account also pays interest.

highInterestSavings: A high-interest savings account is a savings account. Therefore, it inherits all the properties of a savings account. It also requires a minimum balance.

certificateOfDeposit: A certificate of deposit account is a bank account. Therefore, it inherits all the properties of a bank account. In addition, it has instance variables to store the number of CD maturity months, interest rate, and the current CD month.

Write the definitions of the classes described in this programming exercise and a program to test your classes.

I have the code, but need comments added 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 << "\t\tTesting 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 << "\t\tTesting 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 << "\t\tTesting 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 << "\t\tTesting 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 << "\t\tTesting 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 << "\t\tTesting 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 << "\t\tWelcome 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;
    }
};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//below code is well commented and corrected . sample output snapshot is also attached

//Accounts.cpp
#include
#include
#include
#include "certificateOfDeposit.h"       //including certificateOfDeposit
#include "highInterestChecking.h"       //including highInterestChecking
#include "highInterestSavings.h"       //including highInterestSavings
#include "serviceChargeChecking.h"       //including serviceChargeChecking
using namespace std;


void TestCheckingWithService()
{
//acct object of serviceChargeChecking, values of data member is passed as argument of constructor
serviceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;

cout << "\t\tTesting Checking with Service Charge" << endl << endl;
cout << "Current account overview:" << endl;
//printing the account summary
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: ";
//entering the 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;
}
//after choosing valid choice again printing the account summary
acct.printSummary();
cout << endl;
}
}
//same as above
void TestCheckingNoService()
{
  
//acct is object of noServiceChargeChecking,values of data member is passed as argument of constructor
noServiceChargeChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << "\t\tTesting 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;
}
}
//same as above
void TestCheckingHighInterest()
{
//acct is object of highInterestChecking,values of data member is passed as argument of constructor
highInterestChecking acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << "\t\tTesting 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;
}
}
//same as above
void TestSavings()
{
//acct is object of savingsAccount,values of data member is passed as argument of constructor
savingsAccount acct(123,"John Doe", 1000);
char input=0;
double amount;
cout << "\t\tTesting 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;
}
}
//same as above
void TestSavingsHighInterest()
{
//acct is object of highInterestSavings,values of data member is passed as argument of constructor
highInterestSavings acct(123,"John Doe", 8000);
char input=0;
double amount;
cout << "\t\tTesting 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;
}
}
//same as above
void TestCertificateOfDeposit()
{
//acct is object of certificateOfDeposit,values of data member is passed as argument of constructor
certificateOfDeposit acct(123,"John Doe", 10000, 6);
char input=0;
double amount;
cout << "\t\tTesting 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 << "\t\tWelcome 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: ";
//entering the choice
cin >> input;
switch (input)
{
case '1':
//Checking with Service Charge
TestCheckingWithService();
break;
case '2':
//Checking without Service Charge
TestCheckingNoService();
break;
case '3':
//Checking with High Interest
TestCheckingHighInterest();
break;
case '4':
//for Savings account
TestSavings();
break;
case '5':
//Savings with High Interest
TestSavingsHighInterest();
break;
case '6':
//for Certificate of Deposit
TestCertificateOfDeposit();
break;
default:
cout << "Invalid choice" << endl;
break;
}
}

//bankAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include
#include
#include
using namespace std;

//defining the abstract class that will be inherited to different types of bank accounts
class bankAccount
{
public:
//defining the constructor with argument which intialises the account number , name and intial balance
bankAccount(int acctNum, string name, double initialBalance)
{
m_AcctNumber = acctNum;
m_Name = name;
m_Balance = initialBalance;
}
//default destructor
~bankAccount(void){}

//accessor function for member m_Name
string get_Name()
{
return m_Name;
}
//accessor function for member Account Number
int get_AcctNumber()
{
return m_AcctNumber;
}

//accessor function for m_Balance
double get_Balance()
{
return m_Balance;
}

//defining the deposit function ,updating the amount in account by adding the amount being deposited
void deposit(double amount)
{
m_Balance += amount;
cout << "$" << amount << " has been deposited to your account" << endl;
}
//pure virtual function , will be defined in inherited classes
virtual void withdraw(double amount) = 0;
virtual void printStatement() = 0;

//virtual function ,this function will also be defined in inherited classes. This function prints the summary of the account
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:
//protected data member Name,Account Number, m_Balance
string m_Name;
int m_AcctNumber;
double m_Balance;
};
#endif


//certificateOfDeposit.h
#include
#include
#include
#include "bankAccount.h"   //including bankAccount.h
using namespace std;
//class certificateOfDeposit is inherited from bankAccount
class certificateOfDeposit : public bankAccount
{
public:
//constructor intializing the data members of class, the account number ,name ,intialBalance will get intialised from bankAccount class's constructor
//other data member like m_MaturityMonths get intialised by argument of the constructor matMon
//other data member like m_CurrentMonth , m_InterestRate is intialised by constant values
certificateOfDeposit(int acctNum, string name, double initialBalance, int matMon)
: bankAccount(acctNum, name, initialBalance)
{
m_MaturityMonths = matMon;
m_CurrentMonth = 1;
m_InterestRate = 4.75;
}
//default destructor
~certificateOfDeposit(void){}
//defining its own withdraw function ,updating the balance by subtracting the withdrawal amount
void withdraw(double amount)
{
if (m_Balance-amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount;
}

//defining its own print summary function ,to print the summary of account
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;
  
}
//printStatement function same as printSummary() except the last additional line
void printStatement()
{
printSummary();
cout << "A full implementation would also print a Certificate of Deposite Account Statement here." << endl;
}
private:
//private data members
double m_InterestRate;
int m_MaturityMonths;
int m_CurrentMonth;
};


//checkingAccount.h
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include
#include
#include
#include "bankAccount.h"       //including bankAccount.h
using namespace std;
//class checkingAccount is inherited from bankAccount
class checkingAccount :public bankAccount
{
public:
//constructor intializing the data members of class, the account number ,name ,intialBalance will get intialised from bankAccount class's constructor
checkingAccount(int acctNum, string name, double initialBalance)
: bankAccount(acctNum, name, initialBalance)
{
}
//default destructor
~checkingAccount(void){}
//writeCheck function will be defined in the classes which will be inherited from checkingAccount class
virtual void writeCheck(double amount) = 0;
//defining its own withdraw function ,updating the balance by subtracting the withdrawal 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;
}
//defining its own printStatement function ,to print the statement of account
void printStatement()
{
printSummary();
cout << endl << "A full implementation would also print details of a Checking Account Statement here." << endl << endl;
}
protected:
//protected data member m_InterestRate,m_ChecksRemaining,m_MinimumBalance
double m_InterestRate;
int m_ChecksRemaining;
double m_MinimumBalance;
};
#endif


//highInterestChecking.h
#include
#include
#include
#include "noServiceChargeChecking.h"       //including noServiceChargeChecking.h
using namespace std;

//highInterestChecking is inherited from noServiceChargeChecking class
class highInterestChecking : public noServiceChargeChecking
{
public:
//constructor intialises the acctNum ,name ,initialBalance from the constructor of noServiceChargeChecking class constructor
//members like m_InterestRate,m_ChecksRemaining,m_MinimumBalance will get intialised with constant values
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
}
//default destructor
~highInterestChecking(void){}
};

//highInterestSavings.h
#include
#include
#include
#include "savingsAccount.h"       //including the savingsAccount.h
using namespace std;
//highInterestSavings is inherited from savingsAccount
class highInterestSavings :public savingsAccount
{
public:
//constructor intialises the member account number ,name,initialBalance with the help of savingsAccount's constructor
//intialises m_MinimumBalance with the constant
highInterestSavings(int acctNum, string name, double initialBalance)
: savingsAccount(acctNum, name, initialBalance)
{
m_MinimumBalance = 5000;
}
//default destructor
~highInterestSavings(void){}
//defining its own withdraw function ,updating the balance by subtracting the withdrawal 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;
}
//defining its own print summary function ,to print the summary of account along with Interest rate, Minimum Balance
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 data member
double m_MinimumBalance;
};


//noServiceChargeChecking.h
#include
#include
#include
#include "checkingAccount.h"       //including checkingAccount.h
using namespace std;

//noServiceChargeChecking is inherited from checkingAccount
class noServiceChargeChecking :public checkingAccount
{
public:
//constructor intialises the int acctNum, string name, double initialBalance with the help of checkingAccount constructor
//m_InterestRate, m_ChecksRemaining,m_MinimumBalance is intialised with constant values
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
}
//default destructor
~noServiceChargeChecking(void){}
//updating the balance by subtracting the ammount of written check
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...
}
//printing the summary of account
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
#include
#include
#include "bankAccount.h"       //including the bankAccount.h
using namespace std;
//savingsAccount is inherited from bankAccount
class savingsAccount :public bankAccount
{
public:
//constructor intializing the data members of class, the account number ,name ,intialBalance will get intialised from bankAccount class's constructor
//m_InterestRate is intialised with constant value
savingsAccount(int acctNum, string name, double initialBalance)
: bankAccount(acctNum, name, initialBalance)
{
m_InterestRate = 3.99;
}
//destructor
~savingsAccount(void)
{
}

//defining its own withdraw function ,updating the balance by subtracting the withdrawal amount
void withdraw(double amount)
{
if (m_Balance-amount < 0)
{
cout << "Declined: Insufficient funds remain to withdraw that amount" << endl;
return;
}
m_Balance -= amount;
}
//defining its own print summary function ,to print the summary of account
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;
}
//printStatement function same as printSummary() except the last additional line
void printStatement()
{
printSummary();
cout << "A full implementation would also print a Savings Account Statement here." << endl;
}

protected:
//protected data member m_InterestRate
double m_InterestRate;
};


//serviceChargeChecking.h
#include
#include
#include
#include "checkingAccount.h"       //including checkingAccount.h
using namespace std;
const int MAX_CHECKS=5;
const double SVC_CHARGE=10.0l;
//serviceChargeChecking is inherited from checkingAccount
class serviceChargeChecking :public checkingAccount
{
public:
//constructor intialises the acctNum, name,initialBalance with the help of constructor of checkingAccount
//other data members like m_InterestRate, m_ChecksRemaining,m_MinimumBalance is intialised by a constant value
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){}

//updating the balance by subtracting the ammount of written check
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...
  
}
//defining its own print summary function ,to print the summary of account
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;
}
};

//sample output, you just need to compile Account.cpp, every linked file will get compiled automatically:

File Edit View Bookmarks Settings Help raushan@MyPC: /Documents>g++ Account.cpp -o p raushan@MyPC:-/Documents>./p Welcome to the Bank Account Test Suite what type of account do you want to test? 1 - Checking with Service Charge 2 - Checking without Service Charge 3 - Checking with High Interest 4 - Savings 5 Savings with High Interest 6 Certificate of Deposit Enter choice: I

Add a comment
Know the answer?
Add Answer to:
C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ help please. Savings accounts: Suppose that the bank offers two types of savings accounts: one...

    c++ help please. Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance but has a higher interest rate (the benefit here being larger growth in this type of account). Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no...

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • The objective of this project is to provide experience working with user interface menus and programmed...

    The objective of this project is to provide experience working with user interface menus and programmed decision making. Modify the C++ source you created in Project # 2 to incorporate the following requirements: 1. Present a menu to the user which includes: a. Enter checking account transaction b. Enter savings account transaction c. Quit 2. If the user selects a., request the checking account balance, the checking account transaction date, the checking account description, and the checking account amount from...

  • MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture...

    MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its...

  • C++ Help. PLEASE include detailed comments and explanations. PLEASE follow the drections exactly. Thank you. Define...

    C++ Help. PLEASE include detailed comments and explanations. PLEASE follow the drections exactly. Thank you. Define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount....

    Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount. Implement four methods: • public void deposit(double amount, String account) • public void withdraw(double amount, String account) • public void transfer(double amount, String account) • public double getBalance(String account) Here the account string is "S" or "C". For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is...

  • C++ Check Book Program I need to have a checkbook program that uses the following items....

    C++ Check Book Program I need to have a checkbook program that uses the following items. My code that I have appears below. 1) Math operations using built-in math functions 2) Class type in a separate .h file with member functions (accessor functions, get, set, show, display find, etc). There needs to be an overloaded function base/derived classes or a template. 3) Binary File #include <iostream> using namespace std; int main() {     double checking,savings;     cout<<"Enter the initial checking...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT