Have problem using size_t type...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: Have problem using size_t type...

 
0
  #21
May 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 51
Reputation: code12 is an unknown quantity at this point 
Solved Threads: 0
code12's Avatar
code12 code12 is offline Offline
Junior Poster in Training

Re: Have problem using size_t type...

 
0
  #22
May 11th, 2008
wow....it's working.....great thanks a lot
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 51
Reputation: code12 is an unknown quantity at this point 
Solved Threads: 0
code12's Avatar
code12 code12 is offline Offline
Junior Poster in Training

Re: Have problem using size_t type...

 
0
  #23
May 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: Have problem using size_t type...

 
0
  #24
May 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 51
Reputation: code12 is an unknown quantity at this point 
Solved Threads: 0
code12's Avatar
code12 code12 is offline Offline
Junior Poster in Training

Re: Have problem using size_t type...

 
0
  #25
May 11th, 2008
  1. #include<cstdlib>
  2. #include<string>
  3. #include<time.h>
  4. #include"Person.h"
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. typedef Person* PersonPtr;
  9. class BankAccount{
  10. public:
  11. friend ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount);
  12. friend istream& operator >> (istream& aInput, BankAccount& aBankAccount);
  13. //friend bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2);
  14. BankAccount();
  15. BankAccount(const Person& aPerson);
  16. /** double withdrawal(double aAmount);
  17. double deposit(double aAmount);*/
  18. size_t getAccountNumber()const;
  19. /**void setBalance(double aBalance);
  20. double getBalance() const;
  21. void setAccountOwner(const Person& aPerson);
  22. Person getAccountOwner() const;
  23. bool sufficientFundsToWithdrawal(double aAmount) const;*/
  24. private:
  25. PersonPtr mPerson;
  26. //mAmount;
  27. double mBalance;
  28. size_t mAccountNumber;
  29. };
  30. //#endif
  31.  
  32. int main() {
  33. srand(static_cast<unsigned int>(time(NULL)));
  34. BankAccount ba ;
  35. cout <<"running";
  36. //ba.getAccountNumber();
  37.  
  38. //mAccountNumber = rand();
  39. cout << ba.getAccountNumber() << endl;
  40.  
  41.  
  42. cin >> ba;
  43. //cout << ba;
  44.  
  45. return 0;
  46. }
  47.  
  48.  
  49. ostream& operator << (ostream& aOutput, const BankAccount& aBankAccount){
  50. cout << "A new account with account number";
  51. aOutput << aBankAccount.mAccountNumber << endl;
  52. cout << "has been created for";
  53. aOutput << aBankAccount.mPerson << endl;
  54. return aOutput;
  55. }
  56. istream& operator >> (istream &aInput, BankAccount& aBankAccount){
  57. cout << "Please type the intitial balance for account number: " << aBankAccount.mAccountNumber << endl;
  58. aInput >> aBankAccount.mBalance;
  59. aInput >> aBankAccount.mPerson;
  60. /**cout << "type the first name\n;
  61. aInput >> aBankAccount.mFName;
  62. cout << "type the last name\n;
  63. aInput >> aBankAccount.mLName;
  64. cout << "Type the address\n";
  65. aInput >> aBankAccount.mAddress;
  66. cout << "type the name of the state\n";
  67. aInput >> aBankAccount.mState;
  68. cout << "type the name of the city\n";
  69. aInput >> aBankAccount.mCity;
  70. cout << "type the zip code\n";
  71. aInput >> aBankAccount.mZip;
  72. */
  73. return aInput;
  74. }/**
  75. bool operator == (const BankAccount& aBankAccount1, const BankAccount& aBankAccount2){
  76. return(aBankAccount1.mPerson == aBankAccount2.mPerson &&
  77. aBankAccount1.mBalance == aBankAccount2.mBalance &&
  78. aBankAccount1.mAccountNumber == aBankAccount2.mAccountNumber);
  79. }*/
  80. BankAccount::BankAccount(){
  81. mPerson = new Person();
  82. mBalance = 5.00;
  83. mAccountNumber = rand();
  84. }
  85.  
  86. BankAccount::BankAccount(const Person &aPerson):mPerson( new Person()), mBalance(5.00),mAccountNumber(rand()){
  87. }/**
  88. void BankAccount::setAccountOwner (const Person& aPerson){
  89. mPerson = new Person;
  90. }
  91. Person getAccountOwner () const{
  92. return mPerson;
  93. }
  94. double BankAccount:: withdrawal (double aAmount){
  95. double newBalance = Balance - aAmount;
  96. setBalance(newBalance);
  97. getBalance();
  98. //return aBalance;
  99.  
  100. }
  101.  
  102. double BankAccount::deposit (double aAmount){
  103. double newBalance = newBalance + aAmount;
  104. aBankAccount.setBalance(newBalance);
  105. aBankAccount.getBalance ();
  106.  
  107. }*/
  108. size_t BankAccount::getAccountNumber () const{
  109. return mAccountNumber;
  110. }/**
  111. void BankAccount::setBalance (double aBalance) {
  112. mBalance = aBalance;
  113. }
  114. double BankAccount:: getBalance () const{
  115. return mBalance;
  116. }
  117. bool BankAccount::sufficientFundsToWithdrawal (double aAmount) const {
  118. if((aAmount - aBalance) > 5){
  119. return true;
  120. }
  121. else {
  122. return false;
  123. }
  124. }
  125. */

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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 51
Reputation: code12 is an unknown quantity at this point 
Solved Threads: 0
code12's Avatar
code12 code12 is offline Offline
Junior Poster in Training

Re: Have problem using size_t type...

 
0
  #26
May 11th, 2008
This is my Person.cpp file
  1. #include "Person.h"
  2.  
  3. ostream& operator << (ostream& aOutput, const Person& aPerson){
  4. aOutput << "Person's First Name: " ;
  5. aOutput << aPerson.mFName << endl;
  6. aOutput << "Person's Last Name: ";
  7. aOutput << aPerson.mLName << endl;
  8. aOutput << "Person's address: ";
  9. aOutput << aPerson.mAddress <<endl;
  10. aOutput << "state: ";
  11. aOutput << aPerson.mState << endl;
  12. aOutput << "city: ";
  13. aOutput << aPerson.mCity << endl;
  14. aOutput << "zip: ";
  15. aOutput << aPerson.mZip << endl;
  16. return aOutput;
  17. }
  18.  
  19. istream& operator >> (istream& aInput, Person& aPerson){
  20. cout << "firstName\n";
  21. aInput >> aPerson.mFName;
  22. cout << "lastName\n";
  23. aInput >> aPerson.mLName;
  24. cout << "adddress\n";
  25. aInput >> aPerson.mAddress;
  26. cout << "state\n";
  27. aInput >> aPerson.mState;
  28. cout << "city\n";
  29. aInput >> aPerson.mCity;
  30. cout << "zip\n";
  31. aInput >> aPerson.mZip;
  32. return aInput;
  33. }
  34.  
  35. bool operator == (const Person& aPerson1, const Person& aPerson2){
  36. return(aPerson1.mFName == aPerson2.mFName &&
  37. aPerson1.mLName == aPerson2.mLName &&
  38. aPerson1.mAddress == aPerson2.mAddress &&
  39. aPerson1.mState == aPerson2.mState &&
  40. aPerson1.mCity == aPerson2.mCity &&
  41. aPerson1.mZip == aPerson2.mZip);
  42. }
  43. Person::Person():mFName("UNKNOWN"),mLName("UNKNOWN"),
  44. mAddress("UNKNOWN"), mCity("UNKNOWN"), mState("UNKNOWN"), mZip("UNKNOWN"){
  45. /*empty*/
  46. }
  47. Person::Person(const string& aFName, const string& aLName):mFName(aFName), mLName(aLName), mAddress("UNKNOWN"), mCity("UNKNOWN"), mState("UNKNOWN"), mZip("UNKNOWN"){
  48. if(aFName == "")
  49. mFName = aFName;
  50. if(aLName == "")
  51. mLName == aLName;
  52. }
  53. string Person::getFirstName()const{
  54. return mFName;
  55. }
  56. void Person::setFirstName(const string& aFName){
  57. mFName = aFName;
  58. }
  59. string Person::getLastName()const{
  60. return mLName;
  61. }
  62. void Person::setLastName(const string& aLName){
  63. mLName = aLName;
  64. }
  65. string Person::getAddress()const{
  66. return mAddress;
  67. }
  68. void Person::setAddress(const string& aAddress){
  69. mAddress = aAddress;
  70. }
  71. string Person::getState()const{
  72. return mState;
  73. }
  74. void Person::setState(const string& aState){
  75. mState = aState;
  76. }
  77. string Person::getCity()const{
  78. return mCity;
  79. }
  80. void Person::setCity(const string& aCity){
  81. mCity = aCity;
  82. }
  83. string Person::getZip()const{
  84. return mZip;
  85. }
  86. void Person::setZip(const string& aZip){
  87. mZip = aZip;
  88. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 51
Reputation: code12 is an unknown quantity at this point 
Solved Threads: 0
code12's Avatar
code12 code12 is offline Offline
Junior Poster in Training

Re: Have problem using size_t type...

 
0
  #27
May 11th, 2008
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]
Last edited by code12; May 11th, 2008 at 6:41 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC