| | |
Have problem using size_t type...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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
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
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
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.
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.
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; 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.
Last edited by code12; May 11th, 2008 at 6:17 pm.
This is my Person.cpp file
C++ Syntax (Toggle Plain Text)
#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; }
![]() |
Similar Threads
- problem with size_t filesize (C)
- simple string assignment problem (C)
- Problem (C++)
- help vector problem (C++)
- problem instantiating a subclass of abstract class (C)
- Problem with memory allocation =( (C)
- can't seem to make a yes/no question (C)
- Problem of sorting words of each string using pointers (C++)
- IMF message filter SDK sample problem (C)
Other Threads in the C++ Forum
- Previous Thread: Delete Rows in dataGridView
- Next Thread: help with text editing
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





