File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -291,6 +291,18 @@ void HugeInt::shrink_to_fit() {
291291 }
292292}
293293
294+ std::ostream& operator <<(std::ostream &out, const HugeInt &n) {
295+ out << n.get ();
296+ return out;
297+ }
298+
299+ std::istream& operator >>(std::istream &in, HugeInt &n) {
300+ string temp;
301+ in >> temp;
302+ n.set (temp);
303+ return in;
304+ }
305+
294306void HugeInt::print_full () {
295307 if (negative) cout << " -" ;
296308 for (int i = 39 ; i > -1 ; cout << number[i--]);
Original file line number Diff line number Diff line change @@ -47,9 +47,12 @@ class HugeInt {
4747 HugeInt operator -() const ;
4848
4949 void shrink_to_fit (); // обрезаем ненужные нули
50-
51- void print_full (); // print для теста
52- void print (); // print для теста
50+
51+ friend std::ostream& operator <<(std::ostream &out, const HugeInt &n);
52+ friend std::istream& operator >>(std::istream &in, HugeInt &n);
53+ // ? тест
54+ void print_full (); // ? print для теста
55+ void print (); // ? print для теста
5356};
5457
5558#endif
Original file line number Diff line number Diff line change 1414// ? ДОП:
1515// перегрузка операторов
1616// * - операторы сравнения
17+ // * - операторы вывода на экран
1718// - математические операторы
1819// умножение
1920// нахождение остатка от деления
2223using namespace std ;
2324
2425int main () {
25- HugeInt a;
26- HugeInt b;
27- HugeInt s;
26+ HugeInt a, b, s;
2827 a.print_full ();
2928 a.print ();
3029
@@ -34,37 +33,37 @@ int main() {
3433 a.print ();
3534
3635 if (a.check_zero ()) {
37- cout << a. get () << " - its zero " << endl;
36+ cout << a << " - its zero " << endl;
3837 } else {
39- cout << a. get () << " - not zero " << endl;
38+ cout << a << " - not zero " << endl;
4039 }
4140
4241 if (b.check_zero ()) {
43- cout << b. get () << " - its zero " << endl;
42+ cout << b << " - its zero " << endl;
4443 } else {
45- cout << b. get () << " - not zero " << endl;
44+ cout << b << " - not zero " << endl;
4645 }
4746
4847 if (a > b) {
49- cout << a. get () << " > " << b. get () << endl;
48+ cout << a << " > " << b << endl;
5049 } else if (a < b) {
51- cout << a. get () << " < " << b. get () << endl;
50+ cout << a << " < " << b << endl;
5251 } else if (a == b) {
53- cout << a. get () << " = " << b. get () << endl;
52+ cout << a << " = " << b << endl;
5453 }
5554
5655 s = a.dif (b);
57- cout << " Difference = " << s. get () << endl;
56+ cout << " Difference = " << s << endl;
5857 s.print_full ();
5958 s.print ();
6059 s.shrink_to_fit ();
6160 s.print ();
6261
6362 s = a.sum (b);
64- cout << " Summ = " << s. get () << endl;
63+ cout << " Summ = " << s << endl;
6564
6665 s = -s;
67- cout << s. get () << endl;
66+ cout << s << endl;
6867 s.shrink_to_fit ();
6968 s.print ();
7069
You can’t perform that action at this time.
0 commit comments