Hot Posts

C++ Classes ,Define the class bank Account to store a bank customer’s account number and balance.



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.

  • Derive the class checkingAccount from the class bankAccount. This class inherits members to store the account number and the balance from the base class. Add member variables to store minimum balance and service charges amount if the balance falls below the minimum balance as additional information. In addition to the operations inherited from the base class, this class should provide the following member functions to performs: set interest rate, retrieve interest rate, set minimum balance, retrieve minimum balance and set service charges, 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.
  • Derive the class savingsAccount from the class bankAccount. This class inherits members to store the account number and the balance from the base class. Along with this some additional members to a savings account that typically receives interest, makes deposits, and withdraws money. In addition to the operations inherited from the base class, this class should provide the following additional member functions to do: set interest rate, retrieve interest rate, post interest, withdraw (override the method of the base class), and print account information. Add appropriate constructors.


solution :

                                                                input 

 #include <iostream>

#include <conio.h>

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

}




Post a Comment

0 Comments