Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(( Could You Fix This Code It is Not Working And I Need You Help)) In set theory

ID: 3635537 • Letter: #

Question

(( Could You Fix This Code It is Not Working And I Need You Help))
In set theory, the union of two sets is the list of all elements that appear in either (or both) of the sets., and the intersection of the two sets is the list of all elements that appear in both sets only .




A consists of the elements


A {1, 3,7, 6, 2 ,5 }




B consist of the elements


B { -1, 2, 0, 5, 8, 9}




A union B {-1, 0, 1, 2, 3, 5, 6, 7, 8, 9


A intersection B { 2, 5 }




Write a program in C++ that reads in two arrays of integers representing the elements of two sets from two different user-specified input files and calculates both the union and the intersection of the two sets. Use arrays to contain the input sets and build both the union and intersection. Note that the input sets may not be sorted in order, so your algorithm must work regardless of the order in which set elements are entered.






Test your program on two files




inputA. dat 0, 1, -3, 5, -11, 6, 8, 11,17,15,7,12




inputB. dat 0, -1, 3, 7, -6, 16, 5, 12, 21






PROJECT 6


Algorithm:

Populate arrays using two input files.

Prompt user for file names.

Create files with numeric data, i.e. numbers without commas.

Find union of files

Remove duplicates

Find intersection


No duplicates are allowed in intersection or union.

I have a code that answer this question! but i Want another code with no function if possible! here it is:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

// sorst the array in ascending order
void sort(int a[], int size)
{
for(int i=0; i < size-1; i++)
for(int j = i+1; j < size; j++)
if(a[i] > a[j])
{
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}

// finds and displays the union of A and B
void unionof(int a[], int b[], int asize, int bsize)
{
// defining new array dynamically
int *c = new int[asize + bsize];
int i = 0, j = 0, k = 0;

// placing the both elements of set A and B into the C
while(i < asize && j < bsize)
{
if(a[i] != b[j])
{
if(b[j] > a[i])
{
c[k++] = b[j];
c[k++] = a[i];
}
else
{
c[k++] = a[i];
c[k++] = b[j];
}
}
else
c[k++] = a[i];
i++;
j++;
}

while(i < asize)
c[k++] = a[i++];
while(j < bsize)
c[k++] = a[j++];

// displaying C
cout << " {";
for(i=0; i<k; i++)
cout << c[i] << " ";
cout << "}" << endl;
}

// finds and displays the intersection of A and B
void intersectionof(int a[], int b[], int asize, int bsize)
{
int size = bsize < asize ? bsize : asize;
int *c = new int[size]; // new array C to store intersection values
int k = 0;

// storing the elements that are both in A and B into the C
if(asize < bsize)
{
for(int i=0; i<asize; i++)
for(int j=0; j<bsize; j++)
{
if(a[i] == b[j])
c[k++] = a[i];
}
}
else
{
for(int i=0; i<bsize; i++)
for(int j=0; j<asize; j++)
{
if(b[i] == a[j])
c[k++] = b[i];
}
}

// displaying intersection set
cout << " {";
for(int i=0; i<k; i++)
cout << c[i] << " ";
cout << "}" << endl;
}

// main function
int main()
{
string filename1, filename2;
//read file names
cout << "Enter first file name: ";
cin >> filename1;
cout << "Enter second file name: ";
cin >> filename2;

// open both files
ifstream fileA, fileB;
fileA.open(filename1.c_str());
fileB.open(filename2.c_str());

// arrays two hold two sets
int a[50], b[50];
int asize = 0, bsize = 0;

// reading and displaying set A from inputA.dat
cout << " A consists of the elements: " << endl;
while(!fileA.eof())
{
fileA >> a[asize];
cout << a[asize++] << " ";
}

//reading and displaying set B from inputB.dat
cout << " B consists of the elements: " << endl;
while(!fileB.eof())
{
fileB >> b[bsize];
cout << b[bsize++] << " ";
}

// sorting both sets in ascending order
sort(a, asize);
sort(b, bsize);

// calling appropriate functions
// to find A union B and A intersetion B
cout << " A union B ";
unionof(a, b, asize, bsize);
cout << " A intersection B ";
intersectionof(a, b, asize, bsize);

//closing files
fileA.close();
fileB.close();

return 0;
}

Explanation / Answer

Please Rate:Thanks #include using namespace std; class IntegerSet { public: IntegerSet()//default constructor { int num; for ( aArray[num]; num