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

a) Define the class bankAccount to store a bank customer\'s account number and b

ID: 3684808 • Letter: A

Question

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).

Explanation / Answer

#include<iostream>

using namespace std;

class bankAccount{
  
   private:
       int accountNumber;
       double balance;
   public:
       bankAccount(){
          
       }
       bankAccount(int number, double bal){
           accountNumber = number;
           balance = bal;
       }
      
       void setAccountNumber(int num){
           accountNumber = num;
       }
      
       void setBalance(double bal){
           balance = bal;
       }
       int getAccountNumber(){
           return accountNumber;
       }
      
       double getBalance(){
           return balance;
       }
      
       void deposite(double amount){
           balance = balance + amount;
       }
      
       double withdraw(double amount){
           if((balance - amount) < 0 ){
               cout<<"Insuddicient balance ";
               return 0;
           }
          
           balance = balance - amount;
          
           return amount;
       }
       void printAccountInfo(){
           cout<<"Account Number: "<<getAccountNumber()<<endl;
           cout<<"Balance: "<<getBalance()<<endl;
       }
};

//CheckingAccount

class checkingAccount : public bankAccount{
  
   private :
       double interestRate;
       double min_balance;
       double service_charge;
   public:
       checkingAccount(int acc_num, double balance): bankAccount(acc_num, balance){
          
       }
       checkingAccount(int acc_num, double balance, double rate, double min, double charge): bankAccount(acc_num, balance){
           interestRate = rate;
           min_balance = min;
           service_charge = charge;
       }
      
       void setInterestRate(double rate){
           interestRate = rate;
       }
      
       void setMinBalance(double min){
           min_balance = min;
       }
      
       void setServiceCharge(double charge){
           service_charge = charge;
       }
      
       double getInterestRate(){
           return interestRate;
       }
       double getMinBalance(){
           return min_balance;
       }
       double getServiceCharge(){
           return service_charge;
       }
      
       bool check(){
          
           double interest = getBalance()*interestRate/100.0;
           double totalBalance = getBalance() + interest;
          
           if(totalBalance < min_balance){
               return true; // balance is less than minimum balance
           }
           else
               return false;
       }
      
       double withdraw(double amount){
          
           bool isBelowMin = check();
          
           double interest = getBalance()*interestRate/100.0;
           double totalBalance = getBalance() + interest;
          
           if(isBelowMin){ // service charge is aplicable
              
               double newamount = amount + service_charge;
              
               if(totalBalance < newamount){
                   cout<<"Insufficient balance ";
                   return 0;
               }
              
               setBalance(totalBalance - newamount);
               return amount;
           }
           else{
              
               if(totalBalance < amount){
                   cout<<"Insufficient balance ";
                   return 0;
               }
               else{
                   setBalance(totalBalance - amount);
                   return amount;
               }
           }
       }
      
       void printAccountInfo(){
           cout<<"Account Number: "<<getAccountNumber()<<endl;
           cout<<"Balance: "<<getBalance()<<endl;
           cout<<"Interest rate: "<<interestRate<<endl;
           cout<<"Service charge: "<<service_charge<<endl;
           cout<<"Minimum Balance: "<<min_balance<<endl;
       }
  
};

//Saving Account

class savingAccount: public bankAccount{
  
   private:
       double interestRate;
   public:
       savingAccount(int acc_num, double bal): bankAccount(acc_num, bal){
      
       }
       savingAccount(int acc_num, double bal, double rate): bankAccount(acc_num, bal){
           interestRate = rate;
       }
      
       void setInterestRate(double rate){
           interestRate = rate;
       }
       double getInterestRate(){
           return interestRate;
       }
      
       double withdraw(double amount){
          
           double interest = getBalance()*interestRate/100.0;
           double totalBalance = getBalance() + interest;
          
           if(totalBalance < amount){
               cout<<"Insufficient balance ";
               return 0;
           }
           else{
               setBalance(totalBalance - amount);
               return amount;
           }
       }
       void printAccountInfo(){
           cout<<"Account Number: "<<getAccountNumber()<<endl;
           cout<<"Balance: "<<getBalance()<<endl;
           cout<<"Interest rate: "<<interestRate<<endl;
       }
};


// Main method

int main(){
  
   checkingAccount *checkingAcc = new checkingAccount(123, 456.34);
  
   checkingAcc->setInterestRate(3);
   checkingAcc->setMinBalance(300);
   checkingAcc->setServiceCharge(6);
  
   checkingAcc->printAccountInfo();
  
   cout<<endl;
  
   savingAccount *savingAcc = new savingAccount(342, 560);
   savingAcc->setInterestRate(4);
  
   savingAcc->printAccountInfo();
  
   return 0;
}


/*

sample output:

Account Number: 123
Balance: 456.34
Interest rate: 3
Service charge: 6
Minimum Balance: 300

Account Number: 342
Balance: 560
Interest rate: 4

*/