-
Notifications
You must be signed in to change notification settings - Fork 0
/
double class.cpp
203 lines (153 loc) · 4.33 KB
/
double class.cpp
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
#include <math.h>
#include <stdio.h>
#include <iostream>
int g_count = 0;
int g_maxcount = 0;
class number
{
private:
double num;
public:
number& operator++();
number& operator--();
number operator+ (const number& sec);
number operator- (const number& sec);
number operator* (const number& sec);
number operator/ (const number& sec);
number& operator+= (const number& sec);
number& operator-= (const number& sec);
number& operator*= (const number& sec);
number& operator/= (const number& sec);
number& operator= (const number& sec);
bool operator< (const number& sec);
bool operator<= (const number& sec);
bool operator> (const number& sec);
bool operator>= (const number& sec);
bool operator== (const number& sec);
bool operator!= (const number& sec);
number (double a) : num (a)
{
printf ("%p \n %s", this, "áûë âûçâàí êîíñòðóêòîð ñ ïàðàìåòðîì \n");
g_count++;
}
number() : num (0)
{
printf ("%p \n %s", this, "áûë âûçâàí áàçîâûé êîíñòðóêòîð \n");
g_count++;
}
number (const number& sec) : num (sec.num)
{
printf ("%p \n %s", this, "áûë âûçâàí êîíñòðóêòîð êîïèðîâàíèÿ \n");
g_count++;
}
~ number()
{
printf ("%p \n %s", this, "áûë âûçâàí äåñòðóêòîð \n");
if (g_count > g_maxcount)
{
g_maxcount = g_count;
}
g_count--;
}
};
number number::operator+ (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñëîæåíèÿ äëÿ îáúåêòà êëàññà \n");
return number (num + sec.num);
}
number number::operator- (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð âû÷èòàíèÿ äëÿ îáúåêòà êëàññà \n");
return number (num - sec.num);
}
number number::operator* (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð óìíîæåíèÿ äëÿ îáúåêòà êëàññà \n");
return number (num * sec.num);
}
number number::operator/ (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð äåëåíèÿ äëÿ îáúåêòà êëàññà \n");
return number (num + sec.num);
}
number& number::operator+= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñëîæåíèÿ-ðàâíî äëÿ îáúåêòà êëàññà \n");
(*this).num = sec.num + (*this).num;
return *this;
}
number& number::operator-= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð âû÷èòàíèÿ-ðàâíî äëÿ îáúåêòà êëàññà \n");
(*this).num = sec.num + (*this).num;
return *this;
}
number& number::operator*= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð óìíîæåíèÿ-ðàâíî äëÿ îáúåêòà êëàññà \n");
(*this).num = sec.num + (*this).num;
return *this;
}
number& number::operator/= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð äåëåíèÿ-ðàâíî äëÿ îáúåêòà êëàññà \n");
(*this).num = sec.num + (*this).num;
return *this;
}
number& number::operator++ ()
{
printf ("%s", "áûë âûçâàí îïåðàòîð èíêðåìåíò äëÿ îáúåêòà êëàññà \n");
(*this).num++;
return *this;
}
number& number::operator-- ()
{
printf ("%s", "áûë âûçâàí îïåðàòîð äåêðåìåíò äëÿ îáúåêòà êëàññà \n");
(*this).num--;
return *this;
}
number& number::operator= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ïðèñâàèâàíèÿ äëÿ îáúåêòà êëàññà \n");
(*this).num = sec.num;
return *this;
}
bool number:: operator< (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñðàâíåíèÿ < äëÿ îáúåêòà êëàññà \n");
return (num < sec.num);
}
bool number:: operator> (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñðàâíåíèÿ > äëÿ îáúåêòà êëàññà \n");
return (num > sec.num);
}
bool number:: operator>= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñðàâíåíèÿ >= äëÿ îáúåêòà êëàññà \n");
return (num >= sec.num);
}
bool number:: operator<= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñðàâíåíèÿ <= äëÿ îáúåêòà êëàññà \n");
return (num <= sec.num);
}
bool number:: operator== (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñðàâíåíèÿ == äëÿ îáúåêòà êëàññà \n");
return (num == sec.num);
}
bool number:: operator!= (const number& sec)
{
printf ("%s", "áûë âûçâàí îïåðàòîð ñðàâíåíèÿ != äëÿ îáúåêòà êëàññà \n");
return (num != sec.num);
}
int main()
{
setlocale(LC_ALL, "Russian");
number a;
number b = a + 3;
number c = a / b + 8.5;
printf ("%d \n%d \n", g_count, g_maxcount);
return 0;
}