Facebook
From Soft Lizard, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 207
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class A;
  8.  
  9. class person{
  10. private:
  11.     string nazwa;
  12.     int wiek;
  13.     vector<person*> vec;
  14. public:
  15.     person() {}
  16.     person(string nazwa, int wiek){
  17.         this->nazwa=nazwa;
  18.         this->wiek=wiek;
  19.     }
  20.  
  21.      int getWiek() const
  22.      {
  23.          return wiek;
  24.      }
  25.      string getNazwa() const{
  26.          return nazwa;
  27.      }
  28.  
  29.      bool operator<(const person &p){
  30.          if(this->wiek < p.getWiek())
  31.              return true;
  32.          else if(this->wiek > p.getWiek())
  33.              return false;
  34.          else
  35.              return this->nazwa < p.getNazwa();
  36.      }
  37.  
  38.      person &operator <<=(person *p)
  39.      {
  40.       for(const person *a : vec)
  41.       {
  42.           if(a->getNazwa()==p->getNazwa() && a->getWiek()==p->getWiek())
  43.               return *this;
  44.       }
  45.       vec.push_back(p);
  46.       return *this;
  47.      }
  48.  
  49.      person operator[](int a)
  50.      {
  51.          return *vec[a];
  52.      }
  53.  
  54.      friend class A;
  55. };
  56.  
  57. class A {
  58. private:
  59.     person *o;
  60. public:
  61.     A(person *p) {
  62.         o = p;
  63.     }
  64.  
  65.     bool operator()(person *p) {
  66.         return p == o
  67.             || find(o->vec.begin(), o->vec.end(), p) != o->vec.end();
  68.     }
  69. };
  70.  
  71. int main()
  72. {
  73.     person p("Janusz", 50);
  74.     person p1("Sebek", 17);
  75.     person p2("Dzesika", 17);
  76.     cout<<(p1<p2)<<endl;
  77.  
  78.     p<<=&p1;
  79.     p<<=&p2;
  80.  
  81.     person p3=p[0];
  82.     cout<<p3.getNazwa()<<endl;
  83.  
  84.     A januszoweA(p);
  85.     bool b = januszoweA(p1);
  86.  
  87.     return 0;
  88. }
  89.