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

13. a. Define the class bankAccount to store a bank customer’s account number an

ID: 664404 • Letter: 1

Question

13. a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors.

b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. Add member variables to store this additional information. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, set minimum balance, retrieve minimum balance, set service charges, retrieve service charges, post interest, verify if the balance is less than the minimum balance, write a check, withdraw (override the method of the base class), and print account information. Add appropriate constructors.

c. Every bank offers a savings account. Derive the class savingsAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a savings account typically receives interest, makes deposits, and withdraws money. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, post interest, withdraw (override the method of the base class), and print account information. Add appropriate constructors.

d. Write a program to test your classes designed in parts (b) and (c).

I have the program written, but I'd like the comments added.

#include <iostream>
using namespace std;

class BankAccount
   {
       public:
       int accountNumber;
       double Balance;

public:
   BankAccount(int Accno,double Bal)
   {
       accountNumber = Accno;
       Balance = Bal;
   }
   BankAccount()
   {
   }
public:
   double getBal()
   {
       return(Balance);
   }
   int getAccNo()
   {
       return(accountNumber);
   }
   void setBal(double amount)
   {
       Balance = amount;
   }
   void setAccNo(int Accno)
   {
       accountNumber = Accno;
   }
   void virtual showAccNo()
   {
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
   }

   double virtual depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;
       return(Balance);
   }

   double virtual wdrawAmnt(double wAmnt)
   {
       Balance = Balance - wAmnt;
       return(Balance);
   }
};

class CheckingAccount : BankAccount
{
   double Intrst;
   double minBal;
   double serChge;

public:
   CheckingAccount(int pAccno,double pAmnt,double pIntrst):BankAccount(pAccno,pAmnt)
   {
       Intrst = pIntrst;
       minBal = 500;//By default
   }

   void setIntRate(double intRate)
   {
       Intrst = intRate;
   }

   double retIntRate()
   {
       return(Intrst);
   }

   void setMinBal(double mBal)
   {
       minBal = mBal;
   }

   double retMinBal()
   {
       return(minBal);
   }

   void setSerChge(double sCharge)
   {
       serChge = sCharge;
   }

   double retSerChge()
   {
       return(serChge);
   }

   double depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;
       return(Balance);
   }

   double wdrawAmnt(double wAmnt)
   {
       if(wAmnt <= Balance)
           Balance = Balance - wAmnt;
       else
           cout << "You have insufficient funds!" << endl;
       return(Balance);
   }

   void showAccNo()
   {
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
   }
};

class SavingAccount:BankAccount
   {
       double minBal;
   public:
       SavingAccount(int pAccno,double pAmnt):BankAccount(pAccno,pAmnt)
       {
           minBal = 500;
       }
       double depAmnt(double dAmnt)
       {
           Balance = Balance + dAmnt;
           return(Balance);
       }
       double wdrawAmnt(double wAmnt)
       {
           if(wAmnt <= Balance)
               Balance = Balance - wAmnt;
           else
               cout << "You have in sufficient funds!" << endl;
           return(Balance);
       }
       void setMinBal(double mBal)
       {
           minBal = mBal;
       }
       void showAccNo()
       {
           cout << endl;
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
       }
};

int main()
   {
       double amount;
       int choice;
       do
       {
           cout << endl;
           cout << "       Create an Account      " << endl;
           cout << " *****************************" << endl;
           cout << " ** 1 - Checking Account   **" << endl;
           cout << " ** 2 - Saving Account     **" << endl;
           cout << " ** 3 - Exit               **" << endl;
           cout << " *****************************" << endl;
           cin >> choice;
           cout << endl;
          
           if(choice==1)
           {
               cout << "Enter account number: " << endl;
               int Accno;
               cin >> Accno;
               cout << "Enter opening balance: " << endl;
               double newBal;
               cin >> newBal;
               double intRate;
               cout << "Enter interest rate: " << endl;
               cin >> intRate;
               CheckingAccount obj(Accno,newBal,intRate);
               int accChoice;
               do
               {
                   cout << endl;
                   cout << " *************************" << endl;
                   cout << " ** 1 - Deposit        **" << endl;
                   cout << " ** 2 - Withdraw       **" << endl;
                   cout << " ** 3 - Account Info   **" << endl;
                   cout << " ** 4 - Exit           **" << endl;
                   cout << " *************************" << endl;
                   cin >> accChoice;
                   cout << endl;
                   switch(accChoice)
                   {
                   case 1:
                       cout << "Enter amount: " << endl;
                       cin >> amount;
                       double dAmnt;
                       dAmnt = obj.depAmnt(amount);
                       cout << "Available balance: " << dAmnt << endl;
                       break;
                   case 2:
                       cout << "Enter amount: " << endl;
                       cin >> amount;
                       double wAmnt;
                       wAmnt = obj.wdrawAmnt(amount);
                       cout << "Available balance: "<< wAmnt << endl;
                       break;
                   case 3:
                       obj.showAccNo();
                       break;
                   }
               }

               while(accChoice!=4);
           }
           else if(choice==2)
           {
               cout << "Enter account number:" << endl;
               int pAccno;
               cin >> pAccno;
               cout << "Enter opening balance:" << endl;
               double pnewBal;
               cin >> pnewBal;
               double _irate;
               cout << "Enter interest rate:" << endl;
               cin >> _irate;
               SavingAccount sObj(pAccno,pnewBal);
               int pChoice;
               do
               {
                   cout << endl;
                   cout << " *************************" << endl;
                   cout << " ** 1 - Deposit        **" << endl;
                   cout << " ** 2 - Withdraw       **" << endl;
                   cout << " ** 3 - Account Info   **" << endl;
                   cout << " ** 4 - Exit           **" << endl;
                   cout << " *************************" << endl;
                   cin>>pChoice;
                   cout << endl;
                   switch(pChoice)
                   {
                   case 1:
                       cout << "Enter amount:" << endl;
                       cin >> amount;
                       double _dAmnt;
                       _dAmnt = sObj.depAmnt(amount);
                       cout << "Available balance: " << _dAmnt;
                       break;
                   case 2:
                       cout << "Enter amount:" << endl;
                       cin >> amount;
                       double _wamount;
                       _wamount = sObj.wdrawAmnt(amount);
                       cout << "Available balance: " << _wamount;
                       break;
                   case 3:
                       sObj.showAccNo();
                       break;
                   case 4:
                       break;
                   default:
                       cout << "Invalid choice";
                       break;
                   }
               }
               while(pChoice!=4);
           }
       }
       while(choice!=3);
}

Explanation / Answer

#include <iostream>
using namespace std;

class BankAccount //set and retrieve account number, retrieve balance, deposit and withdraw money and print account information
   {
       public:
       int accountNumber;
       double Balance;

public:
   BankAccount(int Accno,double Bal)
   {
       accountNumber = Accno;
       Balance = Bal;
   }
   BankAccount()
   {
   }
public:
   double getBal()
   {
       return(Balance);
   }
   int getAccNo()
   {
       return(accountNumber);
   }
   void setBal(double amount)
   {
       Balance = amount;
   }
   void setAccNo(int Accno)
   {
       accountNumber = Accno;
   }
   void virtual showAccNo() // to print the details
   {
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
   }

   double virtual depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;
       return(Balance);
   }

   double virtual wdrawAmnt(double wAmnt)
   {
       Balance = Balance - wAmnt;
       return(Balance);
   }
};

class CheckingAccount : BankAccount
{
   double Intrst;
   double minBal;
   double serChge;

public:
   CheckingAccount(int pAccno,double pAmnt,double pIntrst):BankAccount(pAccno,pAmnt)
   {
       Intrst = pIntrst;
       minBal = 500;//By default
   }

   void setIntRate(double intRate)
   {
       Intrst = intRate;
   }

   double retIntRate()
   {
       return(Intrst);
   }

   void setMinBal(double mBal)
   {
       minBal = mBal;
   }

   double retMinBal()
   {
       return(minBal);
   }

   void setSerChge(double sCharge)
   {
       serChge = sCharge;
   }

   double retSerChge()
   {
       return(serChge);
   }

   double depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;
       return(Balance);
   }

   double wdrawAmnt(double wAmnt) // fuction to check whether there is sufficent balance is there in account or not and deduct the amount from balance
   {
       if(wAmnt <= Balance)
           Balance = Balance - wAmnt;
       else
           cout << "You have insufficient funds!" << endl;
       return(Balance);
   }

   void showAccNo()
   {
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
   }
};

class SavingAccount:BankAccount //set and retrieve interest rate, set and retrieve interest earned, post interest, withdraw, and print account info
   {
       double minBal;
   public:
       SavingAccount(int pAccno,double pAmnt):BankAccount(pAccno,pAmnt)
       {
           minBal = 500;
       }
       double depAmnt(double dAmnt)
       {
           Balance = Balance + dAmnt;
           return(Balance);
       }
       double wdrawAmnt(double wAmnt)
       {
           if(wAmnt <= Balance)
               Balance = Balance - wAmnt;
           else
               cout << "You have in sufficient funds!" << endl;
           return(Balance);
       }
       void setMinBal(double mBal)
       {
           minBal = mBal;
       }
       void showAccNo()
       {
           cout << endl;
           cout << " ---------------------------------" << endl;
           cout << " ||        Account Info           " << endl;
           cout << " ---------------------------------" << endl;
           cout << " || Account Number :" << accountNumber << endl;
           cout << " || Account Balance:" << Balance << endl;
           cout << " ---------------------------------" << endl;
           cout << endl;
       }
};

int main() // main function
   {
       double amount;
       int choice;
       do
       {
           cout << endl;
           cout << "       Create an Account      " << endl;
           cout << " *****************************" << endl;
           cout << " ** 1 - Checking Account   **" << endl;
           cout << " ** 2 - Saving Account     **" << endl;
           cout << " ** 3 - Exit               **" << endl;
           cout << " *****************************" << endl;
           cin >> choice;
           cout << endl;
          
           if(choice==1)
           {
               cout << "Enter account number: " << endl;
               int Accno;
               cin >> Accno;
               cout << "Enter opening balance: " << endl;
               double newBal;
               cin >> newBal;
               double intRate;
               cout << "Enter interest rate: " << endl;
               cin >> intRate;
               CheckingAccount obj(Accno,newBal,intRate);
               int accChoice;
               do
               {
                   cout << endl;
                   cout << " *************************" << endl;
                   cout << " ** 1 - Deposit        **" << endl;
                   cout << " ** 2 - Withdraw       **" << endl;
                   cout << " ** 3 - Account Info   **" << endl;
                   cout << " ** 4 - Exit           **" << endl;
                   cout << " *************************" << endl;
                   cin >> accChoice;
                   cout << endl;
                   switch(accChoice)
                   {
                   case 1:
                       cout << "Enter amount: " << endl;
                       cin >> amount;
                       double dAmnt;
                       dAmnt = obj.depAmnt(amount);
                       cout << "Available balance: " << dAmnt << endl;
                       break;
                   case 2:
                       cout << "Enter amount: " << endl;
                       cin >> amount;
                       double wAmnt;
                       wAmnt = obj.wdrawAmnt(amount);
                       cout << "Available balance: "<< wAmnt << endl;
                       break;
                   case 3:
                       obj.showAccNo();
                       break;
                   }
               }

               while(accChoice!=4);
           }
           else if(choice==2)
           {
               cout << "Enter account number:" << endl;
               int pAccno;
               cin >> pAccno;
               cout << "Enter opening balance:" << endl;
               double pnewBal;
               cin >> pnewBal;
               double _irate;
               cout << "Enter interest rate:" << endl;
               cin >> _irate;
               SavingAccount sObj(pAccno,pnewBal);
               int pChoice;
               do
               {
                   cout << endl;
                   cout << " *************************" << endl;
                   cout << " ** 1 - Deposit        **" << endl;
                   cout << " ** 2 - Withdraw       **" << endl;
                   cout << " ** 3 - Account Info   **" << endl;
                   cout << " ** 4 - Exit           **" << endl;
                   cout << " *************************" << endl;
                   cin>>pChoice;
                   cout << endl;
                   switch(pChoice)
                   {
                   case 1:
                       cout << "Enter amount:" << endl;
                       cin >> amount;
                       double _dAmnt;
                       _dAmnt = sObj.depAmnt(amount);
                       cout << "Available balance: " << _dAmnt;
                       break;
                   case 2:
                       cout << "Enter amount:" << endl;
                       cin >> amount;
                       double _wamount;
                       _wamount = sObj.wdrawAmnt(amount);
                       cout << "Available balance: " << _wamount;
                       break;
                   case 3:
                       sObj.showAccNo();
                       break;
                   case 4:
                       break;
                   default:
                       cout << "Invalid choice";
                       break;
                   }
               }
               while(pChoice!=4);
           }
       }
       while(choice!=3);
}

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