I need to write a C program to test the transitivity of an i

I need to write a C++ program to test the transitivity of an input file.

The input file will describe the direct relationships between up to 26 elements (named \"A,\" \"B,\" \"C,\" etc.). We will determine if the input implies that the first element (\"A\") is also related, via some sequence of transitive relationships, to the last element of the input file. Additionally, we will check for such transitive relationships from every fifth element after the first (\"F,\" \"K,\" etc.) to the last element of each input file.

The program will output the results of each relationship search, as follows, either:

- element X does not have connectivity to end vertex Y.

- element X does have connectivity to end vertex Y.

Where X represents the name of each fifth vertex starting with A, and Y represents the name of the last vertex described in a given input file.

Each input file will include, on the first line, the number of elements for this relationship family. Each subsequent line will contain exactly two numbers, representing an implicative relationship from the first to the second element. (For programming convenience, the elements are described by integers rather than letters: A=0, B=1,C=2, etc.)

For example, the file:

8

0 1

0 2

0 5

1 2

1 3

1 6

2 3

3 5

3 6

5 6

6 7

describes 8 data elements (A, B, C, D, E, F, G, and H), with the following implicative relationships:

A -> B

A -> C

A -> F

B -> C

B -> D

B -> G

C -> D

D -> F

D -> G

F -> G

G ->H

For simplification of this problem IN ALL CASES X < Y.

For assignment, may assume \"friendly\" input, that is, the input data files are guarenteed to be in format stated above.

For this sample input file, your program should output:

element A has connectivity to end vertex H.

element F has connectivity to end vertex H.

Solution

#include<iostream>
#include <vector>

using namespace std;
class node {
public:
int id;
int out_list[26];
};
node arr[26];
int start, e;
bool search(int i) {
if (i >= 26)
return false;
if (arr[i].out_list[e] == 1) {
return true;
} else {
for (int j = 0; j < 26; j++) {
if (arr[i].out_list[j] == 1) {
return search(j);
}
}

}
return false;
}
int main(int argc, char **argv) {
int num_of_input;
cin >> num_of_input;
int first, second;
for (int i = 0; (cin >> first >> second); i++) {

if (i == 0)
start = first;

e = second;
//cout << first << \" \" << e << \" \" << num_of_input << endl;

arr[first].out_list[second] = 1;

}

for (int i = start; i < e; i = i + 5) {
char s=(char)( start + 65);
char ee=(char) (e + 65);
if (search(i))
cout << \"Element \" << s
<< \" does have connectivity to end vertex \" << ee
<< endl;
else
cout << \"Element \" << s
<< \" does not have connectivity to end vertex \"
<< ee << endl;

}
}

I need to write a C++ program to test the transitivity of an input file. The input file will describe the direct relationships between up to 26 elements (named
I need to write a C++ program to test the transitivity of an input file. The input file will describe the direct relationships between up to 26 elements (named
I need to write a C++ program to test the transitivity of an input file. The input file will describe the direct relationships between up to 26 elements (named

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site