46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
|
|
class NR {
|
|
private:
|
|
int m_Numerator;
|
|
int m_Denominator; // has to be > 0, sign is carried by the numerator
|
|
|
|
public:
|
|
NR();
|
|
NR(int entier);
|
|
NR(int numerator, int denominator); // check if denominator != 0
|
|
|
|
int GetNumerator() const;
|
|
int GetDenominator() const;
|
|
|
|
bool operator==(const NR& opNR) const;
|
|
bool operator<(const NR& opNR) const;
|
|
bool operator>(const NR& opNR) const;
|
|
|
|
bool operator!=(const NR& opNR) const;
|
|
bool operator<=(const NR& opNR) const;
|
|
bool operator>=(const NR& opNR) const;
|
|
|
|
NR operator+(const NR& opNR) const;
|
|
NR operator-(const NR& opNR) const;
|
|
NR operator*(const NR& opNR) const;
|
|
NR operator/(const NR& opNR) const;
|
|
|
|
NR& operator+=(const NR& opNR);
|
|
NR& operator-=(const NR& opNR);
|
|
NR& operator*=(const NR& opNR);
|
|
NR& operator/=(const NR& opNR);
|
|
|
|
void Invert();
|
|
|
|
friend std::ostream& operator<<(std::ostream& os, const NR& opNR);
|
|
friend std::istream& operator>>(std::istream& os, NR& opNR);
|
|
|
|
private:
|
|
void Reduce();
|
|
};
|
|
|
|
int PGCD(int x, int y);
|