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

Banks offer various types of accounts, such as savings, checking, certificate of

ID: 3677430 • Letter: B

Question

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.
1 2
Programming Exercises | 863
C7958_C12
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. bankAccount: Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name, accountNumber, andbalance 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 statement. 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.
bankAccount
checkingAccount savingsAccount
highInterestSavingsserviceChargeChecking noServiceChargeChecking
highInterestChecking
certificateOfDeposit
FIGURE 12-25 Inheritance hierarchy of banking accounts
864 | Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists
C7958_C12
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.

Explanation / Answer


main.cpp
#include <iostream>
#include <string>
#include "dakins4-2.h"
using namespace std;

int main()
{
   string acccounname1;
   string accountnumber1;
   double accountbalance1;
   cout << "Welcome to your Bank. Please enter your account information to create your account." << endl;
   getline(cin,acccounname1);
   cout << "Account Number" << endl;
   getline(cin,accountnumber1);
   cout << "Welcome " << acccounname1 << " ,Please Enter your Account Balance" << endl;
   cin >> accountbalance1;
  

   bankaccount getbasicbankinfo(acccounname1,accountnumber1,accountbalance1);
  

   cout << "Thank you, What would you like to do today?" << endl;
   cout << "1 : Access Checking Account" << endl;
   cout << "2 : Access Savings Account" << endl;
   cout << "3 : Request Certificate of Deposit" << endl;
   cout << "4 : Exit" << endl;
   int selectionnum;
   cin >> selectionnum;
  
   if (selectionnum == 1)
   {
       checkingaccount check;
       bankaccounttype *type2 = &check;
       type2->typeofaccount();
       bankaccounttype*type3 =&check;


       cout << "(S for Service Check and N for no Service Check)" << endl;

       bool service;
       cin >> service;
           if(service = "S")
           {
               servicechargecheck service;
               checkingaccount *type4 = &service;
               type4->serviceoption();
          
           }
           else
           {
               noservicechargechecktype noservice;
               checkingaccount *type5 = &noservice;
               type5->serviceoption();

               cout << "Do you want a high interest check?" << endl;
               bool yessnoo;
               cin >> yessnoo;
               if (yessnoo = "y")
               {
                   highinterestchecking inter;
                   noservicechargechecking *type6 = &inter;
                   type6->interest();
               }
               else
               { cout << "OK" << endl;
               bankaccount printbasicinfo();
               system("PAUSE");
               return 0;
               }

           }

   }

   /*      +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
   else if (selectionnum == 2)
   {
       savingsaccount save;
       bankaccounttype *bank1 = &save;
       bank1->typeofaccount();
       bool yesno;
   cin >> yesno;
   if (yesno = "yes")
   {
   highinterestsavings high;
   savingsaccount *bank2 = &high;
   bank2->highinterest();
   savingsaccount ShowSavingsAccount();
   }
   else
   { cout << "OK" << endl;
       system("PAUSE");
       return 0;
   }

   }


   /**************************************************************************************************/

   else if (selectionnum == 3)
   {
       double depositrate;
       int monthamount;
       string month;
       certificateofdeposittype cert;
       bankaccounttype *type7 = &cert;
       type7->typeofaccount();
      
       cout << "Requesting Certificate of Deposit: Enter the following information." << endl;
       cout << "Deposit Rate" << endl;
       cin >> depositrate;
       cout << "Month Certificate was Requested." << endl;
       getline(cin,month);
       cout << "Amount of Time this will be valid." << endl;
       cin >> monthamount;

   }
   else if (selectionnum == 4)
   {
   cout << "Thanks for visiting today, " << acccounname1 << endl;
   system("PAUSE");
   return 0;
   }


system("PAUSE");
return 0;
}

darkins.cpp

#include "dakins4-2.h"
#include <iostream>
#include <string>
using namespace std;

bankaccount::bankaccount(string name, string number, double balance)
{
   accountname = " ";
   accountbalance = 0;
   accountnumber = " ";

}

void bankaccount::getbasicbankinfo(string name, string number, double balance)
{
   accountname = name;
   accountbalance = balance;
   accountnumber = number;
}

void bankaccount::printbasicinfo()
{
   cout << "Account Name:" << accountname << endl;
   cout << "Account Number:" << accountnumber << endl;
   cout << "Account Balance:" << accountbalance << endl;
}


void certificateofdeposit::getCDs(double interest, string month, int numberofmonths)
{
   CDinterestrate = interest;
   CDmonth = month;
   numberofCDmonths = numberofmonths;
}

void certificateofdeposit::printCDcheck()
{
   cout << "Account Name:" << accountname << endl;
   cout << "Account Number:" << accountnumber << endl;
   cout << "Account Balance:" << accountbalance << endl;
   cout << "Certificate deposit rate:" << CDinterestrate << endl;
   cout << "Certificate Month:" << CDmonth << endl;
   cout << "Number of Months" << numberofCDmonths << endl;

}

void savingsaccount::ShowSavingsAccount()
{
   cout << "Account Name:" << accountname << endl;
   cout << "Account Number:" << accountnumber << endl;
   cout << "Savings Balance:" << accountbalance << endl;
  
}

void highinterestsavings::minimumbalances()
{
   minimumbalance = 5000;

}

void highinterestsavings::printminimumbalances()
{
       cout << "Minimum balance is:" << minimumbalance << endl;
}

void servicechargecheck::Printcheck()
{
   cout << "Account Name:" << accountname << endl;
   cout << "Account Number:" << accountnumber << endl;
   cout << "Service Check Balance:" << accountbalance << endl;

}

void noservicechargechecking::Printchecks()
{
   cout << "Account Name:" << accountname << endl;
   cout << "Account Number:" << accountnumber << endl;
   cout << "Service Check Balance:" << accountbalance << endl;
}

certificateofdeposit::certificateofdeposit(double interest, string month, int numberofmonths)
{
   CDinterestrate = 0;
   CDmonth = " ";
   numberofCDmonths = 0;

}

dakins4-2.h

#include <iostream>

using namespace std;


class bankaccount
{
public:
   void printbasicinfo();
   bankaccount(string name, string number, double balance);
   void getbasicbankinfo(string name, string number, double balance);
  
private:
   string accountname;
   string accountnumber;
   double accountbalance;
   double CDinterestrate;
   string CDmonth;
   int numberofCDmonths;
};

class bankaccounttype
{
public:
   virtual void typeofaccount() = 0;
};
class checkingaccounttype: public bankaccount
{
public:
   virtual void writecheck() = 0;

};

class checkingaccount: public bankaccounttype
{
public:
  
   void typeofaccount()
   { cout << "This is your checking account. Select from the following options:" << endl;};
   virtual void serviceoption()
   { cout << "would you rather write a service charge check?" << endl;};
  
private:
   string accountname;
   string accountnumber;
   double accountbalance;

};

class certificateofdeposittype: public bankaccounttype
{
   void typeofaccount()
   {cout << "This is your certificate of deposit." << endl;};

};
class certificateofdeposit: public bankaccounttype
{
public:
   certificateofdeposit(double interest, string month, int numberofmonths);
   void getCDs(double interest, string month, int numberofmonths);
   void printCDcheck();
  
private:
   string accountname;
   string accountnumber;
   double accountbalance;
   double CDinterestrate;
   string CDmonth;
   int numberofCDmonths;
};

class savingsaccount: public bankaccounttype
{
public:
   void typeofaccount()
   {cout << "This is your savings account. Would you like a high interest account?" << endl;};
   virtual void highinterest()
   {cout << "High Interest Savings Account" << endl;};
   void ShowSavingsAccount();
private:
   string accountname;
   string accountnumber;
   double accountbalance;
};

class serviceclasstype: public checkingaccount
{
   void serviceoption()
   { cout << "You are writing a service charge check. You can only print out a maximum of 6 service checks a month." << endl;};

};

class servicechargecheck: public checkingaccount
{
public:
   void Printcheck();
private:
   string accountname;
   string accountnumber;
   double accountbalance;
};

class noservicechargechecktype: public checkingaccount
{
public:
   void serviceoption()
   { cout << "You are not writing a service charge check. You can write a minimum of 1,000 on the acocunt." << endl;
   cout << "Did you want a high Interest checking account?" << endl;};

};


class highinterestsavings: public savingsaccount
{
public:
   void highinterest()
   { cout << "High Interest Savings" << endl;}
   void minimumbalances();
   void printminimumbalances();

private:
   string accountname;
   string accountnumber;
   double accountbalance;
   double minimumbalance;
};

class noservicechargechecking: public checkingaccount
{
public:
   virtual void interest()
   {cout << "high interest savings" << endl;};
   void Printchecks();

private:
   string accountname;
   string accountnumber;
   double accountbalance;
   double minimumbalance;
};

class highinterestchecking: public noservicechargechecking
{
public:
   void interest()
   { cout << "High Interest Savings" << 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