Relation template

closed account (23q2T05o)
Hi, I have to make a template class that describes Binary Relation between elements of type T and elements of type U. The relation shows sequnece of pairs that are in realtion. I jave to do constructors, method that find if the elements are in realtion r(t, u), a method !r that finds the reverse realtion r (all the pairs (u,t) that are in relation r).

What I have done:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
template <typename T, typename U> 
class BinaryRelation
{
protected:
	T fA;
	U fB;

public:
	//constructors
	BinaryRelation();
	BinaryRelation(T a, U b);
	BinaryRelation& operator=(const BinaryRelation& other);
	BinaryRelation(const BinaryRelation& other);
	~BinaryRelation();

	//checks if T and U are in relation
	bool isRelation(T a, U b)const;
	bool reverse_relation(T& a, T& b)const;

	//operators
	BinaryRelation& operator+=(const BinaryRelation& other);
	BinaryRelation& operator^=(const BinaryRelation& other);
	BinaryRelation& operator*= (const BinaryRelation & other);

	//HAVE TO SAVE THEM IN FILES.
	friend std::istream& operator>>(std::istream& in, BinaryRelation& vector);
	friend std::ostream& operator<<(std::ostream& out, const BinaryRelation& vector);

	//finds the domain
	BinaryRelation domain();
	BinaryRelation ran();

	//finds the ooposite relation
	BinaryRelation opposite();

	void read_realtion();
	void print_realtion()const;
};


Idk how to do the method that says if they are in relation or not. I mean if I have two int numbers and say if the second one is bigger thatn the first one then they are in relation but if have two char* idk what to do. Idk if thatt for the bigger number is correct. The problem is that I don't understand how to check if the T a and U b are in relation /for the diff types of T and U/. Also idk what constructors should I have that are oppropriate.
Last edited on
First there is:
The relation shows sequnece of pairs that are in realtion.

Then:
if I have two int numbers and say if the second one is bigger thatn the first one then they are in relation but if have two char* idk what to do

Perhaps you could begin by defining what a BinaryRelation is before attempting to code something that doesn't have a definition.
something like this gives you a path to figure out what the type is

1
2
char b{};
	std::cout << typeid(b).name();


as far as relation comparisons of chars etc. I'm not exactly sure what youre looking for there but i'd imagine a good place to start would be here. http://www.asciitable.com/
Topic archived. No new replies allowed.