Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- enum type {
- deserted,
- hasTrees,
- frozen
- };
- class mountain {
- private:
- string name;
- string country;
- float height;
- type typeOfMountain;
- public:
- mountain(string name, string country, float height, type typeOfMountain)
- {
- this->name = name;
- this->country = country;
- this->height = height;
- this->typeOfMountain = typeOfMountain;
- }
- string getName() { return name; }
- string getCountry() { return country; }
- float getHeight() { return height; }
- type getType() { return typeOfMountain; }
- void printMountainInfo() {
- cout << "Name: " << name << endl;
- cout << "Country: " << country << endl;
- cout << "Height: " << height << endl;
- cout << "Type of mountain: " << height << endl;
- }
- bool operator < (mountain& temp) {
- return this->height < temp.height;
- }
- };
- typedef bool(*Predicat)(mountain);
- class FilterService {
- public:
- FilterService()
- {
- }
- vector<mountain> FilterCollectionBy(vector<mountain> Coll ,Predicat logic) {
- vector<mountain> temp;
- for (auto item : Coll)
- {
- if (logic(item)) {
- temp.push_back(item);
- }
- }
- return temp;
- }
- };
- int main() {
- FilterService holder;
- vector<mountain> list{
- *new mountain("Ialbuzi" , "Georgia", 750, frozen),
- *new mountain("Everest" , "Georgia", 700, frozen),
- *new mountain("Gora" , "Georgia", 600, deserted),
- *new mountain("Caucasus" , "Russia", 500, frozen),
- *new mountain("Babayaga" , "Russia", 800, hasTrees)
- };
- vector<mountain>height = holder.FilterCollectionBy(list, [](mountain temp) {return temp.getHeight() > 600; });
- vector<mountain>Country = holder.FilterCollectionBy(list, [](mountain temp) {return temp.getCountry() == "Georgia"; });
- vector<mountain>isFrozen = holder.FilterCollectionBy(list, [](mountain temp) {return temp.getType() == frozen; });
- for (size_t i = 0; i < list.size(); i++)
- {
- for (size_t t = 0; t < list.size() - 1; t++)
- {
- if (list[t] < list[t + 1]) {
- mountain temp = list[t];
- list[t] = list[t + 1];
- list[t + 1] = temp;
- }
- }
- }
- cout << "Mountains which have height over 600 " << endl;
- for (auto item : height) {
- item.printMountainInfo();
- cout << "===========================" << endl;
- }
- cout << endl << endl;
- cout << "Mountains which are located in Georgia " << endl;
- for (auto item : Country) {
- item.printMountainInfo();
- cout << "===========================" << endl;
- }
- cout << endl << endl;
- cout << "Mountains which are frozen " << endl;
- for (auto item : isFrozen) {
- item.printMountainInfo();
- cout << "===========================" << endl;
- }
- cout << endl << endl;
- cout << "Highest mountain is : " << endl;
- list[0].printMountainInfo();
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement