Guest User

Untitled

a guest
Dec 8th, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNING
  2. #include "Person.h"
  3. #include <iostream>
  4. #include <exception>
  5. #include <vector>
  6. #include <cstring>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13. setlocale(LC_ALL, "RUS");
  14.  
  15. const Person *NO_DAD, *Adam, *Eve, *Ivan, *Maria ;
  16. try
  17. {
  18.  
  19. Adam = new Person("Adam", Person::Gender::man);
  20. Eve = new Person("Eve", Person::Gender::woman);
  21. NO_DAD = new Person("NO_DAD", Person::Gender::man);
  22. cout << *Adam << endl;
  23. cout << *Eve << endl;
  24. Maria = Eve->GiveBirth("Maria", Person::Gender::woman);
  25. cout << *Maria << endl;
  26. }
  27. catch (runtime_error& error)
  28. {
  29. cout << error.what() << endl;
  30. return 1;
  31. }
  32.  
  33. try
  34. {
  35. Ivan = Eve->GiveBirth("Ivan", Person::Gender::man, Adam);
  36. cout << *Ivan << endl;
  37.  
  38. }
  39. catch (runtime_error& error)
  40. {
  41. cout << error.what() << endl;
  42. return 1;
  43. }
  44.  
  45.  
  46. vector <const Person*> People;
  47. People.push_back(NO_DAD);
  48. People.push_back(Adam);
  49. People.push_back(Eve);
  50. People.push_back(Maria);
  51. People.push_back(Ivan);
  52.  
  53. for (int i = 0; ; )
  54. {
  55. if (i == People.size())
  56. i = 0;
  57. cout << "Do you want to create person?(1 - yes, 0 - no)" << endl;
  58. int choice;
  59. cin >> choice;
  60. if (choice == 1)
  61. {
  62. char name[50];
  63. char o[90];
  64. if (i % 2 == 0)
  65. cout << "It is a girl!" << endl;
  66. else
  67. cout << "It is a boy!" << endl;
  68. cout << "Enter Name: " << endl;
  69. cin.getline(o, 90);
  70. cin.getline(name, 50);
  71. cout << "Choose mother:" << endl;
  72. for (int i = 0; i < People.size(); i++)
  73. {
  74. if (People[i]->GetGender() == Person::Gender::woman)
  75. cout << People[i]->GetName() << " -- " << i << endl;
  76. }
  77. int mother;
  78. cin >> mother;
  79.  
  80. cout << "Choose father:" << endl;
  81. for (int i = 0; i < People.size(); i++)
  82. {
  83. if (People[i]->GetGender() == Person::Gender::man)
  84. cout << People[i]->GetName() << " -- " << i << endl;
  85. }
  86.  
  87.  
  88. int father;
  89.  
  90. cin >> father;
  91.  
  92. Person::Gender gender;
  93. const Person *s;
  94.  
  95. if (i % 2 == 0)
  96. gender = Person::Gender::woman;
  97. else
  98. gender = Person::Gender::man;
  99. s = People[mother]->GiveBirth(name, gender, People[father]);
  100. People.push_back(s);
  101. i++;
  102.  
  103. }
  104.  
  105. if (choice == 0)
  106. {
  107. for (int i = 4; i < People.size(); i++)
  108. {
  109. cout << *People[i] << endl;
  110. }
  111. system("pause");
  112. return 0;
  113. }
  114.  
  115. }
  116. for (int i = 0; i < People.size(); i++)
  117. {
  118. delete[] People[i];
  119. }
  120. system("pause");
  121. return 0;
  122. }
RAW Paste Data