-
Notifications
You must be signed in to change notification settings - Fork 0
/
rational.h
39 lines (33 loc) · 961 Bytes
/
rational.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
#ifndef RATIONAL
#define RATIONAL
#include "fstream"
class rational{
public:
rational():mNumerator(0),mDenominator(1){}
rational(int n):mNumerator(n),mDenominator(1){}
rational(int n,int d);
int getNumerator()const;
int getDenominator()const;
void reciprocal();
rational operator+(const rational& other);
rational operator-(const rational& other);
rational operator *(const rational& other);
rational operator /(const rational& other);
rational operator++();
rational operator--();
void printRationalNumber()const;
friend std::ostream& operator<<(std::ostream& os,const rational& a)
{
os<<a.getNumerator()<<"/"<<a.getDenominator();
return os;
}
friend std::istream& operator>>(std::istream& is, rational& a){
is>>a.mNumerator>>a.mDenominator;
return is;
}
private:
void mGcd(int n,int d);
int mNumerator;
int mDenominator;
};
#endif // RATIONAL