954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Have problem using size_t type...

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.

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

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 ...
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 
#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 ?

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

In my code the line 107 is

mAccountNumber = rand();


so it's complainig about this line

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

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?

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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.

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

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.

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

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 ??

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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(time(NULL))) and rand() functions

srand(static_cast(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(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."

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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(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

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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() <strong>const </strong>{ 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
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

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;
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

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();
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 
#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...

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 
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;
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 
#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

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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

code12
Junior Poster in Training
51 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You