This exercise that i'm trying to do reads something like this at one point:
1 - Generate a unique account number for each depositor For the first depositor, account number will be BA1000, for the second depositor it will be BA1001 and so on.
2 - The number of depositors will be entered by user from keyboard.
So, i know the code below is not enough, but i just cannot understand how am i supposed to know the number of objects(depositors) before the user enters them, so i can use that number inside my generateAccount function, so i can know for how long to loop through depositors to get that "BA1000" style bank account.
#include <iostream>
using namespace std;
class BankAccount {
public:
string depistor_name;
string depositor_address;
string account_type;
int account_balance, nr_transactions;
void generateAccount () {
string acc = "BA";
int acc_nr = 1000;
for ( int i = 0; i < //unknown number of objects so i have no variable to put here ; i++) {
// below are comments of what i would need to do with this function
// iterate and add +i to the acc_nr variable, until theres no more depositors.
// print "BA" string + new acc_nr variable for each object
}
};
int main(int argc, const char * argv[]) {
return 0;
}
If i wouldn't need to use the number of objects(depositors) that the user would enter from keyboard, i would normally just create an array of objects like so:
int x;
std::cout << "Please enter number of depositors";
cin >> x;
BankAccount ac[x];
But i need to know how many depositors the user is going to enter so i can iterate and generate the account as shown above and i dont know if theres a way to pull x from main inside my function thats inside my class.
Please ask for more details if you don't understand what i'm trying to say as this may be confusing.