Hello
I am creating a bank account for an assignment and the account number must be automatically generated with consecutive numbers. I have written some code that works, but now I need to know how to use it in conjunction with my Account class, especially how to add it to my class constructor. I have the code below, the whole program doesn't compile and I am working at it one chunk at a time. The first piece of code is the accountNumber class which gives a new incremented account number each time it is called. The second part is my Account class and how I think it has to be added. Thank you in advance.
#include "stdafx.h"
#include <iostream>
using namespace std;
class AccountNumber
{
private:
static int accountNumber;
public:
static int addNum()
{ accountNumber++;
cout << "new account number is :" << accountNumber << endl;
return accountNumber;
}
static int getAccountNumber()
{
return accountNumber;
}
};
int AccountNumber::accountNumber = 1000;
int main()
{
AccountNumber::addNum();
AccountNumber::addNum();
AccountNumber::addNum();
AccountNumber::addNum();
AccountNumber::addNum();
AccountNumber::addNum();
system ("Pause");
return 0;
}
class Account
{
protected: //these are protected since there are child classes
AccountNumber accountNumber;
double accountBalance;
public:
Account(AccountNumber acctNum, double bal); //I have my doubts about this
void enterAccountData(AccountNumber acctNum, double bal); // and this
void displayAccount();
};
and finally my Account constructor
Account::Account (AccountNumber acctNum, double bal)
{
AccountNumber accountNumber = acctNum;
accountBalance = bal;
}