195k views
2 votes
Write code that will create an array of 300 BankAccount objects. You are only to instantiate two of them. The object with index 47 should have a beginning balance of $92, and index 102 should have $1007. The name of your array will be ba.

1 Answer

5 votes

Answer:

C++

#include <iostream>

using namespace std;

////////////////////////////////////////////

class BankAccount {

int balance;

public:

BankAccount() {

balance = 0;

}

void setBalance(int balance) {

this->balance = balance;

}

};

////////////////////////////////////////////

int main() {

BankAccount ba[300];

ba[47].setBalance(92);

ba[102].setBalance(1007);

return 0;

}

Step-by-step explanation:

Create class BankAccount. Create constructor and define setBalance method.

In main function, declare "ba" array with 300 objects of type BankAccount.

And use the public setBalance method to set the required balance value.

User Himadri Ganguly
by
4.8k points