-
Notifications
You must be signed in to change notification settings - Fork 0
/
rational.h
66 lines (57 loc) · 1.8 KB
/
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
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
#ifndef RATIONAL_H
#define RATIONAL_H
#include <iostream>
using namespace std;
//create the rational class
class Rational
{
//public methods and variables
public:
//empty constructor
Rational();
//constructor w/ numerator and denominator
Rational(int numerator, int denominator);
//constructor with only numerator and denominator equal to 1
Rational(int numerator);
//getNumerator method
int getNumerator() const;
//getDenominator method
int getDenominator() const;
//compare two rationals wether number is less, equal to , or greater than
int compare(const Rational &other) const;
//print the rational
void print() ; // uses default argument
//simply the fraction to lowest terms using gcd function
void simplify();
//add two rationals
void add(const Rational &other);
//subtract two rationals
void sub(const Rational &other);
//multiple two rationals
void mul(const Rational &other);
//divide two rationals
void div(const Rational &other);
//find if a rational is less than another
bool less(const Rational &other);
//find the negative of a rational
void neg(const Rational &other);
//private variables for the numerator and denominator of the rational
private:
int numerator_;
int denominator_;
};
//addition operator
Rational operator+(const Rational & a);
//subtraction operator
Rational operator-(const Rational & a);
//addition of two rationals operator
Rational operator+(const Rational & a, const Rational & b);
//subtraction of two rationals operator
Rational operator-(const Rational & a, const Rational & b);
//multiplication of two rationals operator
Rational operator*(const Rational & a, const Rational & b);
//divison of two two rationals operator
Rational operator/(const Rational & a, const Rational & b);
// relational operators
bool operator<(const Rational & a, const Rational & b);
#endif