C++ program using classes

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

Join Date: Jun 2005
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

C++ program using classes

 
0
  #1
Jul 16th, 2005
Below is a program that determines if one address comes before another address using classes. One constructor takes an apartment parameter and the other doesn't. My errors are invalid conversion from int to const and among others. Any ideas?


  1. #include <iostream>
  2. #include <stdlib>
  3.  
  4. using namespace std;
  5.  
  6. class Address
  7. {
  8.  
  9. public:
  10. Address(int h, string st, int appt, string c, string s, string pc);
  11. Address(int h, string st, string c, string s, string pc);
  12. bool comes_before(Address a) const;
  13. void print() const;
  14.  
  15. private:
  16. int house_number;
  17. string street;
  18. int apartment_number;
  19. string city;
  20. string state;
  21. string postal_code;
  22. };
  23.  
  24. Address::Address(int h, string st, int appt, string c, string s, string pc)
  25. {
  26. // initialization of the variables
  27. house_number = h;
  28. street = st;
  29. apartment_number = appt;
  30. city = c;
  31. state = s;
  32. postal_code = pc;
  33. }
  34.  
  35. Address::Address(int h, string st, string c, string s, string pc)
  36. {
  37.  
  38.  
  39. // initialization of the variables
  40. house_number = h;
  41. street = st;
  42. city = c;
  43. state = s;
  44. postal_code = pc;
  45. }
  46. void Address::print()const
  47. {
  48.  
  49. cout << house_number << " " << street;
  50. if (apartment_number > 0 )
  51. cout << ", #" << apartment_number << endl;
  52. cout << city << ", " << state << ", " << postal_code << endl;
  53. }
  54.  
  55. bool Address::comes_before( Address other)const
  56. {
  57.  
  58. return postal_code < other.postal_code;
  59.  
  60. }
  61.  
  62.  
  63. int main()
  64. {
  65. //creating an object of 'Address' for a house
  66. Address aHouse(100, "N.University Dr.", "Edmond", "OK", 73034);
  67.  
  68. //creating another object of 'Address' for an apartment
  69. Address anApartment(201, "N.E. 89th St.", 305, "Oklahoma City", "OK", 73134);
  70.  
  71. cout << " Comparing Address\n\n";
  72. a.House.print();
  73.  
  74. cout << "\nwith address\n\n";
  75.  
  76. anApartment.print();
  77.  
  78. if(a.House.comes_before(anApartment))
  79.  
  80. cout << "\nThe HOUSE address comes before the APARTMENT address\n";
  81. else
  82. cout << "\nThe HOUSE address does o come before the APARTMENT address\n";
  83.  
  84.  
  85. // comparing again
  86.  
  87. if (anApartment.comes_before(aHouse))
  88.  
  89. cout << " \nThe APARTMENT address comes before the HOUSE address\n";
  90. else
  91. cout << " \nThe APARTMENT address does not come before the HOUSE address\n";
  92.  
  93. return 0;
<< moderator edit: added code tags: [code][/code] >>
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

Re: C++ program using classes

 
0
  #2
Jul 16th, 2005
figured it out was using a string in the class for zip code instead of int.
Reply With Quote Quick reply to this message  
Reply

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




Views: 5741 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC