Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Osoba
  7. {
  8.   public:
  9.     Osoba()
  10.     {
  11.  
  12.     }
  13.  
  14.     Osoba(string Imie, string Nazwisko, string Pesel)
  15.     {
  16.       this->Imie() = Imie;
  17.       this->Nazwisko() = Nazwisko;
  18.       this->Pesel() = Pesel;
  19.     }
  20.  
  21.   private:
  22.     string _Imie;
  23.     string _Nazwisko;
  24.     string _Pesel;
  25.  
  26.   public:
  27.     string& Imie()
  28.     {
  29.       return _Imie;
  30.     }
  31.  
  32.     string& Nazwisko()
  33.     {
  34.       return _Nazwisko;
  35.     }
  36.  
  37.     string& Pesel()
  38.     {
  39.       return _Pesel;
  40.     }
  41.  
  42.     bool operator==(Osoba Osoba1)
  43.     {
  44.       if (Imie() == Osoba1.Imie() && Nazwisko() == Osoba1.Nazwisko() && Pesel() == Osoba1.Pesel()) return true;
  45.       else return false;
  46.     }
  47. };
  48.  
  49. class BazaDanych
  50. {
  51. private:
  52.   Osoba* _Osoby;
  53.   unsigned int _N;
  54.  
  55.   public:
  56.     BazaDanych()
  57.     {
  58.       _Osoby = 0;
  59.       _N = 0;
  60.     }
  61.  
  62.     BazaDanych(const BazaDanych& Baza1)
  63.     {
  64.       this->_N = Baza1._N;
  65.  
  66.       this->_Osoby = new Osoba[_N];
  67.  
  68.       for (unsigned int I = 0; I < _N; I++)
  69.       {
  70.         _Osoby[I] = Baza1._Osoby[I];
  71.       }
  72.     }
  73.  
  74.     ~BazaDanych()
  75.     {
  76.       delete[] _Osoby;
  77.     }
  78.  
  79.     BazaDanych& operator=(const BazaDanych& Baza1)
  80.     {
  81.       if(this != &Baza1)
  82.       {
  83.         if (_N != 0) delete[] _Osoby;
  84.  
  85.         _N = Baza1._N;
  86.  
  87.         _Osoby = new Osoba[_N];
  88.  
  89.         for (unsigned int I = 0; I < _N; I++)
  90.         {
  91.           _Osoby[I] = Baza1._Osoby[I];
  92.         }
  93.       }
  94.  
  95.       return *this;
  96.     }
  97.  
  98.     Osoba& operator[](unsigned int I)
  99.     {
  100.       return _Osoby[I];
  101.     }
  102. };
  103.  
  104. int main()
  105. {
  106.   Osoba o1;
  107.   cout << "---- 1 ----" << endl;
  108.   cout << o1 << endl;
  109.  
  110.   Osoba o2("Jan", "Kowalski", 11111111111);
  111.   cout << "---- 2 ----" << endl;
  112.   cout << o2 << endl;
  113.  
  114.   cout << "---- 3 ----" << endl;
  115.   cout << boolalpha << (o1 == o2) << endl;
  116.  
  117.   BazaDanych db1;
  118.   cout << "---- 4 ----" << endl;
  119.   cout << db1;
  120.  
  121.   db1 = db1 + o1;
  122.   cout << "---- 5 ----" << endl;
  123.   cout << db1;
  124.  
  125.   ifstream plik_we("zadanie6.txt");
  126.   if(!plik_we)
  127.   {
  128.     cout << "---- 6 ----" << endl;
  129.     return 1;
  130.   }
  131.  
  132.   while(plik_we >> o2)
  133.   {
  134.       db1 = db1 + o2;
  135.   }
  136.   cout << "---- 7 ----" << endl;
  137.   cout << db1;
  138.  
  139.   {
  140.       BazaDanych db2(db1);
  141.       cout << "---- 8 ----" << endl;
  142.       cout << db2;
  143.   }
  144.   cout << "---- 9 ----" << endl;
  145.   cout << db1;
  146.  
  147.   BazaDanych db3;
  148.   db3 = db1 + db1
  149.   cout << "---- 10 ----" << endl;
  150.   cout << db3;
  151.  
  152.   for(int i=0; i<db3.liczbaOsob(); ++i)
  153.   {
  154.       cout << db3[i] << endl;
  155.   }
  156.   cout << "---- 11 ----" << endl;
  157.  
  158.   db1 = db1 - o1;
  159.   cout << "---- 12 ----" << endl;
  160.   cout << db1;
  161.  
  162.   cout << "---- 13 ----" << endl;
  163.   cout << db3;
  164.   cout << "---- 14 ----" << endl;
  165.  
  166.   return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement