-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargenum.h
More file actions
85 lines (61 loc) · 2.21 KB
/
Copy pathlargenum.h
File metadata and controls
85 lines (61 loc) · 2.21 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <vector>
using namespace std;
class LargeNum {
// output number with a comma after ever 3 digits,
// e.g. 1234567890 -> 1,234,567,890
friend ostream &operator<<(ostream &out, const LargeNum &num);
private:
// Define private data members and methods here
string num;
bool isPositive = true;
public:
// default constructor from string
explicit LargeNum(const string &str = "0");
// constructor from int
explicit LargeNum(int anInteger);
// use the default copy constructor
LargeNum(const LargeNum &other) = default;
// use the default copy assignment operator
LargeNum &operator=(const LargeNum &other) = default;
// use the default destructor
~LargeNum() = default;
// returns true if the number is zero
bool isZero() const;
// negate the number, positive becomes negative, negative becomes positive
// Zero is always positive
LargeNum &negate();
// add two numbers
LargeNum operator+(const LargeNum &rhs) const;
// subtract two numbers
LargeNum operator-(const LargeNum &rhs) const;
// multiply two numbers
LargeNum operator*(const LargeNum &rhs) const;
// divide two numbers. rhs is the divisor
// similar to integer division, ignore remainder
LargeNum operator/(const LargeNum &rhs) const;
// return true if the numbers are equal
bool operator==(const LargeNum &rhs) const;
// return true if the numbers are not equal
bool operator!=(const LargeNum &rhs) const;
// return true if the left-hand-side number is greater than the
// right-hand-side number
bool operator<(const LargeNum &rhs) const;
// return true if the left-hand-side number is less than or equal to the
// right-hand-side number
bool operator>(const LargeNum &rhs) const;
// return true if the left-hand-side number is less than the right-hand-side
// number
bool operator<=(const LargeNum &rhs) const;
// return true if the left-hand-side number is greater than or equal to the
// right-hand-side number
bool operator>=(const LargeNum &rhs) const;
// prefix increment
LargeNum &operator++();
// postfix increment
LargeNum operator++(int);
// prefix decrement
LargeNum &operator--();
// postfix decrement
LargeNum operator--(int);
};