Answer to Question #309839 in C++ for Nitik

Question #309839

Create a class 'Bank' with a function 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a function with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the function 'getBalance' by the object of each of the three banks.


1
Expert's answer
2022-03-11T11:53:01-0500
#include <iostream>
using namespace std;


class Bank {
public:
    int getBalance() { return 0; }    
};


class BankA : public Bank {
public:
    int getBalance() { return 10; }    
};


class BankB : public Bank {
public:
    int getBalance() { return 20; }    
};


class BankC : public Bank {
public:
    int getBalance() { return 30; }    
};


int main() {
    BankA bank1;
    BankB bank2;
    BankC bank3;

    cout << "BankA balance: $" << bank1.getBalance() << endl;
    cout << "BankB balance: $" << bank2.getBalance() << endl;
    cout << "BankC balance: $" << bank3.getBalance() << endl;

    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