Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. class Date
  10. {
  11. public:
  12. Date(int =1,int =1,int =1900);//setup the Date constructor
  13. void print()const;//A print function
  14. ~Date();
  15. Date CopyDate(Date param);//This is supposed to take in one date and copy it into another Date and return that.
  16. int RetMonth(){return month;}//Access Month
  17. int Retday(){return day;}//Access Day
  18. int Retyear(){return year;}//acess year
  19. void setmonth(int m);//set month
  20. void setday(int d);//set day
  21. void setyear(int y);//set year
  22.  
  23. private:
  24. int month;
  25. int day;
  26. int year;
  27. };
  28. Date CopyDate(Date param)
  29. {
  30. Date A;
  31. A.setday(param.Retday());
  32. A.setyear(param.Retyear());
  33. A.setmonth(param.RetMonth());
  34. return A;
  35. };
  36. void Date::setday(int d)
  37. {
  38. day=d;
  39. }
  40. void Date::setyear(int y)
  41. {
  42. year=y;
  43. }
  44. void Date::setmonth(int m)
  45. {
  46. month=m;
  47. }
  48.  
  49. Date::Date(int m,int d, int y)//Date Constructor
  50. {
  51. month=m;
  52. day=d;
  53. year=y;
  54. }
  55. void Date::print() const//Date Print out
  56. {
  57. cout << month << '/' << day << '/' << year;
  58. }
  59. Date::~Date()
  60. {
  61. //cout << "Date object destructor for date ";
  62. month=1;
  63. day=1;
  64. year=1900;
  65. //cout << endl;
  66. }
  67.  
  68. class Person
  69. {
  70. public:
  71. Person(string first, string last,const Date&, const Date&);//Constructor for person
  72. void print() const ;//Prit
  73. ~Person();
  74. private:
  75. string firstName;
  76. string lastName;
  77. const Date birth;
  78. const Date death;
  79. };
  80.  
  81. Person::Person(string first,string last, const Date &dateofbirth,const Date & dateOfDeath):birth(dateofbirth),death(dateOfDeath)
  82. {
  83. firstName=first;//set the first name in Person to the value passed in
  84. lastName=last;//set the last name in person to the value passed in
  85. }
  86. void Person::print() const
  87. {
  88. cout << lastName << ", " << firstName << " Birth: ";
  89. birth.print();//Print out birth date
  90. cout << " Death: ";
  91. death.print();//Print out death date
  92. cout << endl;
  93. }
  94.  
  95. Person::~Person()
  96. {
  97. //cout << "Person destructor: " << lastName << ", " << firstName << endl;
  98. lastName=" ";
  99. firstName=" ";
  100. }
  101.  
  102. struct Data
  103. {
  104.  
  105. string first;//First Name
  106. string last;//Last Name
  107. const Date birthed;//Birth Date
  108. const Date died;//Death Date
  109. //Data operator = (Data temp);
  110. Data &Data::operator =(Data param)//Overload operator Here
  111. {
  112.  
  113. const Data temp;
  114. cout << "temp.birthed.print" << endl;
  115. //this->birthed.CopyDate(param.birthed);
  116. // temp.birthed=param.birthed;
  117. this->birthed.CopyDate(param.birthed);
  118. cout << endl;
  119. first=param.first;//Copy the first name of the passed in name to the return name
  120. last=param.last;//Copy the last name of the passed in name to the return name
  121. return *this;//return the data structure.
  122. };
  123. Data(string fName, string lName,const Date & dOfBir,const Date& dofDie): birthed(dOfBir),died(dofDie){ first = fName; last = lName;};//Constructor
  124. Data()//constructor
  125. {
  126. first="None";
  127. last="Lol";
  128. }
  129. void print()//print out data information
  130. {
  131. cout << "print() has been called." << endl;
  132. cout << first << ", " << last << endl;
  133. cout << "B: ";
  134. birthed.print();//print birth date
  135. cout << endl;
  136. cout << "D: ";
  137. died.print();//print death date
  138. cout << endl;
  139.  
  140. }
  141.  
  142. };
  143.  
  144. void main()
  145.  
  146. {
  147. Date defBirth=Date(1,1,1900);//default Birth
  148. Date defDeath=Date(1,1,1900);//default Death
  149. string f = "first"; //test data
  150. string l = "Last";//test tdata
  151. Data List[2];//a list of the data structure
  152. Data Test;//a test variable
  153. Data X("Bob","Weir",Date(4,9,1990),defDeath);//Set a variable of Data X to some data
  154. Test=X;//overload operator in action to set Test to X
  155. // The Date are not being copied yet. The operator= for Data needs to be modified to do that.
  156. List[0].print();
  157. List[0]=X;
  158. List[0].print();
  159. List[1]=X;
  160. List[1].print();
  161. //X.print();//Show X
  162. //Test.print();//Show Test
  163. //cout << "List 1" << endl;
  164.  
  165.  
  166.  
  167. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement