Advertisement
thevals

123445

May 13th, 2022
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. DecStr operator+(const DecStr& ob1, const int ob2)
  2. {
  3. DecStr tmp(ob1);
  4. int n1 = atoi(tmp.GetStr()), n2 = ob2;
  5. long long int A = long long int(n1) + n2;
  6. if (A < -2147483648 || A > 2147483647) {
  7. delete[] tmp.pCh;
  8. tmp.len = 0;
  9. tmp.pCh = new char[tmp.len + 1];
  10. tmp.pCh[0] = '\0';
  11. }
  12. else {
  13. char* tmpCh;
  14. int len2 = 0, tmpn = ob2;
  15. while (tmpn > 0) {
  16. len2++;
  17. tmpn /= 10;
  18. }
  19. if (tmp.len < len2) tmp.len = len2;
  20. tmpCh = new char[tmp.len + 2];
  21. _itoa_s(A, tmpCh, tmp.len + 2, 10);
  22. if (tmp.pCh) delete[] tmp.pCh;
  23. tmp.pCh = tmpCh;
  24. tmp.len = strlen(tmp.pCh);
  25. }
  26. cout << "DecStr operator+(const DecStr& ob1, const int ob2)" << endl;
  27. return tmp;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement