bepisXDDD

Untitled

Oct 17th, 2020
1,007
23 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. char rus[] = "абвгдежзийклмнопрстуфхцчшщъыьэюя\0";
  9. const bool printLogs = true;
  10.  
  11.  
  12. class Set
  13. {
  14. private:
  15.     static int unSz, cnt;
  16.     int pwr;
  17.     char tag, *ar;
  18. public:
  19.     Set operator &(const Set&) const;
  20.     Set& operator &=(const Set& other);
  21.     Set operator ~() const;
  22.     void Print();
  23.     int power()
  24.     {
  25.         return pwr;
  26.     }
  27.     Set(char);
  28.     Set();
  29.     Set(const Set&);
  30.     Set(Set&&);
  31.     Set& operator =(const Set&);
  32.     Set& operator=(Set&& other);
  33.    
  34.     ~Set()
  35.     {
  36.         if (printLogs)
  37.             cout << tag << " - tag of deleted object\n";
  38.         delete[] ar;
  39.     }
  40. };
  41.  
  42. Set& Set::operator &=(const Set& other)
  43. {
  44.     Set rslt(*this);
  45.     pwr = 0;
  46.     for (int i = 0; i < rslt.pwr; ++i)
  47.         for (int j = 0; j < other.pwr; j++)
  48.             if (rslt.ar[i] == other.ar[j])
  49.                 ar[pwr++] = rslt.ar[i];
  50.     ar[pwr] = 0;
  51.     //if (printLogs)
  52.     //  cout << tag << " - tag of object which called [operator&=(const Set& other)]\n";
  53.     return *this;
  54. }
  55.  
  56. Set Set::operator&(const Set& other) const
  57. {
  58.     Set res(*this);
  59.     //if (printLogs)
  60.     //  cout << tag << " - tag of object which called [operator&(const Set& other) const]\n";
  61.     return (res &= other);
  62. }
  63.  
  64. Set Set::operator~() const
  65. {
  66.     Set res;
  67.     char* cur = ar;
  68.     char* curRus = rus;
  69.     while (*cur != '\0')
  70.     {
  71.         while (*curRus != *cur && *curRus != '\0')
  72.             res.ar[res.pwr++] = *curRus++;
  73.         cur++;
  74.         curRus++;
  75.     }
  76.     while (*curRus != '\0')
  77.         res.ar[res.pwr++] = *curRus++;
  78.     res.ar[res.pwr] = 0;
  79.     //if (printLogs)
  80.     //  cout << tag << " - tag of object which called [operator~()]\n";
  81.     return res;
  82. }
  83.  
  84. void Set::Print()
  85. {
  86.     cout << tag << " = [" << ar << "]"<<'\n';
  87. }
  88.  
  89. //default constructor
  90. Set::Set()
  91. {
  92.     pwr = 0;
  93.     tag = 'A' + cnt++;
  94.     ar = new char[unSz + 1];
  95.     ar[0] = 0;
  96.     if (printLogs)
  97.         cout << tag << " - tag of object which called [default constructor]\n";
  98. }
  99.  
  100. //random constructor (to call pass any char as a param)
  101. Set::Set(char)
  102. {
  103.     pwr = 0;
  104.     tag = 'A' + cnt++;
  105.     ar = new char[unSz + 1];
  106.     for (int i = 0; i < unSz; i++)
  107.         if (rand() % 2)
  108.             ar[pwr++] = rus[i];
  109.     ar[pwr] = 0;
  110.     if (printLogs)
  111.         cout << tag << " - tag of object which called [random constructor]\n";
  112. }
  113.  
  114. Set::Set(const Set& other)
  115. {
  116.     tag = 'A' + cnt++;
  117.     pwr = other.pwr;
  118.     ar = new char[unSz + 1];
  119.     char *dst = ar, *src = other.ar;
  120.     while (*dst++ = *src++);
  121.     if (printLogs)
  122.         cout << tag << " - tag of object which called [constructor (const Set& other)]\n";
  123. }
  124.  
  125. Set& Set::operator=(const Set& other)
  126. {
  127.     if (this != &other)
  128.     {
  129.         pwr = other.pwr;
  130.         char *dst = ar, *src = other.ar;
  131.         while (*dst++ = *src++);
  132.     }
  133.     //if (printLogs)
  134.     //  cout << tag << " - tag of object which called [operator=(Set& other)]\n";
  135.     return *this;
  136. }
  137.  
  138. Set::Set(Set &&other)
  139. {
  140.     tag = 'A' + cnt++;
  141.     pwr = other.pwr;
  142.     ar = other.ar;
  143.     other.ar = nullptr;
  144.     if (printLogs)
  145.         cout << tag << " - tag of object which called [costructor (Set&& other)]\n";
  146. }
  147.  
  148. Set& Set::operator=(Set&& other)
  149. {
  150.     if (this != &other)
  151.     {
  152.         pwr = other.pwr;
  153.         //delete[] ar;
  154.         ar = other.ar;
  155.         ar[pwr] = 0;
  156.         tag = 'A' + cnt++;
  157.         other.ar = nullptr;
  158.     }
  159.     //if (printLogs)
  160.     //  cout << tag << " - tag of object which called [operator=(Set&& other)]\n";
  161.     return *this;
  162. }
RAW Paste Data