Here is my code for the program. which I'm trying to complie...I just started testing it and was going through it step by step...but the first function whichI started testing is getAccountNumbers, but there are some issues with it, here's the code, it has Person file included in it, it just takes the detais of the person.

#include<cstdlib>
#include<string>
#include<time.h>
#include"Person.h"
#include<iostream>
using namespace std;

typedef Person* PersonPtr;
class BankAccount{
public:
	//friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount); 
	//friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
	//friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
	BankAccount();
  	BankAccount(const Person& aPerson);
/**	double withdrawal(double aAmount);
	double deposit(double aAmount);*/
	size_t getAccountNumber() const;
	/**void setBalance(double aBalance);
	double getBalance() const;
	void setAccountOwner(const Person& aPerson);
	Person getAccountOwner() const;
	bool sufficientFundsToWithdrawal(double aAmount) const;*/
private: 
	PersonPtr mPerson;
	//mAmount;
	double mBalance;	
	 size_t mAccountNumber;
};
//#endif

int main() {
//BankAccount ba;
	Person p;
cout <<"running";
getAccountNumber();
//cin >> ba; 
	//cout << ba;

	return 0;
}

/**
ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
	cout << "A new account with account number";
	aOutput << aBankAccount.mAccountNumber << endl;
	cout << "has been created for";
	aOutput << aBankAccount.mPerson << endl;
	return aOutput;
}
istream&  operator >> (istream &aInput, BankAccount& aBankAccount){
	cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
	aInput >> aBankAccount.mBalance;
	aInput >> aBank.mPerson;

cout << "type the first name\n;
	aInput >> aBankAccount.mFName;
	cout << "type the last name\n;
	aInput >> aBankAccount.mLName;
	cout << "Type the address\n";
	aInput >> aBankAccount.mAddress;
	cout << "type the name of the state\n";
	aInput >> aBankAccount.mState;
	cout << "type the name of the city\n";
	aInput >> aBankAccount.mCity;
	cout << "type the zip code\n";
	aInput >> aBankAccount.mZip;
	
	return aInput;
}
bool  operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
	return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
		aBankAccount1.mBalance == aBankAccount2.mBalance &&
	       	aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
}
BankAccount::BankAccount(){
	mPerson = new Person;
	mBalance = 5.00;
	mAccountNumber = getAccountNumber();
}

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person), mBalance(5.00),mAccountNumber(getAccountNumber()){
}
void  setAccountOwner (const Person& aPerson){
	mPerson =  new Person;
}
Person  getAccountOwner () const{
	return mPerson;
}
double  withdrawal (double aAmount){
	double newBalance =  Balance - aAmount;
	setBalance(newBalance);
	getBalance();
	//return aBalance;
		
} 

double  deposit (double aAmount){
	double newBalance =  newBalance + aAmount; 
	aBankAccount.setBalance(newBalance);
	aBankAccount.getBalance ();
	
}*/
size_t  getAccountNumber () const {
	srand(static_cast<unsigned int>(time(NULL)));
	mAccountNumber = rand();
	return  mAccountNumber;
}/**
void  setBalance (double aBalance) {
	mBalance = aBalance;
}
double  getBalance () const{
	return mBalance;
}  
bool sufficientFundsToWithdrawal (double aAmount) const {
	if((aAmount - aBalance) > 5){
		return true;
	}
	else {
		return false;
	}
}
*/

I'm trying to test only the getAccountNumber function here . But the compiler giives me error like this:

1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(37) : error C3861: 'getAccountNumber': identifier not found
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(105) : error C2270: 'getAccountNumber' : modifiers not allowed on nonmember functions
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(107) : error C2065: 'mAccountNumber' : undeclared identifier
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(108) : error C2065: 'mAccountNumber' : undeclared identifier


Please help me figure out how to handle that size_t type an wy its complainig that mAccountNumber identifier is undeclared.

Here is my code for the program. which I'm trying to complie...I just started testing it and was going through it step by step...but the first function whichI started testing is getAccountNumbers, but there are some issues with it, here's the code, it has Person file included in it, it just takes the detais of the person.

#include<cstdlib>
#include<string>
#include<time.h>
#include"Person.h"
#include<iostream>
using namespace std;

typedef Person* PersonPtr;
class BankAccount{
public:
	//friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount); 
	//friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
	//friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
	BankAccount();
  	BankAccount(const Person& aPerson);
/**	double withdrawal(double aAmount);
	double deposit(double aAmount);*/
	size_t getAccountNumber() const;
	/**void setBalance(double aBalance);
	double getBalance() const;
	void setAccountOwner(const Person& aPerson);
	Person getAccountOwner() const;
	bool sufficientFundsToWithdrawal(double aAmount) const;*/
private: 
	PersonPtr mPerson;
	//mAmount;
	double mBalance;	
	 size_t mAccountNumber;
};
//#endif

int main() {
//BankAccount ba;
	Person p;
cout <<"running";
getAccountNumber;
//cin >> ba; 
	//cout << ba;

	return 0;
}

/**
ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
	cout << "A new account with account number";
	aOutput << aBankAccount.mAccountNumber << endl;
	cout << "has been created for";
	aOutput << aBankAccount.mPerson << endl;
	return aOutput;
}
istream&  operator >> (istream &aInput, BankAccount& aBankAccount){
	cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
	aInput >> aBankAccount.mBalance;
	aInput >> aBank.mPerson;

cout << "type the first name\n;
	aInput >> aBankAccount.mFName;
	cout << "type the last name\n;
	aInput >> aBankAccount.mLName;
	cout << "Type the address\n";
	aInput >> aBankAccount.mAddress;
	cout << "type the name of the state\n";
	aInput >> aBankAccount.mState;
	cout << "type the name of the city\n";
	aInput >> aBankAccount.mCity;
	cout << "type the zip code\n";
	aInput >> aBankAccount.mZip;
	
	return aInput;
}
bool  operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
	return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
		aBankAccount1.mBalance == aBankAccount2.mBalance &&
	       	aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
}
BankAccount::BankAccount(){
	mPerson = new Person;
	mBalance = 5.00;
	mAccountNumber = getAccountNumber();
}

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person), mBalance(5.00),mAccountNumber(getAccountNumber()){
}
void  setAccountOwner (const Person& aPerson){
	mPerson =  new Person;
}
Person  getAccountOwner () const{
	return mPerson;
}
double  withdrawal (double aAmount){
	double newBalance =  Balance - aAmount;
	setBalance(newBalance);
	getBalance();
	//return aBalance;
		
} 

double  deposit (double aAmount){
	double newBalance =  newBalance + aAmount; 
	aBankAccount.setBalance(newBalance);
	aBankAccount.getBalance ();
	
}*/
size_t  getAccountNumber () const {
	srand(static_cast<unsigned int>(time(NULL)));
	mAccountNumber = rand();
	return  mAccountNumber;
}/**
void  setBalance (double aBalance) {
	mBalance = aBalance;
}
double  getBalance () const{
	return mBalance;
}  
bool sufficientFundsToWithdrawal (double aAmount) const {
	if((aAmount - aBalance) > 5){
		return true;
	}
	else {
		return false;
	}
}
*/

I'm trying to test only the getAccountNumber function here . But the compiler giives me error like this:

1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(37) : error C3861: 'getAccountNumber': identifier not found
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(105) : error C2270: 'getAccountNumber' : modifiers not allowed on nonmember functions
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(107) : error C2065: 'mAccountNumber' : undeclared identifier
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(108) : error C2065: 'mAccountNumber' : undeclared identifier


Please help me figure out how to handle that size_t type an wy its complainig that mAccountNumber identifier is undeclared.

size_t is not the problem here. The problem is the way you have set up your class and the function call. Change line 104 to this:

size_t BankAccount::getAccountNumber () const{

This tells the compiler that this function is part of the BankAccount class.

Line 36: This isn't a function call. Try changing it to something line this:

size_t acctNum = p.getAccountNumber ();

This is assuming that the getAccountNumber function you want to call is the one that is part of the BankAccount class.

If you are going to set the value of mAccountNumber inside BankAccount::getAccountNumber(), then the function must be non-const, i.e. you need to have it like:

size_t BankAccount::getAccountNumber ()
{
     // set the value here ...
}
#include<cstdlib>
#include<string>
#include<time.h>
#include"Person.h"
#include<iostream>
using namespace std;

typedef Person* PersonPtr;
class BankAccount{
public:
	//friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount); 
	//friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
	//friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
	BankAccount();
  	BankAccount(const Person& aPerson);
/**	double withdrawal(double aAmount);
	double deposit(double aAmount);*/
	size_t getAccountNumber() const;
	/**void setBalance(double aBalance);
	double getBalance() const;
	void setAccountOwner(const Person& aPerson);
	Person getAccountOwner() const;
	bool sufficientFundsToWithdrawal(double aAmount) const;*/
private: 
	PersonPtr mPerson;
	//mAmount;
	double mBalance;	
	 size_t mAccountNumber;
};
//#endif

int main() {
BankAccount ba;
	//Person p;
cout <<"running";
ba.getAccountNumber();
//cin >> ba; 
	//cout << ba;

	return 0;
}

/**
ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
	cout << "A new account with account number";
	aOutput << aBankAccount.mAccountNumber << endl;
	cout << "has been created for";
	aOutput << aBankAccount.mPerson << endl;
	return aOutput;
}
istream&  operator >> (istream &aInput, BankAccount& aBankAccount){
	cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
	aInput >> aBankAccount.mBalance;
	aInput >> aBank.mPerson;

cout << "type the first name\n;
	aInput >> aBankAccount.mFName;
	cout << "type the last name\n;
	aInput >> aBankAccount.mLName;
	cout << "Type the address\n";
	aInput >> aBankAccount.mAddress;
	cout << "type the name of the state\n";
	aInput >> aBankAccount.mState;
	cout << "type the name of the city\n";
	aInput >> aBankAccount.mCity;
	cout << "type the zip code\n";
	aInput >> aBankAccount.mZip;
	
	return aInput;
}
bool  operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
	return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
		aBankAccount1.mBalance == aBankAccount2.mBalance &&
	       	aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
}
BankAccount::BankAccount(){
	mPerson = new Person;
	mBalance = 5.00;
	mAccountNumber = getAccountNumber();
}

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person), mBalance(5.00),mAccountNumber(getAccountNumber()){
}
void  setAccountOwner (const Person& aPerson){
	mPerson =  new Person;
}
Person  getAccountOwner () const{
	return mPerson;
}
double  withdrawal (double aAmount){
	double newBalance =  Balance - aAmount;
	setBalance(newBalance);
	getBalance();
	//return aBalance;
		
} 

double  deposit (double aAmount){
	double newBalance =  newBalance + aAmount; 
	aBankAccount.setBalance(newBalance);
	aBankAccount.getBalance ();
	
}*/
size_t BankAccount::getAccountNumber () const{
	srand(static_cast<unsigned int>(time(NULL)));
	mAccountNumber = rand();
	return  mAccountNumber;
}/**
void  setBalance (double aBalance) {
	mBalance = aBalance;
}
double  getBalance () const{
	return mBalance;
}  
bool sufficientFundsToWithdrawal (double aAmount) const {
	if((aAmount - aBalance) > 5){
		return true;
	}
	else {
		return false;
	}
}
*/

i edited the things which u told to do, and it has really solved those of the errors, but now a new error is showing up:
it is like this:
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(107) : error C2166: l-value specifies const object


what is this l-value ?

In my code the line 107 is

mAccountNumber = rand();

so it's complainig about this line

Whoops, gave some bad advice. p is type Person, not BankAccount so this won't work:

p.getAccountNumber ()

You'll want to create a variable of type BankAccount:

BankAccount ba = new BankAccount ();
ba.getAccountNumber ();

Also, see mitrmkar's post and remove the const modifier.

you know I'm not using any set function for creating a bank account, so once this value is returned in getBankAccountNumber, it won't be changed after that. this way every person would have a unique accountnumber.

so I have to declare it as a const(means we won't be changing it's value once it's created)

regarding the variable for BankAccount I did create a variable for BankAccount as
BankAccount ba
& then I did like

ba.getAccountNumber();

but not clear why you have allocated dynamic memory to bankAccount here in

BankAccount ba = new BankAccount ();

do we really need to do this, It won't work without doing this?

MITRMKAR do you agree with what i wrote in my last post regarding use of const.
i guess this should work?

If no then . i think I will need to include set function even and have the chances of changing the value of bankAccount, which was created before creating any bank account.

you know I'm not using any set function for creating a bank account, so once this value is returned in getBankAccountNumber, it won't be changed after that. this way every person would have a unique accountnumber.

so I have to declare it as a const(means we won't be changing it's value once it's created)

regarding the variable for BankAccount I did create a variable for BankAccount as
BankAccount ba
& then I did like

ba.getAccountNumber();

but not clear why you have allocated dynamic memory to bankAccount here in

BankAccount ba = new BankAccount ();

do we really need to do this, It won't work without doing this?

I hadn't noticed your updated code when I posted. Dynamic versus non-dynamic shouldn't matter:

BankAccount ba;

should work fine.

Regarding the const modifier, if it was me, I'd have a set function. Seems like the easiest way to do it. If you want to do it with the get function and not have a set function, I can't think of a way to do it with the const modifier. Maybe there is one, but even if there is a way, I'd have a set function anyway since I think it's more descriptive. Anyway, that's just my opinion. I'd have a setAccountNumber () function which you call once and have that function not have a const modifier, then have a getAccountNumber () and put the const modifier on that function. Have the bank account number be set using rand in the setAccountNumber and then just have the getAccountNumber function return the value and put the const modifier on it. That's how I'd do it.

Hmm .. if you have a member function of a class declared as const, then you are not to modify the class instance's data. If you can cope with it, then fine. (I'm not fully following with what you wrote, sorry).

You might have a generateAccountNumber() which returns the generated new value that you can assign to a newly created account object and leave the const getBankAccountNumber() for just returning the pre-set account number.

If I try to use this in my main:

srand(static_cast<unsigned int>(time(NULL)));
	mAccountNumber = rand();
               cout << mAccountNumber

And remove that getAccountNumber function from this program, will it work ??

This is how I'm told to use this function:


To set the account number to a unique number you should use the functions:

srand(static_cast<unsigned int>(time(NULL))) and rand() functions

srand(static_cast<unsigned int>(time(NULL)) sets the seed to the current time for the random number generation.
this is the number that is the starting point for the unique number rand() generates the random number. So to create your unique number, use:

srand(static_cast<unsigned int>(time(NULL)));
mAccountNumber = rand();

& this is what I'm told about set Function: told not to use it:(
"
Although we're implementing an ADT, we leave the setAccountNumber out because this is generated when the BankAccount is created and should not be changed once the BankAccount is created."

If I use that code for generating a unique # whithout having any getAccountNumber function then even i get these for these two lines in main:

int main() {
BankAccount ba ;
    cout <<"running";
//ba.getAccountNumber();
srand(static_cast<unsigned int>(time(NULL)));
    mAccountNumber = rand();
    cout <<  mAccountNumber;
return 0;
}

1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(39) : error C2065: 'mAccountNumber' : undeclared identifier
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(40) : error C2065: 'mAccountNumber' : undeclared identifier

Edited 3 Years Ago by Reverend Jim: Fixed formatting

A short example, the rand() function is directly used in the constructor, and the
getAccountNumber() can now be const.
Note that you need to call srand() only once.

class BankAccount
{
public:
    // constructor
    BankAccount()
    {
        // set the number here 
        mAccountNumber = rand();
    }
    size_t getAccountNumber() [B]const [/B]{ return mAccountNumber; }
private:
 size_t mAccountNumber;
};

int  main()
{
    // seed the random number generator at the beginning of main()
    srand(static_cast<unsigned int>(time(NULL)));
    // rest of the program follows
}

mAccountNumber is a member variable of BankAccount class, hence you need an instance of that class in the first place. So you might write something like

int main() 
{
    srand(static_cast<unsigned int>(time(NULL)));

    BankAccount ba;

    // given that the mAccountNumber were a public member variable,
    // the following assignment would work
    ba.mAccountNumber = rand();
    cout <<  ba.mAccountNumber;

    return 0;
}

Actually one of your posts says that "we leave the setAccountNumber out because this is generated when the BankAccount is created" <-> essentially this is what I suggested about using rand() in the constructor, so I think you might very well do it like that, i.e. simply

// constructor
BankAccount()
{
    // set the number here 
    mAccountNumber = rand();
}
#include<cstdlib>
#include<string>
#include<time.h>
#include"Person.h"
#include<iostream>
using namespace std;

typedef Person* PersonPtr;
class BankAccount{
public:
	//friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount); 
	//friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
	//friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
	BankAccount();
  	BankAccount(const Person& aPerson);
/**	double withdrawal(double aAmount);
	double deposit(double aAmount);*/
	size_t getAccountNumber()const;
	/**void setBalance(double aBalance);
	double getBalance() const;
	void setAccountOwner(const Person& aPerson);
	Person getAccountOwner() const;
	bool sufficientFundsToWithdrawal(double aAmount) const;*/
private: 
	PersonPtr mPerson;
	//mAmount;
	double mBalance;	
	 size_t mAccountNumber;
};
//#endif

int main() {
BankAccount ba ;
	cout <<"running";
//ba.getAccountNumber();
srand(static_cast<unsigned int>(time(NULL)));
	//mAccountNumber = rand();
	//cout <<  mAccountNumber;


//cin >> ba; 
	//cout << ba;

	return 0;
}

/**
ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
	cout << "A new account with account number";
	aOutput << aBankAccount.mAccountNumber << endl;
	cout << "has been created for";
	aOutput << aBankAccount.mPerson << endl;
	return aOutput;
}
istream&  operator >> (istream &aInput, BankAccount& aBankAccount){
	cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
	aInput >> aBankAccount.mBalance;
	aInput >> aBank.mPerson;

cout << "type the first name\n;
	aInput >> aBankAccount.mFName;
	cout << "type the last name\n;
	aInput >> aBankAccount.mLName;
	cout << "Type the address\n";
	aInput >> aBankAccount.mAddress;
	cout << "type the name of the state\n";
	aInput >> aBankAccount.mState;
	cout << "type the name of the city\n";
	aInput >> aBankAccount.mCity;
	cout << "type the zip code\n";
	aInput >> aBankAccount.mZip;
	
	return aInput;
}
bool  operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
	return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
		aBankAccount1.mBalance == aBankAccount2.mBalance &&
	       	aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
}*/
BankAccount::BankAccount(){
	mPerson = new Person;
	mBalance = 5.00;
	mAccountNumber = rand();
}

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person), mBalance(5.00),mAccountNumber(rand()){
}/**
void  BankAccount::setAccountOwner (const Person& aPerson){
	mPerson =  new Person;
}
Person  getAccountOwner () const{
	return mPerson;
}
double BankAccount:: withdrawal (double aAmount){
	double newBalance =  Balance - aAmount;
	setBalance(newBalance);
	getBalance();
	//return aBalance;
		
} 

double  BankAccount::deposit (double aAmount){
	double newBalance =  newBalance + aAmount; 
	aBankAccount.setBalance(newBalance);
	aBankAccount.getBalance ();
	
}*/
size_t BankAccount::getAccountNumber () const{
	//srand(static_cast<unsigned int>(time(NULL)));
	//mAccountNumber = rand();
	return  mAccountNumber;
}/**
void  BankAccount::setBalance (double aBalance) {
	mBalance = aBalance;
}
double BankAccount:: getBalance () const{
	return mBalance;
}  
bool BankAccount::sufficientFundsToWithdrawal (double aAmount) const {
	if((aAmount - aBalance) > 5){
		return true;
	}
	else {
		return false;
	}
}
*/

I have done as you told, now it doesnot give any errors but , how do I check which accountNumber is created...
I mean to say that I want to see th eaccountNumber created on the ouput screen after we run the program...

int main() 
{
   // Before allocating any BankAccounts ... call srand() first
   srand(static_cast<unsigned int>(time(NULL)));

    BankAccount ba1, ba2;
    // see what account numbers were given ...
    cout << "Account: " << ba1.getAccountNumber() << "\n";
    cout << "Account: " << ba2.getAccountNumber() << "\n";

    return 0;
}
#include<cstdlib>
#include<string>
#include<time.h>
#include"Person.h"
#include<iostream>
using namespace std;

typedef Person* PersonPtr;
class BankAccount{
public:
	//friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount); 
	//friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
	//friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
	BankAccount();
  	BankAccount(const Person& aPerson);
/**	double withdrawal(double aAmount);
	double deposit(double aAmount);*/
	size_t getAccountNumber()const;
	/**void setBalance(double aBalance);
	double getBalance() const;
	void setAccountOwner(const Person& aPerson);
	Person getAccountOwner() const;
	bool sufficientFundsToWithdrawal(double aAmount) const;*/
private: 
	PersonPtr mPerson;
	//mAmount;
	double mBalance;	
	 size_t mAccountNumber;
};
//#endif

int main() {
	srand(static_cast<unsigned int>(time(NULL)));
BankAccount ba ;
	cout <<"running";
//ba.getAccountNumber();

	//mAccountNumber = rand();
	cout <<  ba.getAccountNumber() << endl;


//cin >> ba; 
	//cout << ba;

	return 0;
}

/**
ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
	cout << "A new account with account number";
	aOutput << aBankAccount.mAccountNumber << endl;
	cout << "has been created for";
	aOutput << aBankAccount.mPerson << endl;
	return aOutput;
}
istream&  operator >> (istream &aInput, BankAccount& aBankAccount){
	cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
	aInput >> aBankAccount.mBalance;
	aInput >> aBank.mPerson;

cout << "type the first name\n;
	aInput >> aBankAccount.mFName;
	cout << "type the last name\n;
	aInput >> aBankAccount.mLName;
	cout << "Type the address\n";
	aInput >> aBankAccount.mAddress;
	cout << "type the name of the state\n";
	aInput >> aBankAccount.mState;
	cout << "type the name of the city\n";
	aInput >> aBankAccount.mCity;
	cout << "type the zip code\n";
	aInput >> aBankAccount.mZip;
	
	return aInput;
}
bool  operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
	return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
		aBankAccount1.mBalance == aBankAccount2.mBalance &&
	       	aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
}*/
BankAccount::BankAccount(){
	mPerson = new Person;
	mBalance = 5.00;
	mAccountNumber = rand();
}

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person), mBalance(5.00),mAccountNumber(rand()){
}/**
void  BankAccount::setAccountOwner (const Person& aPerson){
	mPerson =  new Person;
}
Person  getAccountOwner () const{
	return mPerson;
}
double BankAccount:: withdrawal (double aAmount){
	double newBalance =  Balance - aAmount;
	setBalance(newBalance);
	getBalance();
	//return aBalance;
		
} 

double  BankAccount::deposit (double aAmount){
	double newBalance =  newBalance + aAmount; 
	aBankAccount.setBalance(newBalance);
	aBankAccount.getBalance ();
	
}*/
size_t BankAccount::getAccountNumber () const{
	//srand(static_cast<unsigned int>(time(NULL)));
	//mAccountNumber = rand();
	return  mAccountNumber;
}/**
void  BankAccount::setBalance (double aBalance) {
	mBalance = aBalance;
}
double BankAccount:: getBalance () const{
	return mBalance;
}  
bool BankAccount::sufficientFundsToWithdrawal (double aAmount) const {
	if((aAmount - aBalance) > 5){
		return true;
	}
	else {
		return false;
	}
}
*/

now it is giving these errors:

1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(39) : error C2039: 'getAccountNumber' : is not a member of 'BankAccount'
1> c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(9) : see declaration of 'BankAccount'
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(109) : error C2039: 'getAccountNumber' : is not a member of 'BankAccount'
1> c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(9) : see declaration of 'BankAccount'
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(109) : error C2270: 'getAccountNumber' : modifiers not allowed on nonmember functions
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(109) : error C2365: 'getAccountNumber' : redefinition; previous definition was 'formerly unknown identifier'
1>c:\users\sherry\documents\visual studio 2008\projects\testing\testing\bankaccount.cpp(112) : error C2065: 'mAccountNumber' : undeclared identifier

my mistake didn't remove // in front of declaration of GetAccountNumber();

Hmm ... reason is obvious, line 18 looks like

//size_t getAccountNumber()const;

so there really is no such function in the class. You have to uncomment that line to make it compile.

one more ques...u know I have one function:
Person getAccountOwner() const;

It is related to class Perosn.h file..now as i did in my one argument constructor:

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person), mBalance(5.00),mAccountNumber(rand()){

I wanted to take all the information which was entered in my Person. h file ( all the details regrding firstname, lastname. address, etc)

now is this the right way to have all the information from Person.h file

If I understand you right, you might construct a member function in the Person class, which queries the user for the necessary details (that is information pertaining to the person).

One note about the bank account numbers, just so that you know, simply by using rand() the numbers are not guaranteed to be unique. If your program must have unique numbers, you must write some code which guarantees that.

#include<cstdlib>
#include<string>
#include<time.h>
#include"Person.h"
#include<iostream>
using namespace std;

typedef Person* PersonPtr;
class BankAccount{
public:
	friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount); 
	friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
	//friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
	BankAccount();
  	BankAccount(const Person& aPerson);
/**	double withdrawal(double aAmount);
	double deposit(double aAmount);*/
	size_t getAccountNumber()const;
	/**void setBalance(double aBalance);
	double getBalance() const;
	void setAccountOwner(const Person& aPerson);
	Person getAccountOwner() const;
	bool sufficientFundsToWithdrawal(double aAmount) const;*/
private: 
	PersonPtr mPerson;
	//mAmount;
	double mBalance;	
	 size_t mAccountNumber;
};
//#endif

int main() {
	srand(static_cast<unsigned int>(time(NULL)));
BankAccount ba ;
	cout <<"running";
//ba.getAccountNumber();

	//mAccountNumber = rand();
	cout <<  ba.getAccountNumber() << endl;


cin >> ba; 
	//cout << ba;

	return 0;
}


ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
	cout << "A new account with account number";
	aOutput << aBankAccount.mAccountNumber << endl;
	cout << "has been created for";
	aOutput << aBankAccount.mPerson << endl;
	return aOutput;
}
istream&  operator >> (istream &aInput, BankAccount& aBankAccount){
	cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
	aInput >> aBankAccount.mBalance;
	aInput >> aBankAccount.mPerson;
/**cout << "type the first name\n;
	aInput >> aBankAccount.mFName;
	cout << "type the last name\n;
	aInput >> aBankAccount.mLName;
	cout << "Type the address\n";
	aInput >> aBankAccount.mAddress;
	cout << "type the name of the state\n";
	aInput >> aBankAccount.mState;
	cout << "type the name of the city\n";
	aInput >> aBankAccount.mCity;
	cout << "type the zip code\n";
	aInput >> aBankAccount.mZip;
	*/
	return aInput;
}/**
bool  operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
	return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
		aBankAccount1.mBalance == aBankAccount2.mBalance &&
	       	aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
}*/
BankAccount::BankAccount(){
	mPerson = new Person();
	mBalance = 5.00;
	mAccountNumber = rand();
}

BankAccount::BankAccount(const Person &aPerson):mPerson( new Person()), mBalance(5.00),mAccountNumber(rand()){
}/**
void  BankAccount::setAccountOwner (const Person& aPerson){
	mPerson =  new Person;
}
Person  getAccountOwner () const{
	return mPerson;
}
double BankAccount:: withdrawal (double aAmount){
	double newBalance =  Balance - aAmount;
	setBalance(newBalance);
	getBalance();
	//return aBalance;
		
} 

double  BankAccount::deposit (double aAmount){
	double newBalance =  newBalance + aAmount; 
	aBankAccount.setBalance(newBalance);
	aBankAccount.getBalance ();
	
}*/
size_t BankAccount::getAccountNumber () const{
	return  mAccountNumber;
}/**
void  BankAccount::setBalance (double aBalance) {
	mBalance = aBalance;
}
double BankAccount:: getBalance () const{
	return mBalance;
}  
bool BankAccount::sufficientFundsToWithdrawal (double aAmount) const {
	if((aAmount - aBalance) > 5){
		return true;
	}
	else {
		return false;
	}
}
*/

this is my code now, which is trying to get all the information for creating a bank account.. right now it is able to create anAccountNumber and then aask user to input whatever money they want to deposit in it....now my next step should be to get the accountholder's personal information, this all information is asked in Person.cpp file.. Now i'm trying to get that information in BankAccount.cpp file, by using the operator overloading function for >> used inPerson.cpp file.

But It is not working....is the way I have called function on line 59 , the right way or not to do this.

This is my Person.cpp file

#include "Person.h"

ostream& operator << (ostream& aOutput, const Person& aPerson){
	aOutput << "Person's First Name: " ;
	aOutput << aPerson.mFName << endl;
	aOutput << "Person's Last Name: ";
	aOutput << aPerson.mLName << endl;
	aOutput << "Person's address: ";
	aOutput << aPerson.mAddress <<endl;
	aOutput << "state: ";
	aOutput << aPerson.mState << endl;
	aOutput << "city: ";
	aOutput << aPerson.mCity << endl;
	aOutput << "zip: ";	
	aOutput << aPerson.mZip << endl;
	return aOutput;
}

istream& operator >> (istream& aInput, Person& aPerson){
	cout << "firstName\n";
	aInput >> aPerson.mFName;
cout << "lastName\n";
	aInput >> aPerson.mLName;
cout << "adddress\n";
	aInput >> aPerson.mAddress;
	cout << "state\n";
	aInput >> aPerson.mState;
cout << "city\n";
	aInput >> aPerson.mCity;
cout << "zip\n";
	aInput >> aPerson.mZip;
	return aInput;
}

bool operator == (const Person& aPerson1, const Person& aPerson2){
	return(aPerson1.mFName == aPerson2.mFName &&
	       aPerson1.mLName == aPerson2.mLName &&
	       aPerson1.mAddress == aPerson2.mAddress &&
	       aPerson1.mState == aPerson2.mState &&
	       aPerson1.mCity == aPerson2.mCity &&
	       aPerson1.mZip == aPerson2.mZip);
}	
Person::Person():mFName("UNKNOWN"),mLName("UNKNOWN"), 
mAddress("UNKNOWN"), mCity("UNKNOWN"), mState("UNKNOWN"), mZip("UNKNOWN"){
	/*empty*/
}
Person::Person(const string& aFName, const string& aLName):mFName(aFName), mLName(aLName), mAddress("UNKNOWN"), mCity("UNKNOWN"), mState("UNKNOWN"), mZip("UNKNOWN"){
	if(aFName == "")
		mFName = aFName;
	if(aLName == "")
		mLName == aLName;
}
string Person::getFirstName()const{
	return mFName;
}
void Person::setFirstName(const string& aFName){
	mFName = aFName;
}
string Person::getLastName()const{
	return mLName;
}
void Person::setLastName(const string& aLName){
	mLName = aLName;
}
string Person::getAddress()const{
	return mAddress;
}
void Person::setAddress(const string& aAddress){
	mAddress = aAddress;
}
string Person::getState()const{
	return mState;
}
void Person::setState(const string& aState){
	mState = aState;
}
string Person::getCity()const{
	return mCity;
}
void Person::setCity(const string& aCity){
	mCity = aCity;
}
string Person::getZip()const{
	return mZip;
}
void Person::setZip(const string& aZip){
	mZip = aZip;
}

What does this error means:
1> c:\users\sherry\documents\visual studio 2008\projects\testing\testing\person.h(19): or 'std::istream &operator >>(std::istream &,Person &)' [found using argument -dependent lookup]

This article has been dead for over six months. Start a new discussion instead.