Hi, I'm new here, I ran into a small problem while writing an math extension library. So far I have a Rational class that represents rational numbers as listed below:

Code:

class Rational {
friend bool operator==(const Rational& l, const Rational& r);
friend bool operator!=(const Rational& l, const Rational& r);
friend bool operator>=(const Rational& l, const Rational& r);
friend bool operator<=(const Rational& l, const Rational& r);
friend bool operator<(const Rational& l, const Rational& r);
friend bool operator>(const Rational& l, const Rational& r);
public:
Rational();
~Rational();
Rational(int n, unsigned d = 1);
Rational(int n, int d);
Rational(const Rational& r);
Rational& operator-(void);
Rational& operator^(int exp);
Rational& operator=(const Rational& r);
Rational& operator+=(const Rational& r);
Rational& operator-=(const Rational& r);
Rational& operator*=(const Rational& r);
Rational& operator/=(const Rational& r);
Rational& operator++(void);
Rational& operator--(void);
Rational operator++(int);
Rational operator--(int);
Rational operator+(const Rational& r);
Rational operator-(const Rational& r);
Rational operator*(const Rational& r);
Rational operator/(const Rational& r);
operator double(void) const;
double operator^(const Rational& r);
void print(void) const;
private:
int num;
unsigned den;
unsigned gcd(int x, unsigned y);
void reduce(void);
};

All implementations for above is done but I can't seen to convert floating point numbers into rational numbers, is there an algorithm to do this? It would be better if it doesn't attempt to convert irrational floating point numbers.

I need an advice as how to write this, so any help would be appreciated.