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

I have the program written, but I\'d like the comments added. #include <iostream

ID: 664443 • Letter: I

Question

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
   {
       public:
       int accountNumber;   //varaiable to hold account number
       double Balance;   //variable to hold the account balance

public:
   BankAccount(int Accno,double Bal)   //parameterized constructor
   {
       accountNumber = Accno;   //set the account no.
       Balance = Bal;   //set the balance
   }
   BankAccount()   //empty default constructor
   {
   }
public:
   double getBal()
   {
       return(Balance);   //return the account balance
   }
   int getAccNo()
   {
       return(accountNumber);   //return the acoount no.
   }
   void setBal(double amount)
   {
       Balance = amount;   //set the account balance
   }
   void setAccNo(int Accno)
   {
       accountNumber = Accno;   //set the account no.
   }
   void virtual showAccNo()   //display the account 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;   //add the deposited amount to the existing balance
       return(Balance);   //return the new balance
   }

   double virtual wdrawAmnt(double wAmnt)
   {
       Balance = Balance - wAmnt;   //subtract the deposited amount from the existing balance
       return(Balance);   //return the reduced account balance
   }
};

class CheckingAccount : BankAccount
{
   double Intrst;   //variable to hold the interest
   double minBal;   //variable to hold the minimum balance
   double serChge;   //variable to hold the service charge

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

   void setIntRate(double intRate)
   {
       Intrst = intRate;   //set the interest rate
   }

   double retIntRate()
   {
       return(Intrst);   //retturn the interest rate
   }

   void setMinBal(double mBal)
   {
       minBal = mBal;   //set the minimum balance
   }

   double retMinBal()
   {
       return(minBal);   //return the minimum balance
   }

   void setSerChge(double sCharge)
   {
       serChge = sCharge;   //set the service charge
   }

   double retSerChge()
   {
       return(serChge);   //return the service charge
   }

   double depAmnt(double dAmnt)
   {
       Balance = Balance + dAmnt;   //add the deposited amount to the existing balance
       return(Balance);   //return the new balance
   }

   double wdrawAmnt(double wAmnt)
   {
       if(wAmnt <= Balance)   //chek if there is there is sufficient fund to be withdrawn
           Balance = Balance - wAmnt;   //subtract the amount withdrawn from the balance
       else
           cout << "You have insufficient funds!" << endl;   //insufficient fund
       return(Balance);   //return the new balance
   }

   void showAccNo()   //display account details
   {
           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;   //variable to hold the minimum balance
   public:
       SavingAccount(int pAccno,double pAmnt):BankAccount(pAccno,pAmnt)   //parameterized constructor
       {
           minBal = 500;   //initialize the minimum balance for savings account
       }
       double depAmnt(double dAmnt)
       {
           Balance = Balance + dAmnt;   //add the deposited amount to the existing balance
           return(Balance);   //return the updated balance
       }
       double wdrawAmnt(double wAmnt)
       {
           if(wAmnt <= Balance)   //chek if there is there is sufficient fund to be withdrawn
               Balance = Balance - wAmnt;   //subtract the amount withdrawn from the balance
           else
               cout << "You have in sufficient funds!" << endl;   //insufficient fund
           return(Balance);   //return the new balance
       }
       void setMinBal(double mBal)
       {
           minBal = mBal;   //set the minimum balance
       }
       void showAccNo()   //display the account details
       {
           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;   //vaiable to hold the amount
       int choice;   //variable to hold the user's choice
       do
       {
           cout << endl;
       /*display the menu*/
           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;   //accept the user's chocie
           cout << endl;
        
           if(choice==1)
           {
               cout << "Enter account number: " << endl;
               int Accno;   //variable to hold the account no.
               cin >> Accno;   //accept the account no.
               cout << "Enter opening balance: " << endl;
               double newBal;   //variable to hold the opening balance
               cin >> newBal;   //accept the opening balance
               double intRate;   //varaiable to hold the interest rate
               cout << "Enter interest rate: " << endl;
               cin >> intRate;   //accept the interest rate
               CheckingAccount obj(Accno,newBal,intRate);   //create and initialize a checking account
               int accChoice;   //varaiable to hold user's choice to be done with the account
               /*display the account related menu*/
           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;   //accept the deposit amount
                       double dAmnt;
                       dAmnt = obj.depAmnt(amount);   //deposit the amount
                       cout << "Available balance: " << dAmnt << endl;
                       break;
                   case 2:
                       cout << "Enter amount: " << endl;
                       cin >> amount;   //accept the amount wished to be withdrawn
                       double wAmnt;
                       wAmnt = obj.wdrawAmnt(amount);   //withdaw the amount
                       cout << "Available balance: "<< wAmnt << endl;
                       break;
                   case 3:
                       obj.showAccNo();   //display the account details
                       break;
                   }
               }

               while(accChoice!=4);   //continue while user's chooses not to exit
           }
           else if(choice==2)
           {
               cout << "Enter account number:" << endl;
               int pAccno;   //variable to hold the account no.
               cin >> pAccno;   //accpt the account no.
               cout << "Enter opening balance:" << endl;
               double pnewBal;   //variable to hold the opening balance
               cin >> pnewBal;   //accept the opening balance
               double _irate;   //variable to hold interest rate
               cout << "Enter interest rate:" << endl;
               cin >> _irate;   //accpet the interest rate
               SavingAccount sObj(pAccno,pnewBal);   //create and initialize a savings account
               int pChoice;   //varaiable to hold user's choice related to the account
               /*display the account related menu*/
           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;   //accept the amount to be deposited
                       double _dAmnt;
                       _dAmnt = sObj.depAmnt(amount);   //deposit the amount
                       cout << "Available balance: " << _dAmnt;
                       break;
                   case 2:
                       cout << "Enter amount:" << endl;
                       cin >> amount;   //accept the amount wished to be withdrawn
                       double _wamount;
                       _wamount = sObj.wdrawAmnt(amount);   //withdraw the amount
                       cout << "Available balance: " << _wamount;
                       break;
                   case 3:
                       sObj.showAccNo();   //display the account details
                       break;
                   case 4:
                       break;   //exit
                   default:
                       cout << "Invalid choice";   //invalid option is selected
                       break;
                   }
               }
               while(pChoice!=4);   //continue while user's chooses not to exit
           }
       }
       while(choice!=3);   //continue while user's chooses not to exit
}