From 1964f043860813dda3a9f6d3f210c02c62f12c75 Mon Sep 17 00:00:00 2001 From: Artem Barinov <145492721+Aigo-Oggi@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:43:31 +0300 Subject: [PATCH] Add files via upload --- photo_2024-10-16_19-43-09.jpg | Bin 0 -> 10664 bytes tbitfield.cpp | 189 ++++++++++++++++++++++++++++++++++ tset.cpp | 149 +++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 photo_2024-10-16_19-43-09.jpg create mode 100644 tbitfield.cpp create mode 100644 tset.cpp diff --git a/photo_2024-10-16_19-43-09.jpg b/photo_2024-10-16_19-43-09.jpg new file mode 100644 index 0000000000000000000000000000000000000000..20bce09ca9ff77a754fe2fe297ee9950a319fcf8 GIT binary patch literal 10664 zcmcI~by!?Yv*#Jy-66QUyAv!E+$FeMaDoR94uiY9yGsa8a19V#f(Iw)lK0--@7uf2 zKKsY+)|u1uJAJC^RQJ@>balBfzS_$C7n?dd|Hb037{ys#Rq7SLf5qgM z|AtNe4V#&}n7;DZz493TYiu8L0D%7r0HEXl)n}3n04-qvK(P9+KI%LGKo0?c=GlMs zT`K)EUJzcNtNEu_TL3_jO#*NZY6(AUZ`G;U%2_7B}9v%r10Ra&S9SQmMK*vMFKzn`R;SgYBVH4m`kq{7& zP%%)FQ!;QcGjoUviK?jBgZ^(7yz~K>2!INd05k{_fWibpV}f4#0q)oNf`b0*hyR0M z;hQvc8vAprflF@Y_tA=)66$D*Dvf^+#t1Zqt>8^ICaN=4a&S~4Y9PzGRIh>_Vy z6!*aa>=UMi+c_(mh?ce(~;f) zx57?VI!zyD7pf1A>;_QRp~o*@0Qtj?b4s5px4vq7LWMq({oa43s8ZEyj{TzYw+sY5ONBitVg0)^mdK^-Y{k=tA=-{;&cNN9Yy6A9a8(9JzaR095 z{|_d6b$AYpzy1z@V4y%yu+Xrteh&=;1q%m)2Qaa)ad7c4xX3A~sM+yp#d(#DT-`pu zdi(2F0RUkEFTf_DIa3-j97C4kI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-H~hy!J8*kHGPjsqPwdLvwOH$E3pshG5cv4{#JAXR3$V~F92( z_GK|ibbciNoux&&gAlFp_UzEKPkyXN#d?FMCWAR@Xilj0AA4VpIHCe~U5H06DkwzI$8ug|gy1Yft*Bi8-r z=&l|d4n9IQ-|)v21pc0=uQ)-Umv|F9sXjf9L!Y295a*@T$m$n#afoG2;Tmdy6YObd zW#1!J@u42 zDk19n`f1&YaX+tNUR|wwL`BQih{XK!u^Y}U5pomD8)>WZn0x_Z8eAeSGW|ckvYNJ4 z<{F;3XehWUBP{H_#BUw62;W=?9c z4VF1zB@fwxHCOW6p4-=0)G_T?m>v7HvlVT!S%XOCzB}dt|9;WBI(}-v)m%lgfsmix zqt2OAf~Y}LT~l@BdwKX~+Gbph$;c6zo3t>Gawiw-uT|qvxydKn<13C?Ed!%3Cfr$2 z)$+Y7=Qls^-r=n?JA&DenyB5PJ$R?8%B}x=Q8gfmKYfCrR*IUQc1?{rH_gpRj*^N4 z%yMrKM4YljB9hb7E52>1mnGvxo5laA>)7&mBYWdO#9)6p?P(Fvo7m8X7UJFv8iv=v z8yoMlQPUcs4>e1O#CvAN*@vboc5`bna0qANiXep+_(6eYCOui|{Jv#3o|eL7uB zegX68vemdx-*39is-~Mf>D*agN{+(K!Z$aJB|e}+16uDOjXEWq8^T@R&5qpTgYNND qg^vw+?3*WV)QLn}?66H=1CRM~{yR@&onjdY#uIATp-1eOAO8&t^Yg#} literal 0 HcmV?d00001 diff --git a/tbitfield.cpp b/tbitfield.cpp new file mode 100644 index 000000000..432ebe8a1 --- /dev/null +++ b/tbitfield.cpp @@ -0,0 +1,189 @@ +// ННГУ, ВМК, Курс "Методы программирования-2", С++, ООП +// +// tbitfield.cpp - Copyright (c) Гергель В.П. 07.05.2001 +// Переработано для Microsoft Visual Studio 2008 Сысоевым А.В. (19.04.2015) +// +// Битовое поле + +#include "tbitfield.h" + +#define BITS_IN_ONE_MEM (sizeof(TELEM) * 8) + +//len = 5 +//5+31=36 +//36/32 = 1,.... +// +//len = 32 +//(32+31)/32= 1 +// +//len = 64 +//(64+31)/32 = 2 + +TBitField::TBitField(int len) :BitLen(len) +{ + if (len <= 0) + throw "Invalid value entered"; + int size = (len + BITS_IN_ONE_MEM - 1) / (BITS_IN_ONE_MEM); // количество бит в поле + MemLen = size; // количество блоков + pMem = new TELEM[MemLen]; // массив с полем + for (int i = 0; i < MemLen; i++) + pMem[i] = 0; +} + +TBitField::TBitField(const TBitField& bf) // конструктор копирования +{ + BitLen = bf.BitLen; + MemLen = bf.MemLen; + pMem = new TELEM[MemLen]; + for (int i = 0; i < MemLen; i++) + pMem[i] = bf.pMem[i]; +} + +TBitField::~TBitField() +{ + delete pMem; +} + +int TBitField::GetMemIndex(const int n) const // индекс Мем для бита n +{ + //int Nfield = n / 32; // в каком из полей (блоков поля) находится элемент + if ((n < 0)||(n>=BitLen)) + throw "Invalid index for bit index"; + return n / (BITS_IN_ONE_MEM); // какой блок +} + +TELEM TBitField::GetMemMask(const int n) const // битовая маска для бита n +{ + if ((n < 0) || (n >= BitLen)) + throw "Invalid index for mask"; + return (TELEM)1 << (n % (BITS_IN_ONE_MEM)); +} + +// доступ к битам битового поля + +int TBitField::GetLength(void) const // получить длину (к-во битов) +{ + return BitLen; +} + +void TBitField::SetBit(const int n) // установить бит +{ + if ((n < 0) || (n >= BitLen)) + throw "Invalid index was entered"; + pMem[GetMemIndex(n)] = pMem[GetMemIndex(n)] | GetMemMask(n); +} + +void TBitField::ClrBit(const int n) // очистить бит +{ + if ((n < 0) || (n >= BitLen)) + throw "Invalid index was entered"; + pMem[GetMemIndex(n)] = pMem[GetMemIndex(n)] & ~(GetMemMask(n)); +} + +int TBitField::GetBit(const int n) const // получить значение бита +{ + if ((n < 0) || (n >= BitLen)) + throw "Invalid index was entered"; + return ((pMem[GetMemIndex(n)] & GetMemMask(n)) != 0);//(1 << (n % 32)); +} + +// битовые операции + +TBitField& TBitField::operator=(const TBitField & bf) // присваивание +{ + if (this == &bf) return *this; + BitLen = bf.BitLen; + MemLen = bf.MemLen; + delete pMem; + pMem = new TELEM[MemLen]; + for (int i = 0; i < MemLen; i++) + pMem[i] = bf.pMem[i]; + return *this; +} + +int TBitField::operator==(const TBitField & bf) const // сравнение +{ + if (bf.BitLen != BitLen) + return 0; + for (int i = 0; i < bf.MemLen; i++) + if (pMem[i] != bf.pMem[i]) + return 0; + return 1; +} + +int TBitField::operator!=(const TBitField & bf) const // сравнение +{ + if (bf.BitLen != BitLen) + return 1; + for (int i = 0; i < bf.MemLen; i++) + if (pMem[i] != bf.pMem[i]) + return 1; + return 0; +} + +TBitField TBitField::operator|(const TBitField & bf) // операция "или" +{ + int maxSize = (BitLen > bf.BitLen) ? BitLen : bf.BitLen; + TBitField NewF(maxSize); + for (int i = 0; i < NewF.MemLen; i++) + { + TELEM a = (i < MemLen) ? pMem[i] : 0; + TELEM b = (i < bf.MemLen) ? bf.pMem[i] : 0; + NewF.pMem[i] = a | b; + } + return NewF; +} + +TBitField TBitField::operator&(const TBitField & bf) // операция "и" +{ + int len = BitLen; + if (bf.BitLen > len) len = bf.BitLen; + TBitField res(len); + for (int i = 0; i < MemLen; i++) + res.pMem[i] = pMem[i]; + for (int j = 0; j < MemLen; j++) + res.pMem[j] &= bf.pMem[j]; + /*int maxSize = (BitLen > bf.BitLen) ? BitLen : bf.BitLen; + TBitField NewF(maxSize); + for (int i = 0; i < NewF.MemLen; i++) + { + TELEM a = (i < MemLen) ? pMem[i] : (TELEM)0; + TELEM b = (i < bf.MemLen) ? bf.pMem[i] : (TELEM)0; + NewF.pMem[i] = a & b; + }*/ + return res; +} + + +//32-bit +// len = 40 +// c 40 to 63 +TBitField TBitField::operator~(void) // отрицание +{ + TBitField res(BitLen); + for (int i = 1; i < BitLen+1; i++) + { + if (GetBit(BitLen - i))res.ClrBit(BitLen - i); + else res.SetBit(BitLen - i); + } + return res; +} + +// ввод/вывод + +istream& operator>>(istream & istr, TBitField & bf) // ввод +{ + for (int i = 0; i < bf.MemLen; i++) { + istr >> bf.pMem[i]; + } + return istr; +} + +ostream& operator<<(ostream & ostr, const TBitField & bf) // вывод +{ + for (int i = 0; i < bf.MemLen; i++) + { + ostr << bf.pMem[i] << "\t"; + } + return ostr; +} diff --git a/tset.cpp b/tset.cpp new file mode 100644 index 000000000..237f64ba5 --- /dev/null +++ b/tset.cpp @@ -0,0 +1,149 @@ +// ННГУ, ВМК, Курс "Методы программирования-2", С++, ООП +// +// tset.cpp - Copyright (c) Гергель В.П. 04.10.2001 +// Переработано для Microsoft Visual Studio 2008 Сысоевым А.В. (19.04.2015) +// +// Множество - реализация через битовые поля + +#include "tset.h" + +TSet::TSet(int mp) : BitField(mp) +{ + if (mp < 0) + throw "Invalid power"; + MaxPower = mp; +} + +// конструктор копирования +TSet::TSet(const TSet& s) : BitField(s.BitField) +{ + MaxPower = s.MaxPower; +} + +// конструктор преобразования типа +TSet::TSet(const TBitField& bf) : BitField(bf) +{ + MaxPower = bf.GetLength(); +} + +TSet::operator TBitField() +{ + return BitField; +} + +int TSet::GetMaxPower(void) const // получить макс. к-во эл-тов +{ + return MaxPower; +} + +int TSet::IsMember(const int Elem) const // элемент множества? +{ + if ((Elem < 0) || (Elem > BitField.GetLength())) + throw "Invalid index of Elem"; + bool flag = BitField.GetBit(Elem); + return flag; +} + +void TSet::InsElem(const int Elem) // включение элемента множества +{ + if ((Elem < 0) || (Elem > BitField.GetLength())) + throw "Invalid index of Elem"; + BitField.SetBit(Elem); +} + +void TSet::DelElem(const int Elem) // исключение элемента множества +{ + if ((Elem < 0) || (Elem > BitField.GetLength())) + throw "Invalid index of Elem"; + BitField.ClrBit(Elem); +} + +// теоретико-множественные операции + +TSet& TSet::operator=(const TSet& s) // присваивание +{ + if (this == &s) { + return *this; + } + MaxPower = s.MaxPower; + BitField = s.BitField; +} + +int TSet::operator==(const TSet& s) const // сравнение +{ + if (this == &s) + return 1; + if (MaxPower != s.MaxPower) + return 0; + if (BitField != s.BitField) + return 0; + return 1; +} + +int TSet::operator!=(const TSet& s) const // сравнение +{ + if (this == &s) + return 0; + if (MaxPower != s.MaxPower) + return 1; + if (BitField != s.BitField) + return 1; + return 0; +} + +TSet TSet::operator+(const TSet& s) // объединение +{ + TBitField res(MaxPower); + res = BitField | s.BitField; + return res; +} + +TSet TSet::operator+(const int Elem) // объединение с элементом +{ + TSet res(*this); + res.InsElem(Elem); + return res; +} + +TSet TSet::operator-(const int Elem) // разность с элементом +{ + TSet res(*this); + res.DelElem(Elem); + return res; +} + +TSet TSet::operator*(const TSet& s) // пересечение +{ + int maxP = MaxPower; + if (s.MaxPower > maxP)maxP = s.MaxPower; + TSet res(maxP); + res.BitField = BitField & s.BitField; + return res; +} + +TSet TSet::operator~(void) // дополнение +{ + TSet NewSet(MaxPower); + NewSet.BitField = ~(BitField); + return NewSet; +} + +// перегрузка ввода/вывода + +istream& operator>>(istream& istr, TSet& s) // ввод +{ + for(int i = 0; i < s.MaxPower; i++) + { + istr >> s.BitField; + } + return istr; +} + +ostream& operator<<(ostream& ostr, const TSet& s) // вывод +{ + for(int i = 0; i < s.MaxPower; i++) + { + ostr << s.BitField << "\t"; + } + return ostr; +}