nombres rationnels

This commit is contained in:
Pierre CHATAIGNER
2024-02-25 13:06:11 +01:00
parent a5a14a9763
commit c7268fe536
4 changed files with 265 additions and 5 deletions

View File

@@ -1,12 +1,42 @@
#pragma once
#include <iostream>
class NR {
private:
int m_Numerator;
int m_Denominator;
int m_Denominator; //has to be > 0, sign is carried by the numerator
public:
NR() : m_Numerator(0), m_Denominator(1) {}
NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
NR(int numerator, int denominator) : m_Numerator(numerator), m_Denominator(denominator) {}
};
NR(int numerator, int denominator); //check if denominator != 0
void NRset(int numerator, int denominator); //same
void reduceNR(); //divide by PGCD, not automatically called yet
void invertNR();
int NRgetNum() const;
int NRgetDen() const;
NR& operator =(const NR& opNR);
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;
friend std::ostream& operator <<(std::ostream& os, const NR& opNR);
friend std::istream& operator >>(std::istream& os, NR& opNR);
NR operator +(const NR& opNR) const;
NR operator -(const NR& opNR) const;
NR operator *(const NR& opNR) const;
NR operator /(const NR& opNR) const;
static void test();
};
int PGCD(int x, int y);