My name is Matt and this is my second year learning c++ programming. I am almost finished with this program I am working on but I am having one problem with a segment of my code. I can not get rid of the duplicates for the functions for union and intersection. I was able to get rid of the duplicates for the arrays a and b but I can not get the duplicates out of the Union function even though I think I set it up right. I think I know my error but I am not sure how to fix it. My Union function is not reading in the correct size for setF(array set a without duplicates) and setG(array set b without the duplicates). Can anyone help me fix my code? I have been working on it for days and I still can not find a way to remove the duplicates correctly, If you can suggest another way of removing the duplicates that would also be very helpful. Thanks.
Each line has 20 integers. First 10 integers are array a and second 10 integers are array b. I then have to store them in an array (program requirements).
Here is my code:
#include <iostream>
#include <fstream>
using namespace std;
void compute_union (int a[10], int b[10], int u[20]);
void compute_intersection(int a[10], int b[10], int x[10]);
void compute_differences(int a[10], int b[10], int d[10]);
void filterSets(int u[], int setI[]);
int main()
{
ifstream infile;
int a[10];
int b[10];
int u[20];
int x[10];
int d[10];
int setI[20];
int counter=0;
infile.open("sets.txt");
while(!infile.eof())
{
while(counter < 20)
{
if(counter < 10)
{
infile >> a[counter];
}
else
{
infile >>b[counter-10];
}
counter++;
}
counter = 0;
for(int i = 0; i < 20; i++)
{
if(i < 10)
{
cout<<"Set A contains : "<<a[i]<<endl;
}
else
{
cout<<"Set B contains : "<<b[i-10]<<endl;
}
}
int setF[10];
int countItems = 0;
int numNotDuplicates = 0;