Advertisement
Guest User

Длинная арифметика ? страдания : крепкий сон;

a guest
Nov 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.00 KB | None | 0 0
  1. /*
  2. *   Это заголовочный фаил "big_integer.h"
  3. *   Тут не должно быть определений
  4. */
  5.  
  6. #ifndef __BIG_INTEGER_H__
  7. #define __BIG_INTEGER_H__
  8.  
  9. #include <iostream>
  10. #include <cstdint>
  11.  
  12. typedef std::uint64_t base_t; // определение типа данных под цифру ("uint64_t" is "alias unsigned long long int")
  13. const base_t BASE = 1000000000; //  основание СС (0 <= цифра <= BASE-1)
  14.  
  15. class big_integer_t {
  16. private:
  17.     base_t* data; // для динамического выделения памяти под массив цифр
  18.     base_t size; // размер выделенной памяти
  19.     bool is_negative; // для определения знака (is_negtive = value < 0)
  20. public:
  21.     big_integer_t(const std::int64_t& value = 0); //конструктор для выражений типа big_integer_t a, b(), c(2), d = -4;
  22.     big_integer_t(const big_integer_t& other);  //конструктор для выражений типа big_integer_t e(a), c = b;
  23.                                                 //а также для передачи аргументов и результата функции
  24.     ~big_integer_t(); //деструктор для очищения выделенной памяти
  25.  
  26.     big_integer_t& operator= (const big_integer_t& other); // для выражений типа b = a, c = a + 3, d = c % a--;
  27.     big_integer_t& operator+= (const big_integer_t& other); // для выражений типа b += a, c += a - 3, d += c % ++a;
  28.     big_integer_t& operator-= (const big_integer_t& other); // для выражений типа b -= a, c -= a + 3, d -= c % a--;
  29.     big_integer_t& operator*= (const big_integer_t& other); // для выражений типа b *= a, c *= a + 3, d *= c % a--;
  30.     big_integer_t& operator*= (const std::int64_t& value); // для выражений типа b *= i, c *= j + 3, d *= i % j--;
  31.     big_integer_t& operator/= (const std::int64_t& value); // для выражений типа b /= i, c /= j + 3, d /= i % j--;
  32.     big_integer_t& operator%= (const std::int64_t& value); // для выражений типа b %= i, c %= j + 3, d %= i % j--;
  33.     //не забывай высвобождать излишки памяти
  34.  
  35.     //следущие операторы будут возвращать не ссылки а новые объекты
  36.     friend big_integer_t operator + (const big_integer_t& obj1, const big_integer_t& obj2); // бинарный (big_integer_t)+(big_integer_t)
  37.     friend big_integer_t operator - (const big_integer_t& obj1, const big_integer_t& obj2); // бинарный (big_integer_t)-(big_integer_t)
  38.     friend big_integer_t operator * (const big_integer_t& obj1, const big_integer_t& obj2); // бинарный (big_integer_t)*(big_integer_t)
  39.     friend big_integer_t operator * (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)*(long long)
  40.     friend big_integer_t operator * (const std::int64_t& value, const big_integer_t& obj2); // бинарный (long long)*(big_integer_t)
  41.     friend big_integer_t operator / (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)/(long long)
  42.     friend big_integer_t operator % (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)%(long long)
  43.  
  44.     //операторы сравнения
  45.     friend bool operator == (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)==(big_integer_t)
  46.     friend bool operator != (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)!=(big_integer_t)
  47.     friend bool operator >= (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)>=(big_integer_t)
  48.     friend bool operator > (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)>(big_integer_t)
  49.     friend bool operator <= (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)<=(big_integer_t)
  50.     friend bool operator < (const big_integer_t& obj1, const std::int64_t& value); // бинарный (big_integer_t)<(big_integer_t)
  51.  
  52.     //унарные операторы
  53.     friend big_integer_t operator + (const big_integer_t& obj); // унарный +(big_integer_t)
  54.     friend big_integer_t operator ++ (const big_integer_t& obj); // унарный ++(big_integer_t)
  55.     friend big_integer_t operator ++ (const big_integer_t& obj, int); // унарный (big_integer_t)++
  56.     friend big_integer_t operator - (const big_integer_t& obj); // унарный -(big_integer_t)
  57.     friend big_integer_t operator -- (const big_integer_t& obj); // унарный --(big_integer_t)
  58.     friend big_integer_t operator -- (const big_integer_t& obj, int); // унарный (big_integer_t)--
  59.  
  60.     friend std::istream & operator >>(std::istream &, const big_integer_t& obj); // чтение из std::istream
  61.     friend std::ostream & operator <<(std::ostream &, const big_integer_t& obj); // запись в std::ostream
  62. };
  63.  
  64. // Катя, удачи)
  65. #endif //__BIG_INTEGER_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement