-
Notifications
You must be signed in to change notification settings - Fork 3
/
fraction.h
86 lines (76 loc) · 2.03 KB
/
fraction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include <cmath>
namespace math
{
template <class Number>
Number gcd(Number n1, Number n2)
{
if (n2 > n1)
{
Number n3 = n1;
n1 = n2;
n2 = n3;
}
if (n2 == 0)
{
return n1;
}
return gcd(n2, n1 % n2);
}
template <class Number>
Number lcm(Number n1, Number n2)
{
return n1 * n2 / gcd(n1, n2);
}
template <class Number>
Number anyAbs(Number num)
{
if (num < 0)
{
return -num;
}
return num;
}
}
class Fraction
{
private:
int denominator, numerator;
public:
Fraction(int denominator, int numerator);
Fraction(int num);
void irregularFraction();
void operator=(const Fraction & frac);
void operator=(const int num);
bool operator==(const Fraction & frac);
bool operator!=(const Fraction & frac);
Fraction operator+(const Fraction & frac);
Fraction operator-(const Fraction & frac);
Fraction operator*(const Fraction & frac);
Fraction operator/(const Fraction & frac);
bool operator<(const Fraction & frac);
bool operator>(const Fraction & frac);
bool operator<=(const Fraction & frac);
bool operator>=(const Fraction & frac);
Fraction operator-() const;
Fraction inverseFraction() const;
friend Fraction operator+(const int num, const Fraction & frac);
friend Fraction operator-(const int num, const Fraction & frac);
friend Fraction operator*(const int num, const Fraction & frac);
friend Fraction operator/(const int num, const Fraction & frac);
friend bool operator<(const int num, const Fraction & frac);
friend bool operator>(const int num, const Fraction & frac);
friend bool operator<=(const int num, const Fraction & frac);
friend bool operator>=(const int num, const Fraction & frac);
Fraction operator+(const int num);
Fraction operator-(const int num);
Fraction operator*(const int num);
Fraction operator/(const int num);
bool operator<(const int num);
bool operator>(const int num);
bool operator<=(const int num);
bool operator>=(const int num);
int getNumerator() const;
int getDenominator() const;
Fraction abs();
};