Skip to content

Commit 6b0fdf7

Browse files
committed
all tasks is ready
1 parent 0662a27 commit 6b0fdf7

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

HugeInt.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
using namespace std;
33

44
HugeInt::HugeInt() {
5-
for (int i = 0; i < 41; i++) {
5+
for (int i = 0; i < 40; i++) {
66
number[i] = 0;
77
}
88
depth = 0;
99
negative = false;
1010
}
1111

1212
HugeInt::HugeInt(int d) {
13-
for (int i = 0; i < 41; i++) {
13+
for (int i = 0; i < 40; i++) {
1414
number[i] = 0;
1515
}
1616
depth = d;
@@ -71,6 +71,8 @@ bool HugeInt::check_zero() const {
7171
return true;
7272
}
7373

74+
// геттеры и сеттеры
75+
7476
void HugeInt::set_minus(bool state) {
7577
negative = state;
7678
}
@@ -256,4 +258,25 @@ HugeInt HugeInt::operator-() const {
256258
HugeInt temp(*this);
257259
temp.negative = !temp.negative;
258260
return temp;
261+
}
262+
263+
void HugeInt::shrink_to_fit() {
264+
for (int i = 39; i > -1; i--) {
265+
if (number[i] != 0) {
266+
depth = i + 1;
267+
break;
268+
}
269+
}
270+
}
271+
272+
void HugeInt::print_full() {
273+
if (negative) cout << "-";
274+
for (int i = 39; i > -1; cout << number[i--]);
275+
cout << endl;
276+
}
277+
278+
void HugeInt::print() {
279+
if (negative) cout << "-";
280+
for (int i = depth - 1; i > -1; cout << number[i--]);
281+
cout << endl;
259282
}

HugeInt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class HugeInt {
3636

3737
// операторы
3838
HugeInt operator-() const;
39+
40+
void shrink_to_fit();
41+
void print_full(); // print для теста
42+
void print(); // print для теста
3943
};
4044

4145
#endif

L12_6.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//* менять знак числа
1111
//* узнавать позицию на разряде
1212
//* менять позицию на разряде
13-
// урезать размер числа, чтобы не было нулей
13+
//* урезать размер числа, чтобы не было нулей
1414
//? ДОП:
1515
// перегрузка операторов
1616
// умножение
@@ -23,9 +23,13 @@ int main() {
2323
HugeInt a;
2424
HugeInt b;
2525
HugeInt s;
26+
a.print_full();
27+
a.print();
2628

2729
a.set("1000");
2830
b.set("7");
31+
a.print_full();
32+
a.print();
2933

3034
if (a.check_zero()) {
3135
cout << a.get() << " - its zero " << endl;
@@ -49,12 +53,18 @@ int main() {
4953

5054
s = a.dif(b);
5155
cout << "Difference = " << s.get() << endl;
56+
s.print_full();
57+
s.print();
58+
s.shrink_to_fit();
59+
s.print();
5260

5361
s = a.sum(b);
5462
cout << "Summ = " << s.get() << endl;
5563

5664
s = -s;
57-
cout << s.get();
65+
cout << s.get() << endl;
66+
s.shrink_to_fit();
67+
s.print();
5868

5969
return 0;
6070
}

0 commit comments

Comments
 (0)