Category : Files from Magazines
Archive   : CUJ9203.ZIP
Filename : 1003074A

 
Output of file : 1003074A contained in archive : CUJ9203.ZIP


Listing 7

//
// rational.h
//
#include

class rational
{
public:
rational() { }
rational(long n) : num(n), denom(1) { }
rational(long n, long d) : num(n), denom(d) { }
rational &operator+=(rational r);
rational &operator-=(rational r);
rational &operator*=(rational r);
rational &operator/=(rational r);
rational operator+() { return *this; }
rational operator-();
rational operator++() { return *this += 1; }
rational operator--() { return *this -= 1; }
rational operator++(int); // postfix ++
rational operator--(int); // postfix --
void put(FILE *);
private:
long num, denom;
void simplify();
};

// ... the rest of rational.h as in Listing 5