Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <Windows.h>
- using namespace std;
- int* sort(int* A, int low, int high)
- {
- int i = low, l = high;
- int pivot = A[(low + high) / 2];
- while (i <= l)
- {
- while (A[i] < pivot)
- {
- i++;
- }
- while (A[l] > pivot)
- {
- l--;
- }
- if (i <= l)
- {
- swap(A[i], A[l]);
- i++;
- l--;
- }
- }
- if (low < l)
- {
- sort(A, low, l);
- }
- if (i < high)
- {
- sort(A, i, high);
- }
- return A;
- }
- class Assarr
- {
- private:
- int index;
- int sizeA = 3;
- int *A = new int[sizeA];
- public:
- int* allocator(int size)
- {
- if (size != 0)
- {
- this->A = new int[size];
- return this->A;
- }
- return nullptr;
- }
- Assarr(): A(allocator(sizeA))
- {
- this->A[0] = 11;
- this->A[1] = 10;
- this->A[2] = 5;
- //cout << "Усталений конструктор" << endl;
- }
- Assarr(int size): sizeA(size), A(allocator(sizeA)) {}
- Assarr(int size, int B[]): sizeA(size), A(allocator(sizeA))
- {
- for (int a = 0; a < size; a++)
- {
- A[a] = B[a];
- }
- }
- Assarr(int first, int second = 6, int third = 9): A(allocator(sizeA))
- {
- this->A[0] = first;
- this->A[1] = second;
- this->A[2] = third;
- //cout << "Параметри" << endl;
- }
- Assarr(const Assarr &numm): A(allocator(sizeA))
- {
- for (int i = 0; i < sizeA; i++)
- {
- this->A[i] = numm.A[i];
- }
- //cout << "Copyconst" << endl;
- }
- ~Assarr()
- {
- delete[] A;
- }
- int* getarr()
- {
- return A;
- }
- Assarr quicksort()
- {
- int LOW = 0, HIGH = sizeA - 1;
- sort(this->A, LOW, HIGH);
- return *this;
- }
- Assarr addelement(int elem, int sizeA)
- {
- int *B = allocator(sizeA);
- B = this->A;
- cout << endl;
- for (int a = 0; a < sizeA; a++)
- {
- cout << "A[" << a << "] = " << A[a] << endl;
- }
- cout << endl;
- /* for (int b = 0; b < sizeA; b++)
- {
- B[b] = A[b];
- } */
- delete[] A;
- //sizeA++;
- B[sizeA-1] = elem;
- cout << endl;
- for (int b = 0; b < sizeA; b++)
- {
- cout << "B[" << b << "] = " << B[b] << endl;
- }
- cout << endl;
- /*for (int b = 0; b < sizeA; b++)
- {
- this->A[b] = B[b];
- }*/
- this->A = B;
- for (int a = 0; a < sizeA; a++)
- {
- cout << "A[" << a << "] = " << A[a] << endl;
- }
- return *this;
- }
- int operator[] (int i) { return *(this->A + i); }
- Assarr operator= (Assarr&B)
- {
- if (*this != B) {
- for (int a = 0; a < 3; a++)
- {
- if (this->A[a] != B.A[a])
- {
- this->A[a] = B.A[a];
- }
- }
- }
- return *this;
- }
- bool operator== (Assarr G)
- {
- for (int g = 0; g < 3; g++)
- {
- if (this->A[g] != G.A[g])
- {
- return false;
- }
- }
- return true;
- }
- bool operator!= (Assarr T)
- {
- return !(*this == T);
- }
- Assarr operator= (int* B)
- {
- for (int a = 0; a < 3; a++)
- {
- if (this->A[a] != B[a])
- {
- this->A[a] = B[a];
- }
- }
- return *this;
- }
- friend istream& operator>> (istream&C, Assarr&arr)
- {
- for (int t = 0; t < 3; t++)
- {
- C >> arr.A[t];
- }
- return C;
- }
- friend ostream& operator<< (ostream&C, Assarr&arr)
- {
- for (int t = 0; t < 3; t++)
- {
- C << arr.A[t] << endl;
- }
- return C;
- }
- };
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int choice = 0, copychoice = 0, choice_operation = 0, element = 0, size = 3;
- cout << "Оберіть конструктор (1 -- усталений, 2 -- з параметрами, 3 -- копіювання): ";
- cin >> choice;
- cout << endl;
- switch (choice)
- {
- case 1:
- {
- Assarr number;
- number = number.getarr();
- cout << number << endl;
- break;
- }
- case 2:
- {
- Assarr number1(2, 5, 13);
- number1 = number1.getarr();
- cout << number1 << endl;
- break;
- }
- case 3:
- {
- cout << "Оберіть конструктор для копіювання з: (1 -- усталений, 2 -- з параметрами): ";
- cin >> copychoice;
- switch (copychoice)
- {
- case 1:
- {
- Assarr number;
- number = number.getarr();
- Assarr number2(number);
- number2 = number2.getarr();
- cout << number2 << endl;
- break;
- }
- case 2:
- {
- Assarr number1(2, 5, 13);
- number1 = number1.getarr();
- Assarr number2(number1);
- number2 = number2.getarr();
- cout << number2 << endl;
- break;
- }
- break;
- }
- }
- }
- cout << "Оберіть операцію (1 -- додати новий елемент, 2 -- видалити елемент, 3 -- надрукувати масив, 4 -- завершити роботу): " << endl;
- cin >> choice_operation;
- switch (choice_operation)
- {
- case 1:
- {
- Assarr number;
- number = number.getarr();
- cout << number << endl;
- cout << endl;
- cout << "Введіть новий елемент: " << endl;
- cin >> element;
- number.addelement(element, size);
- cout << number;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement