Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.56 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
  111.     {
  112.         Data temp (Data("none","none",Date(1,1,1900),Date(1,1,1900)));
  113.         //temp.birthed.CopyDate(param.birthed); //I want this to copy the date of the Date passed in.
  114.  
  115.         temp.first=param.first;//Copy the first name of the passed in name to the return name
  116.         temp.last=param.last;//Copy the last name of the passed in name to the return name
  117.         return temp;//return the data structure.
  118.     };
  119.     Data(string fName, string lName,const Date & dOfBir,const Date& dofDie): birthed(dOfBir),died(dofDie){ first = fName; last = lName;};//Constructor
  120.     Data()//constructor
  121.     {
  122.         first="None";
  123.         last="Lol";
  124.     }
  125.     void print()//print out data information
  126.     {
  127.         cout << "print() has been called." << endl;
  128.         cout << first << ", " << last << endl;
  129.         cout << "B: ";
  130.         birthed.print();//print birth date
  131.         cout << endl;
  132.         cout << "D: ";
  133.         died.print();//print death date
  134.         cout << endl;
  135.  
  136.     }
  137.  
  138. };
  139. void main()
  140.  
  141. {
  142.     Date defBirth=Date(1,1,1900);//default Birth
  143.     Date defDeath=Date(1,1,1900);//default Death
  144.     string f = "first"; //test data
  145.     string l = "Last";//test data
  146.     Data List[2];//a list of the data structure
  147.     Data Test;//a test variable
  148.     Data X("Michael","Weir",Date(4,9,1990),defDeath);//Set a variable of Data X to some data
  149.     Test=X;//overload operator in action to set Test to X
  150.     X.print();//Show X
  151.     Test.print();//Show Test
  152.  
  153.  
  154. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement