Answer to Question #243588 in C++ for cdcs

Question #243588

Create an abstract class 'Bank' with an abstract method 'getBalance'. $100, $150 and $200 are deposited in banks A, B and C respectively. 'BankA', 'BankB' and 'BankC' are subclasses of class 'Bank', each having a method named 'getBalance'. Call this method by creating an object of each of the three classes


1
Expert's answer
2021-09-28T06:23:25-0400
#include <iostream>

class Bank {
public:
    virtual void getBalance() {}
};


class BankA : public Bank {
public:
    void getBalance() override {
        std::cout << "Deposited Balance is = $100" << std::endl;
    }
};

class BankB : public Bank {
public:
    void getBalance() override {
        std::cout << "Deposited Balance is = $150" << std::endl;
    }
};

int main() {

    Bank bank;
    bank.getBalance();
    BankA bankA;
    bankA.getBalance();
    BankB bankB;
    bankB.getBalance();

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS