Ok, I'm working on this code where I read in two lines from a text document, then store them in an array, write a binary code for each to indicate what words are in what array, and then compare the two arrays in a variety of ways. I got most of it to work. I create the binary code for the first line fine, and same for the second. Then, when I try to create the binary code for the array that shows what words are in both arrays, it messes up the binary code I made for the second line.
I know that probably doesn't make sense, so here's the example.
Line 1 = I eat green eggs and ham I eat
Line 2 = I don't like green eggs Sam I am
Words used in both lines (1U2) = I eat green eggs and ham don't like Sam am
Line 1 binary = 1 1 1 1 1 1 0 0 0 0
Line 2 binary = 1 0 1 1 0 0 1 1 1 1
1U2 binary = 1 1 1 1 1 1 1 1 1 1
After it creates 1U2, it changes the binary for Line 2 to
1 1 1 1 0 0 1 1 1 1
I've even tried switching their places in hope that that would help, but it seems that my binary for Line 2 and 1U2 always get messed up when I try to create their binary codes.
And also, when I change it back to my main function, somehow binary code for 1U2 gets messed up as well. I'm not entirely sure how, but it changes from all 1's to 2 0 and the rest 1's. If anyone sees why this is messing up, I would appreciate some help.
Here's the pieces of the code that are giving me an issue (if you want the rest, just ask and I can post it). The red sections are where to code goes wrong:
main ()
{ int ALast, BLast, ABLast=1, x=0;
string letter[5] = {"A", "B", "AUB", "A^B", "A-B"};
int BitA[ABLast], BitB[ABLast], BitAUB[ABLast], BitAIB[ABLast];
string A[10], B[10], AB[20], AIB[20], A_B[20];
ifstream InData;
getfile (InData);
input (InData, ALast, A); // Puts the lines into an array
input (InData, BLast, B); // Puts the lines into an array
developArray (A, B, AB, ALast, BLast, ABLast, BitA, BitB, BitAUB);
[B] set (BitAIB, ABLast);
intersect (BitA, BitB, BitAIB, AIB, AB, ABLast); // BitAUB goes bad[/B]
//print outputs
write (ABLast, A, BitA, letter[0]);
cout << endl;
write (ABLast, B, BitB, letter[1]);
cout << endl << endl << endl;
write (ABLast, AB, BitAUB, letter[2]);
write (ABLast, AIB, BitAIB, letter[3]);
cout << endl;
system ("pause");
return 0;
}
void developArray (string A[], string B[], string AB[], int ALast, int BLast, int& ABLast, int BitA[], int BitB[], int BitAB[])
// Stores all the functions used to create the arrays A, B, AB, BitA, BitB, Bit AB
{
createArray (A, B, ALast, BLast, AB, ABLast);
removeDup (A, ALast);
removeDup (B, BLast);
set (BitA, ABLast);
createBit (A, AB, ALast, ABLast, BitA);
[B] set (BitB, ABLast);
createBit (B, AB, BLast, ABLast, BitB); // B fine
set (BitAB, ABLast);
createBit (AB, AB, ABLast, ABLast, BitAB); // B goes bad[/B]
}
void intersect (int BitA[], int BitB[], int BitAB[], string AIB[], string AB[], int ABLast)
// Show what two arrays have in common
{ int x = 0;
for (int count = 0; count < ABLast; count++)
{ if ( BitA[count] == 1 )
{ if (BitB[count] == 1)
{ BitAB[count] = 1;
AIB[x] = AB[count];
x++;}
} } }
// Used in developArray
void set (int Set[], int last)
// Sets all things in array equal to 0
{ for (int z = 0; z < last; z++)
{ Set[z] = 0; } }
void createBit (string A[], string AB[], int ALast, int ABLast, int BitA[])
// Compares AB to A and stores in BitA of length ABLast
{ for (int i = 0; i < ABLast; i++)
{ for (int x = 0; x < ALast; x++)
{ if (AB[i] == A[x])
{ BitA[i] = 1;
break; }
} } }