-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFraction.h
44 lines (39 loc) · 1.6 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
#include <iostream>
#ifndef FRACTION_H
#define FRACTION_H
class Fraction
{
public:
Fraction();
Fraction (int num);
Fraction (int num, int den);
Fraction (const Fraction& other);
Fraction& operator=( const Fraction& other);
friend bool operator> (const Fraction& fra1, const Fraction& fra2);
friend bool operator>= (const Fraction& fra1, const Fraction& fra2);
friend Fraction operator+ (const Fraction& fra1, const Fraction& fra2);
friend Fraction operator- (const Fraction& fra1, const Fraction& fra2);
friend Fraction operator* (const Fraction& fra1, const Fraction& fra2);
friend Fraction operator/(const Fraction& fra1, const Fraction& fra2);
friend std::ostream& operator<< (std::ostream& os, const Fraction& f);
friend bool operator== (const Fraction& fra1, const Fraction& fra2);
friend bool operator!= (const Fraction& fra1, const Fraction& fra2);
friend bool operator< (const Fraction& fra1, const Fraction& fra2);
friend bool operator<= (const Fraction& fra1, const Fraction& fra2);
Fraction operator-() const;
Fraction& operator+= (const Fraction& other);
Fraction& operator-= (const Fraction& other);
Fraction& operator*= (const Fraction& other);
Fraction& operator/= (const Fraction& other);
Fraction& operator++ (); //prefix ++
Fraction operator++ (int); //postfix ++
int getNumerator() const;
int getDenominator() const;
void display() const;
private:
int num;
int den;
void normalize();
int gcd(int a, int b) const;
};
#endif // FRACTION_H