Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. class Person
  6. {
  7. private:
  8. string Name;
  9. string Surname;
  10. int year;
  11.  
  12. Person* father;
  13. Person* mother;
  14.  
  15. public:
  16. Person(string name, string surname, int year);
  17. void print();
  18. int getYear();
  19. int getAge();
  20. Person* getFather();
  21. void setFather(Person* father);
  22. Person* getMother();
  23. void setMother(Person* mother);
  24. void printTree(int i);
  25. };
  26.  
  27. Person::Person(string name, string surname, int year)
  28. {
  29. this->Name = name;
  30. this->Surname = surname;
  31. this->year = year;
  32. }
  33.  
  34. void Person::print()
  35. {
  36. cout << this->Name << " " << this->Surname << " [" << this->year << "] \n";
  37. }
  38.  
  39. int Person::getYear()
  40. {
  41. return this->year;
  42. }
  43.  
  44. int Person::getAge()
  45. {
  46. return 2020 - this->year;
  47. }
  48.  
  49. Person* Person::getFather()
  50. {
  51. return this->father;
  52. }
  53.  
  54. void Person::setFather(Person* father)
  55. {
  56. this->father = father;
  57. }
  58.  
  59. Person* Person::getMother()
  60. {
  61. return this->mother;
  62. }
  63.  
  64. void Person::setMother(Person* mother)
  65. {
  66. this->mother = mother;
  67. }
  68.  
  69. void Person::printTree(int i)
  70. {
  71. for (int x = 0; x < i; x++)
  72. {
  73. cout << " ";
  74. }
  75. this->print();
  76. if (this->father != nullptr)
  77. this->father->printTree(i + 1);
  78. if (this->mother != nullptr)
  79. this->mother->printTree(i + 1);
  80. }
  81.  
  82.  
  83.  
  84. int main()
  85. {
  86. std::cout << "Hello World!\n";
  87. Person osoba = Person("Jmeno", "Prijmeni", 1988);
  88. Person* tata = new Person("Jmeno2", "Prijmeni2", 1989);
  89. Person* mama = new Person("Jmeno3", "Prijmeni3", 1990);
  90. Person* tata2 = new Person("Jmeno4", "Prijmeni4", 1989);
  91. Person* mama2 = new Person("Jmeno5", "Prijmeni5", 1990);
  92. Person* tata3 = new Person("Jmeno6", "Prijmeni6", 1989);
  93. Person* mama3 = new Person("Jmeno7", "Prijmeni7", 1990);
  94.  
  95. osoba.setFather(tata);
  96. osoba.setMother(mama);
  97. tata->setFather(tata2);
  98. tata->setMother(mama2);
  99. mama->setFather(tata3);
  100. mama->setMother(mama3);
  101.  
  102. osoba.printTree(0);
  103. cout << "Osoba se narodila v roce " << osoba.getYear() << endl;
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement