2021-09-17 12:32:14 +02:00
|
|
|
#pragma once
|
2021-09-17 11:59:28 +02:00
|
|
|
|
2021-09-17 14:47:29 +02:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
namespace FractionNS {
|
|
|
|
class Fraction
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int m_numerator, m_denominator;
|
2021-09-20 16:34:45 +02:00
|
|
|
void reduce();
|
2021-09-17 14:47:29 +02:00
|
|
|
public:
|
2021-09-17 12:32:14 +02:00
|
|
|
Fraction(int, int);
|
2021-09-17 14:47:29 +02:00
|
|
|
Fraction(int);
|
|
|
|
Fraction(double);
|
|
|
|
Fraction(float);
|
|
|
|
Fraction(const Fraction&);
|
|
|
|
|
|
|
|
int getNumerator() const;
|
|
|
|
int getDenominator() const;
|
|
|
|
void setNumerator(const int);
|
|
|
|
void setDenominator(const int);
|
|
|
|
|
|
|
|
QString display() const;
|
|
|
|
|
|
|
|
bool operator==(const int) const;
|
|
|
|
bool operator==(const float) const;
|
|
|
|
bool operator==(const double) const;
|
|
|
|
bool operator==(const Fraction&) const;
|
|
|
|
|
|
|
|
bool operator!=(const int) const;
|
|
|
|
bool operator!=(const float) const;
|
|
|
|
bool operator!=(const double) const;
|
|
|
|
bool operator!=(const Fraction&) const;
|
|
|
|
|
|
|
|
Fraction& operator+(const int) const;
|
|
|
|
Fraction& operator+(const Fraction&) const;
|
|
|
|
|
|
|
|
Fraction& operator+=(const int);
|
|
|
|
Fraction& operator+=(const Fraction&);
|
2021-09-20 16:34:45 +02:00
|
|
|
|
|
|
|
Fraction& operator-(const int) const;
|
|
|
|
Fraction& operator-(const Fraction&) const;
|
|
|
|
|
|
|
|
Fraction& operator-=(const int);
|
|
|
|
Fraction& operator-=(const Fraction&);
|
2021-09-21 09:22:46 +02:00
|
|
|
|
|
|
|
Fraction& operator*(const int) const;
|
|
|
|
Fraction& operator*(const Fraction&) const;
|
|
|
|
|
|
|
|
Fraction& operator*=(const int);
|
|
|
|
Fraction& operator*=(const Fraction&);
|
2021-09-17 14:47:29 +02:00
|
|
|
};
|
|
|
|
}
|