-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.h
137 lines (87 loc) · 2.77 KB
/
lint.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
#ifndef LINT
#define LINT
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
namespace apa
{
using namespace std;
template <typename T>
class ComparisonOperators
{
friend bool operator==(T const& lhs, T const& rhs)
{
return lhs.compare(rhs) == 0;
}
friend bool operator!=(T const& lhs, T const& rhs)
{
return lhs.compare(rhs) != 0;
}
friend bool operator<(T const& lhs, T const& rhs)
{
return lhs.compare(rhs) < 0;
}
friend bool operator>(T const& lhs, T const& rhs)
{
return rhs.compare(lhs) < 0;
}
friend bool operator<=(T const& lhs, T const& rhs)
{
bool result = lhs.compare(rhs) <= 0;
return result;
}
friend bool operator>=(T const& lhs, T const& rhs)
{
return rhs.compare(lhs) <= 0;
}
};
class lint : ComparisonOperators<lint>
{
public:
explicit lint(std::string number);
lint();
lint(long long number);
lint(int number);
lint(double number);
lint(vector<int> nums, bool is_neg);
lint(const lint &obj);
int get_length() const;
bool is_negative_number() const;
lint& operator+=(const lint& b);
lint& operator-=(const lint& b);
lint& operator*=(const lint& number2);
lint& operator/=(const lint& b);
explicit operator bool() const;
explicit operator int();
lint operator+() const;
lint operator-() const;
int operator[](size_t index) const;
lint& operator=(const lint& other);
lint& operator++();
lint operator++(int);
lint& operator--();
lint operator--(int);
bool cmp(lint const& rhs) const;
int compare(lint const& rhs) const;
bool is_zero() const;
std::string to_string();
private:
bool is_negative;
vector<int> numbers;
lint abs(lint number) const;
vector<int> reverse_numbers(vector<int> const& numbers) const;
void make_equal_length(const lint& b, vector<int> & number1, vector<int> & number2) const;
void string_to_vector(std::string const& number);
void integer_to_vector(long long a);
};
lint abs(lint number);
lint pow(lint a, int n);
std::ostream& operator<<(std::ostream& os, const lint& obj);
std::istream& operator>>(std::istream& is, lint& obj);
lint operator+(const lint& lhs, const lint& rhs);
lint operator-(const lint& lhs, const lint& rhs);
lint operator*(const lint& lhs, const lint& rhs);
lint operator/(const lint& lhs, const lint& rhs);
}
#endif /* LINT */