Close
Close

I am Tired

   MohsinAli

A boy has his money deposited $1000, $1500 and $2000 in banks-Bank A, Bank B and Bank C respectively. We have to print the money deposited by him in a particular bank. Create a class 'Bank' with a method 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a method with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the method 'getBalance' by the object of each of the three banks.


Answers

  •    musfiraattiqueasher


    #include 
    using namespace std;
    
    class bank
    {
        protected:
            int balance;
        public:
            int getbalance()
            {
                return balance;
            }
    };
    class bankA : bank
    {
        public:
            bankA(int b)
            {
                balance=b;
            }
            void display()
            {
                cout << "The amount deposited in bank A:$" << balance << endl;
            }
    };
    class bankB : bank
    {
        public:
            bankB(int b)
            {
                balance=b;
            }
            void display()
            {
                cout << "The amount deposited in bank B:$" << balance << endl;
            }
    };
    class bankC : bank
    {
        public:
            bankC(int b)
            {
                balance=b;
            }
            void display()
            {
                cout << "The amount deposited in bank C:$" << balance << endl;
            }
    };
    
    
    int main()
    {
        bankA balanceA(1000);
        balanceA.display();
        bankB balanceB(1500);
        balanceB.display();
        bankC balanceC(2000);
        balanceC.display();
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    // #include
    // using namespace std;
    
    // // 1 + 4i
    // // 5 + 8i
    // // -------
    // // 6 + 12i 
    // class Complex{
    //     int a, b;
    //     friend Complex sumComplex(Complex o1, Complex o2);
    //     public:
    //         void setNumber(int n1, int n2){
    //             a = n1;
    //             b = n2;
    //         }
    
    //         // Below line means that non member - sumComplex funtion is allowed to do anything with my private parts (members)
    //         void printNumber(){
    //             cout<<"Your number is "<
    


Ask Yours
Post Yours
Write your answer