#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; [COLOR="red"]size_t mAccountNumber;[/COLOR] }; //#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; } } */
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.
C++ Syntax (Toggle Plain Text)
#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; [COLOR="red"]size_t mAccountNumber;[/COLOR] }; //#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 BankAccount::getAccountNumber () const{
size_t acctNum = p.getAccountNumber ();
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; } } */
mAccountNumber = rand();
p.getAccountNumber ()
BankAccount ba = new BankAccount (); ba.getAccountNumber ();
ba.getAccountNumber();
BankAccount ba = new BankAccount ();
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 likebut not clear why you have allocated dynamic memory to bankAccount here inC++ Syntax (Toggle Plain Text)
ba.getAccountNumber();
C++ Syntax (Toggle Plain Text)
BankAccount ba = new BankAccount ();
do we really need to do this, It won't work without doing this?
BankAccount ba;
| DaniWeb Message | |
| Cancel Changes | |