Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. enum type {
  8. deserted,
  9. hasTrees,
  10. frozen
  11. };
  12.  
  13. class mountain {
  14. private:
  15. string name;
  16. string country;
  17. float height;
  18. type typeOfMountain;
  19. public:
  20. mountain(string name, string country, float height, type typeOfMountain)
  21. {
  22. this->name = name;
  23. this->country = country;
  24. this->height = height;
  25. this->typeOfMountain = typeOfMountain;
  26. }
  27. string getName() { return name; }
  28. string getCountry() { return country; }
  29. float getHeight() { return height; }
  30. type getType() { return typeOfMountain; }
  31.  
  32. void printMountainInfo() {
  33. cout << "Name: " << name << endl;
  34. cout << "Country: " << country << endl;
  35. cout << "Height: " << height << endl;
  36. cout << "Type of mountain: " << height << endl;
  37. }
  38.  
  39. bool operator < (mountain& temp) {
  40. return this->height < temp.height;
  41. }
  42. };
  43. typedef bool(*Predicat)(mountain);
  44. class FilterService {
  45. public:
  46. FilterService()
  47. {
  48.  
  49. }
  50. vector<mountain> FilterCollectionBy(vector<mountain> Coll ,Predicat logic) {
  51. vector<mountain> temp;
  52. for (auto item : Coll)
  53. {
  54. if (logic(item)) {
  55. temp.push_back(item);
  56. }
  57. }
  58. return temp;
  59. }
  60. };
  61.  
  62. int main() {
  63. FilterService holder;
  64. vector<mountain> list{
  65. *new mountain("Ialbuzi" , "Georgia", 750, frozen),
  66. *new mountain("Everest" , "Georgia", 700, frozen),
  67. *new mountain("Gora" , "Georgia", 600, deserted),
  68. *new mountain("Caucasus" , "Russia", 500, frozen),
  69. *new mountain("Babayaga" , "Russia", 800, hasTrees)
  70. };
  71.  
  72. vector<mountain>height = holder.FilterCollectionBy(list, [](mountain temp) {return temp.getHeight() > 600; });
  73. vector<mountain>Country = holder.FilterCollectionBy(list, [](mountain temp) {return temp.getCountry() == "Georgia"; });
  74. vector<mountain>isFrozen = holder.FilterCollectionBy(list, [](mountain temp) {return temp.getType() == frozen; });
  75. for (size_t i = 0; i < list.size(); i++)
  76. {
  77. for (size_t t = 0; t < list.size() - 1; t++)
  78. {
  79. if (list[t] < list[t + 1]) {
  80. mountain temp = list[t];
  81. list[t] = list[t + 1];
  82. list[t + 1] = temp;
  83. }
  84. }
  85. }
  86. cout << "Mountains which have height over 600 " << endl;
  87. for (auto item : height) {
  88. item.printMountainInfo();
  89. cout << "===========================" << endl;
  90. }
  91. cout << endl << endl;
  92.  
  93. cout << "Mountains which are located in Georgia " << endl;
  94. for (auto item : Country) {
  95. item.printMountainInfo();
  96. cout << "===========================" << endl;
  97. }
  98. cout << endl << endl;
  99.  
  100. cout << "Mountains which are frozen " << endl;
  101. for (auto item : isFrozen) {
  102. item.printMountainInfo();
  103. cout << "===========================" << endl;
  104. }
  105. cout << endl << endl;
  106.  
  107. cout << "Highest mountain is : " << endl;
  108. list[0].printMountainInfo();
  109.  
  110. cin.get();
  111. cin.get();
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement