Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:44:22+00:00 2026-05-26T20:44:22+00:00

I am having difficulty trying to code these functions. They are not working properly

  • 0

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.
Sample inputs:

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:

bool reflexive(int a[], int sizeOfA, int b[], int sizeOfB) 
{
  bool hold = true;
  for(int i=0; i+1<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 << "Reflexive - Yes" << endl; 
  else
    cout << "Reflexive - No" << 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<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 << "Symmetric - Yes" << endl;
else // if hold is false return false
    cout << "Symmetric - No" << endl;
}

void antiSymmetric(int b[], int sizeOfB)
{
bool hold = true; // set hold to true
for(int i = 0; i < sizeOfB;) // for each pair (e,f) in b
{
    if(hold == false)
    {
        cout << "AntiSymmetric - No" << endl; 
        break; //Did not find (e,e) in b
    }
    for(int j = 0; j < sizeOfB;)
    {
        if(b[i] == b[j+1] && 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 << "AntiSymmetric - Yes" << 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 << "Set 1: " << endl;
reflexive(set1, 3, rel1, 4);
symmetric(set1, 3, rel1, 4);
antiSymmetric(set1, 3, rel1, 4);

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

cout << 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 << "Set 3: " << endl;
charReflexive(set3, 3, rel3, 18);
charSymmetric(set3, 3, rel3, 18);
charAntiSymmetric(set3, 3, rel3, 18);

cout << 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 << "Set 4: " << endl;
reflexive(set4, 8, rel4, 20);
symmetric(set4, 8, rel4, 20);
antiSymmetric(set4, 8, rel4, 20);

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

return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:44:23+00:00Added an answer on May 26, 2026 at 8:44 pm

    I only read reflexive, but you need to rethink that. In general, if the first element in A is not equal to the first element in B, it prints "Reflexive - No" and stops. I don’t think you thought that through all the way.

    [EDIT] Alright, now that we’ve finally established what int a[] holds, and what int b[] holds, I have to start over. What everyone had before was completely wrong. (Me especially, my old “reflexive” was really symmetric, as well as interpreting the inputs wrong.) If you’ve learned about C++ classes/containers, I would highly recommend replacing int a[] and int b[] with something like:

    template <class T>
    struct relation {
        typedef std::pair<T,T> single_relation;
    
        std::set<T> elements;
        std::set<single_relation> all_relations;
    };
    

    or something similar, but that’s just me.

    reflexive:
        set holds to true
        for each element e in a
            if pair(e,e) is not in b
                set holds to false
                break
    symmetric:
        set holds to true
        for each pair(e,f) in b
            if pair(f,e) is not in b
                set holds to false
                break
    antisymetric: 
        set holds to true
        for each pair(e,f) in b
            if pair(f,e) is in b
                if f is not e
                    set holds to false
                    break
    transitive:
        set holds to true
        for each pair(e,f) in b
            for each pair(f,g) in b
                if pair(e,g) is not in b
                    set holds to false
                    break
            if holds is false
                break
    

    Note that only reflexive actually requires a[] at all.
    Demo:

    bool pair_is_in_relation(int left, int right, int b[], int sizeOfB)
    {
        for(int i=0; i+1<sizeOfB; i+=2) {
            if (b[i]==left && b[i+1]==right)
                return true;
        }
        return false;
    }
    bool antiSymmetric(int b[], int sizeOfB) 
    {
        bool holds = true;
        for(int i=0; i+1<sizeOfB; i+=2) {
            int e = b[i];
            int f = b[i+1];
            if(pair_is_in_relation(f, e, b, sizeOfB)) {
                if (e != f) {
                    holds = false;
                    break;
                 }
            }
        }
        if (holds)
            std::cout << "AntiSymmetric - Yes" << endl; 
        else
            std::cout << "AntiSymmetric - No" << endl; 
        return holds;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having difficulty using MooseX::Declare properly when calling BUILDARGS. I'm trying to create an
I'm having difficulty working with the animation blocks. I'm trying to have the first
im having some difficulty trying to pull out a specific value from a cookie.
Trying to convert the following but am having difficulty. Can anyone see where I'm
I'm having a great deal of difficulty trying to figure out the logic behind
I'm trying to use this library (which looks very nice) but I'm having difficulty
I'm trying to learn the MapKit with Monotouch and I'm having difficulty figuring out
I'm having difficulty with Javascript instance variables. I'm trying to make an easy way
I have been trying to tackle this problem , but I am having difficulty
I have a sum that I'm trying to compute, and I'm having difficulty parallelizing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.