Нужно реализовать функции разности множеств и пересечения, не знаю как сделать без set.difference и set.intersection(именно с помощью массивов нужно).
#include <iostream>
#include <windows.h>
using namespace std;
class Set
{
int n;
int *a;
public:
Set(int s);
Add(const Set &obj);
Set();
void In();
void Out();
bool operator==(Set m)
{
if(n!=m.n)
return false;
for(int i = 0; i<n; i++)
if(a[i] != m.a[i])
return false;
return true;
}
/*
void f()
{
for (int i=0;i<n;i++)
if(a[i]==e)
cout<<"Элемент принадлежит множеству: "<<a[i]<<" ";
else {cout<<"Элемент не принадлежит множествам"<<endl;}
}
*/
};
void Set::In()
{
for (int i=0;i<n;i++)
{
cin>>a[i];
}
}
void Set::Out()
{
for (int i=0;i<n;i++)
cout<<a[i]<<" ";
}
Set::Set(int s)
{
n=s;
a=new int[n];
for(int i = 0; i<n; i++)
a[i] = 0;
}
Set::Set()
{
n = 1;
a = new int[n];
for(int i = 0; i<n; i++)
a[i] = 0;
}
Set::Add(const Set &obj)
{
int *tmp=new int[n+obj.n];
int i;
for (i=0;i<n;i++)
tmp[i]=a[i];
for(i=0;i<obj.n;i++)
tmp[n+i]=obj.a[i];
a=tmp;
n+=obj.n;
}
int main()
{
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
int n,i,e;
Set set3;
cout<<"Введите количество элементов в первом множестве: "<<endl;
cin>>n;
Set set1(n);
cout<<"Введите количество элементов во втором множестве: "<<endl;
cin>>n;
Set set2(n);
cout<<"Введите первое множество: "<<endl;
set1.In();
cout<<"Введите второе множество: "<<endl;
set2.In();
cin.ignore();
cout<<endl;
//cout<<"Введите элемент для поиска в одном из множеств: ";
//cin>>e;
cout<<"Ваше первое множество"<<endl;
cout<<"\n";
set1.Out();
cout<<"\n";
cout<<endl;
cout<<"Ваше второе множество"<<endl;
cout<<"\n";
set2.Out();
cout<<"\n";
cout<<endl;
cout<<"1 - Проверка равенства множеств"<<endl;
if (set1 == set2)
cout<<"Множества равны "<<endl;
else cout<<"Множества не равны "<<endl;
cout<<"\n";
cout<<"2 - Объединение множеств"<<endl;
set1.Add(set2);
set1.Out();
cout<<"\n";
cout<<endl;
cout<<"3 - Вычитание множеств"<<endl;
cout<<"4 - Пересечение множеств"<<endl;
cout<<"5 - Проверка отношения включения"<<endl;
cout<<"6 - Проверка принадлежности заданного символа к множеству"<<endl;
}
set_
...