Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Это заголовочный фаил "big_integer.h"
- * Тут не должно быть определений
- */
- #ifndef __BIG_INTEGER_H__
- #define __BIG_INTEGER_H__
- #include <iostream>
- #include <cstdint>
- typedef std::uint64_t base_t; // определение типа данных под цифру ("uint64_t" is "alias unsigned long long int")
- const base_t BASE = 1000000000; // основание СС (0 <= цифра <= BASE-1)
- class big_integer_t {
- private:
- base_t* data; // для динамического выделения памяти под массив цифр
- base_t size; // размер выделенной памяти
- bool is_negative; // для определения знака (is_negtive = value < 0)
- public:
- big_integer_t(const std::int64_t& value = 0); //конструктор для выражений типа big_integer_t a, b(), c(2), d = -4;
- big_integer_t(const big_integer_t& other); //конструктор для выражений типа big_integer_t e(a), c = b;
- //а также для передачи аргументов и результата функции
- ~big_integer_t(); //деструктор для очищения выделенной памяти
- big_integer_t& operator= (const big_integer_t& other); // для выражений типа b = a, c = a + 3, d = c % a--;
- big_integer_t& operator+= (const big_integer_t& other); // для выражений типа b += a, c += a - 3, d += c % ++a;
- big_integer_t& operator-= (const big_integer_t& other); // для выражений типа b -= a, c -= a + 3, d -= c % a--;
- big_integer_t& operator*= (const big_integer_t& other); // для выражений типа b *= a, c *= a + 3, d *= c % a--;
- big_integer_t& operator*= (const std::int64_t& value); // для выражений типа b *= i, c *= j + 3, d *= i % j--;
- big_integer_t& operator/= (const std::int64_t& value); // для выражений типа b /= i, c /= j + 3, d /= i % j--;
- big_integer_t& operator%= (const std::int64_t& value); // для выражений типа b %= i, c %= j + 3, d %= i % j--;
- //не забывай высвобождать излишки памяти
- //следущие операторы будут возвращать не ссылки а новые объекты
- friend big_integer_t operator + (const big_integer_t& obj1, const big_integer_t& obj2); // бинарный (big_integer_t)+(big_integer_t)
- friend big_integer_t operator - (const big_integer_t& obj1, const big_integer_t& obj2); // бинарный (big_integer_t)-(big_integer_t)
- friend big_integer_t operator * (const big_integer_t& obj1, const big_integer_t& obj2); // бинарный (big_integer_t)*(big_integer_t)
- friend big_integer_t operator * (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)*(long long)
- friend big_integer_t operator * (const std::int64_t& value, const big_integer_t& obj2); // бинарный (long long)*(big_integer_t)
- friend big_integer_t operator / (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)/(long long)
- friend big_integer_t operator % (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)%(long long)
- //операторы сравнения
- friend bool operator == (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)==(big_integer_t)
- friend bool operator != (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)!=(big_integer_t)
- friend bool operator >= (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)>=(big_integer_t)
- friend bool operator > (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)>(big_integer_t)
- friend bool operator <= (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)<=(big_integer_t)
- friend bool operator < (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)<(big_integer_t)
- //унарные операторы
- friend big_integer_t operator + (const big_integer_t& obj); // унарный +(big_integer_t)
- friend big_integer_t operator ++ (const big_integer_t& obj); // унарный ++(big_integer_t)
- friend big_integer_t operator ++ (const big_integer_t& obj, int); // унарный (big_integer_t)++
- friend big_integer_t operator - (const big_integer_t& obj); // унарный -(big_integer_t)
- friend big_integer_t operator -- (const big_integer_t& obj); // унарный --(big_integer_t)
- friend big_integer_t operator -- (const big_integer_t& obj, int); // унарный (big_integer_t)--
- friend std::istream & operator >>(std::istream &, const big_integer_t& obj); // чтение из std::istream
- friend std::ostream & operator <<(std::ostream &, const big_integer_t& obj); // запись в std::ostream
- };
- // Катя, удачи)
- #endif //__BIG_INTEGER_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement