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).
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.
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/