Набросал код,(множества (шаблоном)) программа должна выполнять
Динамическое присваивание, символ "=". При выполнении операции вида A = B, где A и B имеют тип "Множество", объект A должен стать идентичным объекту B. Возвращаемое операцией значение-ссылка на левый операнд.
Проверка, являются ли два множества одинаковыми, символ "==". Операция вида A == B, где A и B имеют тип "Множество", должна возвращать значение true, если множества A и B идентичны, и значение false в противном случае.
Помогите пожалуйста исправить ошибки
Код:
#include<iostream>
#include<cstdlib>
#include<set>
using namespace std;
template<typename T>
class Set
{
public:
Set(); //конструктор
Set(Set<T>& other); //конструктор коіювання
Set& operator=(Set<T>& other);
bool operator==(Set<T>& other);
T& operator[](size_t index);
const T& operator[](size_t index) const;
void show() const;
size_t size() const;
~Set();
private:
size_t _size;
T* arr;
};
template<typename T>
Set<T>::Set()
{
this->_size = 0;
this->arr = new T[this->_size];
}
template<typename T>
Set<T>::Set(Set<T>& other)
{
this->_size = other._size;
this->arr = new T[this->_size];
for (size_t i = 0; i < this->_size; i++)
{
this->arr[i] = other.arr[i];
}
}
template<typename T>
void Set<T>::show() const
{
for (size_t i = 0; i < this->_size; i++)
{
cout << this->arr[i] << " ";
}
cout << endl;
}
template<typename T>
Set<T>& Set<T>::operator=(Set<T>& other)
{
if (this->arr != nullptr)
{
delete[] this->arr;
}
this->_size = other._size;
this->arr = new T[this->_size];
for (size_t i = 0; i < this->_size; i++)
{
this->arr[i] = other.arr[i];
}
return *this;
}
template<typename T>
T& Set<T>::operator[](size_t index)
{
return this->arr[index];
}
template<typename T>
const T& Set<T>::operator[](size_t index) const
{
return this->arr[index];
}
template<typename T>
size_t Set<T>::size() const
{
return this->_size;
}
void Set::Enter()
{
std::cout << "Введите размер " << std::endl;
std::cin >> size;
array = new unsigned int[size];
for (unsigned int i = 0; i < size; i++)
{
std::cout << "Введите элемент " << i + 1 << ") ";
std::cin >> array[i];
}
}
template<typename T>
bool Set<T>::operator==(Set<T>& other)
{
if (this->_size != other._size)
{
return false;
}
for (size_t i = 0; i < this->_size; i++)
{
if (this->arr[i] != other.arr[i])
{
return false;
}
}
return true;
}
void Set::Show()
{
std::cout << "Множество " << std::endl;
for (unsigned int i = 0; i < size; i++)
std::cout << array[i] << " ";
std::cout << std::endl;
}
void Set::extract()
{
unsigned int number, n, i, j;
n = size;
std::cout << "Введите номер элемента от 0 до " << size - 1 << std::endl;
std::cin >> number;
if (number < 0 || number > size)
std::cout << "Ошибка " << std::endl;
else
{
for (i = 0; i < n; i++)
{
if (i == number)
{
for (j = i; j < n - 1; j++)
array[j] = array[j + 1];
n--;
}
}
size--;
}
template<typename T>
Set<T>::~Set() //деструктор
{
if (this->arr != nullptr)
{
delete[] this->arr;
this->arr = nullptr;
this->_size;
}
}
int main()
{
setlocale(0, "rus");
Set<int>a;
std::cout << "Ввод и вывод 1 множества " << std::endl;
a.Enter();
a.Show();
Set b = a;
std::cout << "инициализация множества 2 с помощью конструктора копии " << std::endl;
b.Show();
std::cout << "Ввод множества 2 " << std::endl;
b.Enter();
Set c;
std::cout << "Объединение множеств " << std::endl;
c.Union(a, b);
c.Show();
Set d;
d.intersection(a, b);
std::cout << "Пересечение множеств" << std::endl;
d.Show();
std::cout << "Добавка элемента " << std::endl;
d.add();
d.Show();
std::cout << "Проверка " << std::endl;
d.check();
d.Show();
std::cout << "Извлечение " << std::endl;
d.extract();
d.Show();
}