Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- class Person
- {
- private:
- string Name;
- string Surname;
- int year;
- Person* father;
- Person* mother;
- public:
- Person(string name, string surname, int year);
- void print();
- int getYear();
- int getAge();
- Person* getFather();
- void setFather(Person* father);
- Person* getMother();
- void setMother(Person* mother);
- void printTree(int i);
- };
- Person::Person(string name, string surname, int year)
- {
- this->Name = name;
- this->Surname = surname;
- this->year = year;
- }
- void Person::print()
- {
- cout << this->Name << " " << this->Surname << " [" << this->year << "] \n";
- }
- int Person::getYear()
- {
- return this->year;
- }
- int Person::getAge()
- {
- return 2020 - this->year;
- }
- Person* Person::getFather()
- {
- return this->father;
- }
- void Person::setFather(Person* father)
- {
- this->father = father;
- }
- Person* Person::getMother()
- {
- return this->mother;
- }
- void Person::setMother(Person* mother)
- {
- this->mother = mother;
- }
- void Person::printTree(int i)
- {
- for (int x = 0; x < i; x++)
- {
- cout << " ";
- }
- this->print();
- if (this->father != nullptr)
- this->father->printTree(i + 1);
- if (this->mother != nullptr)
- this->mother->printTree(i + 1);
- }
- int main()
- {
- std::cout << "Hello World!\n";
- Person osoba = Person("Jmeno", "Prijmeni", 1988);
- Person* tata = new Person("Jmeno2", "Prijmeni2", 1989);
- Person* mama = new Person("Jmeno3", "Prijmeni3", 1990);
- Person* tata2 = new Person("Jmeno4", "Prijmeni4", 1989);
- Person* mama2 = new Person("Jmeno5", "Prijmeni5", 1990);
- Person* tata3 = new Person("Jmeno6", "Prijmeni6", 1989);
- Person* mama3 = new Person("Jmeno7", "Prijmeni7", 1990);
- osoba.setFather(tata);
- osoba.setMother(mama);
- tata->setFather(tata2);
- tata->setMother(mama2);
- mama->setFather(tata3);
- mama->setMother(mama3);
- osoba.printTree(0);
- cout << "Osoba se narodila v roce " << osoba.getYear() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement