-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfInt.h
More file actions
180 lines (113 loc) · 3.7 KB
/
Copy pathInfInt.h
File metadata and controls
180 lines (113 loc) · 3.7 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
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
//
// Created by Eldar on 06-Nov-18.
//
#ifndef EX01_INFINT_H
#include "Decimal.h"
#include "Binary.h"
#include <iostream>
#define EX01_INFINT_H
using namespace std;
/**
* Class for InfInt.
*/
class InfInt {
private:
/**
* Inner class for Mydata
*/
class MyData {
public:
// Public members for class Infint
Decimal decimal;
Binary binary;
int counter = 1;
// Default constructor
MyData() {};
// Func increament
void increament() {
this->counter++;
}
// Fun decrement
void decrement() {
this->counter--;
}
/**
* Deep Cloning of mydata, creating all new members.
* @return deep clone of mydata
*/
MyData deepClone() {
MyData *tempMyData = new MyData();
tempMyData->decimal = this->decimal.deepClone();
tempMyData->binary = this->binary.deepClone();
return *tempMyData;
}
};
// Member in Infint class
MyData *data;// = new MyData();
public:
// Destructor to delete allocated memory
~InfInt() {
if (this->getCount() == 1) {
delete (data);
// Decrease by 1
} else {
this->data->decrement();
}
}
//The constructors:
//For pointer of chars
InfInt(const char num[]);
// Copy constructors
InfInt(const InfInt &number);
// Default (empty) constructor
InfInt();
// Constructor for regular int
InfInt(int num);
// Constructor for long int
InfInt(long int num);
InfInt(string num);
operator int() const;
//All the operators
InfInt operator+(const InfInt &number) const;
InfInt &operator+=(const InfInt &number);
InfInt &operator-=(const InfInt &number);
InfInt &operator*=(const InfInt &number);
InfInt operator-(const InfInt &number) const;
InfInt operator*(const InfInt &number) const;
InfInt operator/(const InfInt &number) const;
InfInt operator%(const InfInt &number) const;
InfInt operator&(const InfInt &number) const;
InfInt operator^(const InfInt &number) const;
InfInt operator|(const InfInt &number) const;
bool operator>(const InfInt &number) const;
bool operator>=(const InfInt &number) const;
bool operator<(const InfInt &number) const;
bool operator<=(const InfInt &number) const;
bool operator==(const InfInt &number) const;
InfInt operator<<(const int number) const;
InfInt operator>>(const int number) const;
InfInt &operator=(const InfInt &other);
InfInt &operator>>=(const int number);
InfInt &operator&=(const InfInt &number);
InfInt &operator++();
InfInt operator++(int);
InfInt &operator--();
InfInt operator--(int);
// Operator for stream - in and out
friend ostream &operator<<(ostream &os, const InfInt &inf);
friend istream &operator>>(istream &input, InfInt &d);
// Functions for conversion between decimaly to binary and vice versa
string fromDecimalToBinary(string number) const;
string fromBinaryToDecimal(string number) const;
// Convert to negative binary
void negativeBinary(string &number) const;
// Getters and Setters for all members
Decimal getDecimal() const;
void setDecimal(const string string1);
void setBinary(const string string1);
int getCount() const;
Binary getBinary() const;
// Deep copy for reference counting
InfInt deepCopy() const;
};
#endif //EX01_INFINT_H