Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- class Date
- {
- public:
- Date(int =1,int =1,int =1900);//setup the Date constructor
- void print()const;//A print function
- ~Date();
- Date CopyDate(Date param);//This is supposed to take in one date and copy it into another Date and return that.
- int RetMonth(){return month;}//Access Month
- int Retday(){return day;}//Access Day
- int Retyear(){return year;}//acess year
- void setmonth(int m);//set month
- void setday(int d);//set day
- void setyear(int y);//set year
- private:
- int month;
- int day;
- int year;
- };
- Date CopyDate(Date param)
- {
- Date A;
- A.setday(param.Retday());
- A.setyear(param.Retyear());
- A.setmonth(param.RetMonth());
- return A;
- };
- void Date::setday(int d)
- {
- day=d;
- }
- void Date::setyear(int y)
- {
- year=y;
- }
- void Date::setmonth(int m)
- {
- month=m;
- }
- Date::Date(int m,int d, int y)//Date Constructor
- {
- month=m;
- day=d;
- year=y;
- }
- void Date::print() const//Date Print out
- {
- cout << month << '/' << day << '/' << year;
- }
- Date::~Date()
- {
- //cout << "Date object destructor for date ";
- month=1;
- day=1;
- year=1900;
- //cout << endl;
- }
- class Person
- {
- public:
- Person(string first, string last,const Date&, const Date&);//Constructor for person
- void print() const ;//Prit
- ~Person();
- private:
- string firstName;
- string lastName;
- const Date birth;
- const Date death;
- };
- Person::Person(string first,string last, const Date &dateofbirth,const Date & dateOfDeath):birth(dateofbirth),death(dateOfDeath)
- {
- firstName=first;//set the first name in Person to the value passed in
- lastName=last;//set the last name in person to the value passed in
- }
- void Person::print() const
- {
- cout << lastName << ", " << firstName << " Birth: ";
- birth.print();//Print out birth date
- cout << " Death: ";
- death.print();//Print out death date
- cout << endl;
- }
- Person::~Person()
- {
- //cout << "Person destructor: " << lastName << ", " << firstName << endl;
- lastName=" ";
- firstName=" ";
- }
- struct Data
- {
- string first;//First Name
- string last;//Last Name
- const Date birthed;//Birth Date
- const Date died;//Death Date
- //Data operator = (Data temp);
- Data Data::operator =(Data param)//Overload operator
- {
- Data temp (Data("none","none",Date(1,1,1900),Date(1,1,1900)));
- //temp.birthed.CopyDate(param.birthed); //I want this to copy the date of the Date passed in.
- temp.first=param.first;//Copy the first name of the passed in name to the return name
- temp.last=param.last;//Copy the last name of the passed in name to the return name
- return temp;//return the data structure.
- };
- Data(string fName, string lName,const Date & dOfBir,const Date& dofDie): birthed(dOfBir),died(dofDie){ first = fName; last = lName;};//Constructor
- Data()//constructor
- {
- first="None";
- last="Lol";
- }
- void print()//print out data information
- {
- cout << "print() has been called." << endl;
- cout << first << ", " << last << endl;
- cout << "B: ";
- birthed.print();//print birth date
- cout << endl;
- cout << "D: ";
- died.print();//print death date
- cout << endl;
- }
- };
- void main()
- {
- Date defBirth=Date(1,1,1900);//default Birth
- Date defDeath=Date(1,1,1900);//default Death
- string f = "first"; //test data
- string l = "Last";//test data
- Data List[2];//a list of the data structure
- Data Test;//a test variable
- Data X("Michael","Weir",Date(4,9,1990),defDeath);//Set a variable of Data X to some data
- Test=X;//overload operator in action to set Test to X
- X.print();//Show X
- Test.print();//Show Test
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement