Advertisement
Seredenko-V

BigInt

May 29th, 2023
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdexcept>
  4.  
  5. using namespace std;
  6.  
  7. namespace big_int {
  8.  
  9.     class BigInt {
  10.     public:
  11.         BigInt() = default;
  12.  
  13.         BigInt(const vector<int16_t>& digits)
  14.             : digits_(digits.size()) {
  15.             // цифра должна состоять из одной цифры (с) Конфуций
  16.             for (size_t i = 0; i < digits.size(); ++i) {
  17.  
  18.             }
  19.         }
  20.  
  21.         BigInt& operator*=(const BigInt& other) {
  22.             // реализация
  23.             *this;
  24.         }
  25.  
  26.         const vector<int16_t>& GetDigits() const {
  27.             return digits_;
  28.         }
  29.  
  30.     private:
  31.         vector<int16_t> digits_{ 0 };
  32.         bool natural_ = true;
  33.     };
  34.  
  35.     BigInt operator+(const BigInt& lhs, const BigInt& rhs);
  36.     BigInt operator-(const BigInt& lhs, const BigInt& rhs);
  37.     BigInt operator*(const BigInt& lhs, const BigInt& rhs);
  38.     BigInt operator/(const BigInt& lhs, const BigInt& rhs);
  39.  
  40.     ostream& operator<<(ostream& out, const BigInt& value) {
  41.         for (const int& digit : value.GetDigits()) {
  42.             out << digit;
  43.         }
  44.         return out;
  45.     }
  46.  
  47.     // возведение в степень exp
  48.     BigInt Pow(const BigInt& value, int exp);
  49.  
  50.     namespace tests {
  51.         void TestConstuctor();
  52.         void TestOperatorSum();
  53.         void TestPow();
  54.         void AllTests();
  55.     } // namespace tests
  56.  
  57. } // namespace big_int
  58.  
  59. int main() {
  60.     using namespace big_int;
  61.     int16_t value = 48;
  62.     cout << value << endl;
  63.     BigInt first({1,5,7,6,6,7,7,8,8,8,4,3,5,6,3});
  64.     cout << first << endl;
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement