thevals

rub2

May 13th, 2022 (edited)
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. DecStr operator + (const DecStr& pobj1, const int pobj2)
  2. {
  3.     int num1, num2;
  4.     DecStr tmp(pobj1);
  5.     num1 = atoi(tmp.GetStr());
  6.     num2 = pobj2;
  7.     long long int A = long long(num1) + num2;
  8.     if (A < -2147483648 || A > 2147483647) {
  9.     delete[] tmp.pCh;
  10.     tmp.len = 0;
  11.     tmp.pCh = new char[tmp.len + 1];
  12.     tmp.pCh[0] = '\0';
  13.     } else {
  14.     char* pTmpCh;
  15.     int LenPobj2 = 0;
  16.     int Pobj2_2 = pobj2;
  17.     while (Pobj2_2 % 10 != 0)
  18.     {
  19.         Pobj2_2 = Pobj2_2 / 10;
  20.         LenPobj2++;
  21.     }
  22.     if (tmp.len >= LenPobj2)
  23.     {
  24.         pTmpCh = new char[tmp.len + 2];
  25.         _itoa_s(A, pTmpCh, tmp.len + 2, 10);
  26.     }
  27.     else
  28.     {
  29.         pTmpCh = new char[LenPobj2 + 2];
  30.         _itoa_s(A, pTmpCh, LenPobj2 + 2, 10);
  31.     }
  32.     if (tmp.pCh) delete[] tmp.pCh;
  33.     tmp.pCh = pTmpCh;
  34.     tmp.len = strlen(tmp.pCh);
  35. }
  36.     return tmp;
  37. }
Add Comment
Please, Sign In to add comment