-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigRational.h
71 lines (62 loc) · 2.78 KB
/
BigRational.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
/*******************************************************
* COMP2012 - 2012/13 Spring
* Programming Assignment 3
* File: BigRational.h
*******************************************************/
#ifndef BIGRATIONAL_H_
#define BIGRATIONAL_H_
#include "BigNumber.h"
#define USI unsigned short int
#define BNL list<unsigned short int> // Stands for Big Number List
#define Nmr digitLists[0] // Stands for Numerator
#define Dno digitLists[1] // Stands for Denominator
class BigRational : public BigNumber
{
public:
BigRational();
BigRational(int n);
BigRational(string c);
BigRational(const BigRational& a);
~BigRational();
BigRational& operator=(const BigRational& a);
BigRational& operator+=(const BigRational& a);
BigRational& operator-=(const BigRational& a);
BigRational& operator*=(const BigRational& a);
BigRational& operator/=(const BigRational& a);
virtual bool isZero() const;
virtual void str2bigNumber(const string str);
virtual string toString() const;
virtual void print(ostream &os) const;
virtual void read(istream &is);
void simplify();
list<unsigned short int> getNumerator() const;
list<unsigned short int> getDenominator() const;
friend bool operator==(const BigRational& a, const BigRational& b);
friend int compare(const BigRational& a, const BigRational& b);
friend BigRational operator+(const BigRational& a, const BigRational& b);
friend BigRational operator-(const BigRational& a, const BigRational& b);
friend BigRational operator*(const BigRational& a, const BigRational& b);
friend BigRational operator/(const BigRational& a, const BigRational& b);
// Helper functions
friend list<USI> listMultiply(const list<USI>& a, const list<USI>& b);
friend void listAddTo(list<USI>& a, const list<USI>& b);
friend int listCompare(const BNL& a, const BNL& b);
friend void listMinus(BNL& a, const BNL& b);
friend BNL listDivide(const BNL& a, const BNL& b);
friend BNL listMod(const BNL& a, const BNL& b);
friend BNL listGCD(const BNL& a, const BNL& b);
};
bool operator==(const BigRational& a, const BigRational& b);
int compare(const BigRational& a, const BigRational& b);
BigRational operator+(const BigRational& a, const BigRational& b);
BigRational operator-(const BigRational& a, const BigRational& b);
BigRational operator*(const BigRational& a, const BigRational& b);
BigRational operator/(const BigRational& a, const BigRational& b);
list<USI> listMultiply(const list<USI>& a, const list<USI>& b); // Help in mutiply
void listAddTo(list<USI>& a, const list<USI>& b);
int listCompare(const BNL& a, const BNL& b);
void listMinus(BNL& a, const BNL& b);
BNL listDivide(const BNL& a, const BNL& b);
BNL listMod(const BNL& a, const BNL& b);
BNL listGCD(const BNL& a, const BNL& b);
#endif /* BIGRATIONAL_H_ */