-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrational.h
More file actions
executable file
·55 lines (47 loc) · 1.47 KB
/
rational.h
File metadata and controls
executable file
·55 lines (47 loc) · 1.47 KB
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
//CUSTOM VERSION for use with aSTbc
// rational.h: declaration of Rational ADT
#ifndef RATIONAL_H
#define RATIONAL_H
#include <iostream>
#include <string>
using std::istream;
using std::ostream;
// Rational ADT: class description
class Rational {
public: // member functions
// constructor
Rational(int numer = 0, int denom = 1);
// some arithmetic and stream facilitators
Rational Add(const Rational &r) const;
Rational Multiply(const Rational &r) const;
Rational Subtract(const Rational &r) const;
Rational Divide(const Rational &r) const;
void Insert(ostream &sout) const;
void Extract(istream &sin);
//facilitators
int Compare(const Rational& r) const;
// inspectors
int Numerator() const;
int Denominator() const;
protected:
// mutators
void SetNumerator(int numer);
void SetDenominator(int denom);
//facilitators
void Reduce();
private:
// data members
int NumeratorValue;
int DenominatorValue;
};
// Rational ADT: auxiliary operator description
Rational operator+(const Rational &r, const Rational &s);
Rational operator*(const Rational &r, const Rational &s);
Rational operator-(const Rational &r, const Rational &s);
Rational operator/(const Rational &r, const Rational &s);
ostream& operator<<(ostream &sout, const Rational &s);
istream& operator>>(istream &sin, Rational &r);
bool operator==(const Rational& r,const Rational& s);
bool operator>(const Rational& r,const Rational& s);
bool operator<(const Rational& r,const Rational& s);
#endif