How To Test Whether a Set is Reflexive, Symmetric, Anti-Symmetric and/or Transitive?
<p>I am having difficulty trying to code these functions.  They are not working properly and do not know what I am doing wrong.  As for Transitive, I cannot even get started and would like any help you can give on it and what I am doing wrong in my functions.  Thank you.<br>
Sample inputs:</p>

<pre><code>0 1 2 3 //elements (A)
0 0     //relations (B)
1 1
2 2
3 3

x y z //elements (A)
x y   //relations (B)
y z
y y
z z

x y z //elements (A)
x x   //relations (B)
y z
x y
z y
x z
y y
z x
y x
z z

1 2 3 4 5 6 7 8 //elements (A)
1 4             //relations (B)
1 7
2 5
2 8
3 6
4 7
5 8
6 6
1 1
2 2
</code></pre>

<p>Code:</p>

<pre><code>bool reflexive(int a[], int sizeOfA, int b[], int sizeOfB) 
{
  bool hold = true;
  for(int i=0; i+1&lt;sizeOfB; i+=2) 
  {
    int e = b[i];
    int e1 = b[i];
    if(pair_is_in_relation(e1, e, b, sizeOfB) == false) 
    {
        if (hold) 
    {
            return false;
            break;
         }
    }
  }
  if (hold)
    cout &lt;&lt; "Reflexive - Yes" &lt;&lt; endl; 
  else
    cout &lt;&lt; "Reflexive - No" &lt;&lt; endl; 
return hold;
}

bool symmetric(int a[], int sizeOfA, int b[], int sizeOfB)
{
bool hold = true; // set hold to true
for(int i=0; i+1&lt;sizeOfB; i+=2) // for each pair (e,f) in b
{
    int e = b[i];
    int f = b[i+1];
    if(is_in_relation(f, e, b, sizeOfB)) // if pair(e,f) is not in b
    {
        if(hold) // set hold to false
        {
            return false;
            break;
        }
    }
}
if(hold) // if hold return true
    cout &lt;&lt; "Symmetric - Yes" &lt;&lt; endl;
else // if hold is false return false
    cout &lt;&lt; "Symmetric - No" &lt;&lt; endl;
}

void antiSymmetric(int b[], int sizeOfB)
{
bool hold = true; // set hold to true
for(int i = 0; i &lt; sizeOfB;) // for each pair (e,f) in b
{
    if(hold == false)
    {
        cout &lt;&lt; "AntiSymmetric - No" &lt;&lt; endl; 
        break; //Did not find (e,e) in b
    }
    for(int j = 0; j &lt; sizeOfB;)
    {
        if(b[i] == b[j+1] &amp;&amp; b[i+1] == b[j]) //If true, then pair(f,e) exists
        {
            if(b[i+1] != b[i]) //If true, relation is antisymmetric
            {
                hold = true;
                break;
            }
            else
            {
                hold = false;
                j = j + 2;
            }
        }
        else
        {
            hold = false;
            j = j + 2;
        }

    }
    i = i + 2;

}
if(hold == true)
    cout &lt;&lt; "AntiSymmetric - Yes" &lt;&lt; endl;

}

void transitive(int a[], int sizeOfA, int b[], int sizeOfB)
{

}

int main()
{
char keepGoing = 'y';
    while (keepGoing=='y') {

int set1[4] = {0, 1, 2, 3};
int rel1[8] = {0, 0, 1, 1, 2, 2, 3, 3};
cout &lt;&lt; "Set 1: " &lt;&lt; endl;
reflexive(set1, 3, rel1, 4);
symmetric(set1, 3, rel1, 4);
antiSymmetric(set1, 3, rel1, 4);

cout &lt;&lt; endl;
char set2[4] = {'x', 'y', 'z'};
char rel2[8] = {'x', 'y', 'y', 'z', 'y', 'y', 'z', 'z'};
cout &lt;&lt; "Set 2: " &lt;&lt; endl;
charReflexive(set2, 4, rel2, 8);
charSymmetric(set2, 4, rel2, 8);
charAntiSymmetric(set2, 4, rel2, 8);

cout &lt;&lt; endl;
char set3[3] = {'x', 'y', 'z'};
char rel3[18] = {'x', 'x', 'y', 'z', 'x', 'y', 'z', 'y', 'x', 
                 'z', 'y', 'y', 'z', 'x', 'y', 'x', 'z', 'z'};
cout &lt;&lt; "Set 3: " &lt;&lt; endl;
charReflexive(set3, 3, rel3, 18);
charSymmetric(set3, 3, rel3, 18);
charAntiSymmetric(set3, 3, rel3, 18);

cout &lt;&lt; endl;
int set4[8] = {1, 2, 3, 4, 5, 6, 7, 8};
int rel4[20] = {1, 7, 2, 5, 2, 8, 3, 6, 4, 7, 5, 8, 6, 6, 1, 1,
                2, 2};
cout &lt;&lt; "Set 4: " &lt;&lt; endl;
reflexive(set4, 8, rel4, 20);
symmetric(set4, 8, rel4, 20);
antiSymmetric(set4, 8, rel4, 20);

cout &lt;&lt; endl &lt;&lt; "Would you like to test it again? (y/n): ";
    cin &gt;&gt; keepGoing;
}

return 0;
}
</code></pre>
