-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapn.h
204 lines (141 loc) · 4.95 KB
/
apn.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <iostream>
using namespace std;
class APN {
private:
// digit or floating point node
class DigitNode {
public:
int data;
bool isFloatPoint;
DigitNode* next;
DigitNode* prev;
};
// positions for the most important positions in the number
DigitNode* head;
DigitNode* tail;
DigitNode* floatPointNd;
// whether the number is negative or not
bool isNegative;
// to make sure that the last digit, in either before or after the float point, is rather changed to 0 than delete it
// i.e. the minimum number of nodes are the nodes representing the number 0.0 (three nodes)
bool firstInsertAfterFloat;
bool firstInsertBeforeFloat;
// general insertion function
DigitNode* insertDigitHelper(DigitNode* nd, int digit, bool insertAfter, bool isFloatPoint);
// general deletion function
DigitNode* deleteDigitHelper(DigitNode* nd, bool getAfter);
// insert at front (head) helper
DigitNode* appendFrontHelper(int digit, bool isFloatPoint);
// insert at back (tail) helper
DigitNode* appendBackHelper(int digit, bool isFloatPoint);
// delete at front (head) helper
DigitNode* deleteFrontHelper(bool getNodeAfter);
// delete at back (tail) helper
DigitNode* deleteBackHelper(bool getNodeAfter);
// return all digits == 0
bool isAllZeros(APN& num);
// the most simple multiplication ever, which is adding this's initial number "num" times
void simpleMultiplication(APN& num);
// remove the first digit and round
void round(APN& num);
public:
// just like dividing by 10
void moveFloatingPointUp();
// just like multiplying by 10
void moveFloatingPointDown();
// default constructor - set to 0.0
APN();
// deep copy constructor
APN(APN& num);
// parametrized constructor - string to APN converter
APN(string strNum);
// destructor - deletes every node
~APN();
// number of nodes before the floating point (integer part)
APN frontSize();
// number of nodes after the floating point (decimal part)
APN backSize();
// frontSize + backSize
APN numSize();
// get nd->next
DigitNode* getNext(DigitNode* nd);
// get nd->prev
DigitNode* getPrev(DigitNode* nd);
// insert at front (head)
bool appendFront(int digit);
// insert at back (tail)
bool appendBack(int digit);
// delete at front (head)
void deleteFront();
// delete at back (tail)
void deleteBack();
// return this == num
bool equalTo(APN& num);
// return this < num
bool lessThan(APN& num);
// return this > num
bool greaterThan(APN& num);
// return this <= num
bool lessThanOrEqualTo(APN& num);
// return this >= num
bool greaterThanOrEqualTo(APN& num);
// this = this + num
void add(APN& num);
// this = this - num
void subtract(APN& num);
// this = this * num
void multiply(APN& num);
// this = this / num with some percision passed in as argument
bool divide(APN& num, APN& percision);
// similar to divide, but it will return the reminder rather than the quotient
bool divideRemainder(APN& num, APN& percision);
// cout the current number without '\n' at the end
void printNum();
// get front position
DigitNode* getHeadPtr();
// get back position
DigitNode* getTailPtr();
// get float point position
DigitNode* getFloatPointPtr();
// return num < 0
bool isNegativeNum();
// set to 0.0 with positive sign
void removeAll();
// change sign
void setToNegative(bool isNegativeChange);
// assignment function for deep copy
APN& assign(APN& num);
// making two digits have the same number of nodes by adding 0's after (for front insertion) or before (for back insertion)
// for the number, either this or num, that require them
// i.e. this = 90.687, num = 8989.3 will be this = 0090.687, num = 8989.300
// needed for functions such as subtract
void fixDigitsTo(APN& num);
// remove unnecessary 0's, at front or back, that will not change the meaning of the number
void shrink();
// assignment operator for deep copy
APN& operator=(APN& num);
// assignment operator for string to APN conversion
APN& operator=(string strNum);
// less than operator
bool operator<(APN& num);
// greater than operator
bool operator>(APN& num);
// less than or equal to operator
bool operator<=(APN& num);
// greater than or equal to operator
bool operator>=(APN& num);
// equal to operator
bool operator==(APN& num);
// increment operator
APN& operator++();
// decrement operator
APN& operator--();
// multiplication operator
APN& operator*(APN& num);
// division operator with percision of 50
APN& operator/(APN& num);
// addition operator
APN& operator+(APN& num);
// subtraction operator
APN& operator-(APN& num);
};