Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class animal {
  8. private:
  9. int age;
  10. string gender;
  11. string name;
  12. string breed;
  13. public:
  14. animal() {
  15. }
  16. animal(int _age, string _gender, string _name, string _breed) {
  17. age = _age;
  18. gender = _gender;
  19. name = _name;
  20. breed = _breed;
  21. }
  22.  
  23. #pragma region getters
  24. int getAge() {
  25. return age;
  26. }
  27. string getGender() {
  28. return gender;
  29. }
  30. void printInfo() {
  31. cout << "Name: " << name << endl;
  32. cout << "Gender: " << gender << endl;
  33. cout << "Age: " << age << endl;
  34. cout << "Breed: " << breed << endl;
  35. }
  36. #pragma endregion
  37. };
  38.  
  39. void menu(vector<animal>al);
  40. void getAnimalsByGender(vector<animal>al);
  41. void getAllAnimals(vector<animal>al);
  42. void getAnimalsByAge(vector<animal>al);
  43. void print(string text);
  44.  
  45. int main() {
  46. vector<animal>AL;
  47. animal jina(4, "Female", "Jina", "Husky");
  48. animal mailo(1, "Male", "Mailo", "Jack Russel Terrier");
  49. animal jack(1, "Male", "Jack", "Retriever");
  50. animal jeka(2, "Male", "Jeka", "Husky");
  51. animal jini(2, "Female", "Jini", "Jack Russel Terrier");
  52.  
  53. AL.push_back(jina);
  54. AL.push_back(mailo);
  55. AL.push_back(jack);
  56. AL.push_back(jeka);
  57. AL.push_back(jini);
  58.  
  59. menu(AL);
  60.  
  61. cin.get();
  62. cin.get();
  63. return 0;
  64. }
  65.  
  66. void menu(vector<animal> al)
  67. {
  68. system("cls");
  69. print("1) Animals List");
  70. print("2) Check animals by gender");
  71. print("3) Check animals by age");
  72. int choice;
  73. cin >> choice;
  74. switch (choice)
  75. {
  76. case 1:
  77. getAllAnimals(al);
  78. case 2:
  79. getAnimalsByGender(al);
  80. case 3:
  81. getAnimalsByAge(al);
  82. default:
  83. break;
  84. }
  85. }
  86.  
  87. void getAnimalsByGender(vector<animal>al) {
  88. system("cls");
  89. print("Do you wish to see \"Male\" or \"Female\" dogs? ");
  90. string gender;
  91. cin >> gender;
  92. if (gender == "Male" || gender == "male") {
  93. for (auto item : al) {
  94. if (item.getGender() == "Male") {
  95. item.printInfo();
  96. cout << "------------------------" << endl;
  97. }
  98. }
  99. }
  100. else if (gender == "Female" || gender == "female") {
  101. for (auto item : al) {
  102. if (item.getGender() == "Female") {
  103. item.printInfo();
  104. cout << "------------------------" << endl;
  105. }
  106. }
  107. }
  108. char answ;
  109. print("Do you wish to go back to menu? [y]/[n]");
  110. cin >> answ;
  111. if (answ == 'y')
  112. menu(al);
  113. }
  114.  
  115. void getAllAnimals(vector<animal>al) {
  116. system("cls");
  117. for (auto item : al) {
  118. item.printInfo();
  119. cout <<"------------------------"<< endl;
  120. }
  121. char answ;
  122. print("Do you wish to go back to menu? [y]/[n]");
  123. cin >> answ;
  124. if (answ == 'y')
  125. menu(al);
  126. }
  127.  
  128.  
  129. void print(string text)
  130. {
  131. cout << text << endl;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement