Rockman_Z

Untitled

Feb 20th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class superlong
  6. {
  7. private:
  8.     int arrayLength;
  9. public:
  10.     /*extern*/ int intArray[1000];
  11.     superlong() { for (int i = 0; i < 1001; i++) intArray[i] = 0;}
  12.  
  13.     void get();
  14.     void get(string s);
  15.     void give();
  16.     void give(string& s);
  17.     int length();
  18.     superlong operator+(superlong op2);
  19.  
  20. };
  21.  
  22.  
  23. int main()
  24. {
  25.     superlong new2, new1, new3;
  26.     new1.get();
  27.     new2.get();
  28.     cout << new1.length();
  29.     new3 = new1 + new2;
  30.     //new3.give();
  31.     return 0;
  32. }
  33.  
  34. void superlong::get()
  35. {
  36.     string s = "";
  37.     cin >> s;
  38. //    int intArray[s.length()];
  39.     for (int i = 0; i < s.length(); i++)
  40.     {
  41.         intArray[i] = s[s.length() - i - 1] - '0';
  42.     }
  43.     arrayLength = s.length();
  44. }
  45.  
  46. void superlong::get(string s)
  47. {
  48. //    int intArray[s.length()];
  49.     for (int i = 0; i < s.length(); i++)
  50.     {
  51.         intArray[i] = s[s.length() - i - 1] - '0';
  52.     }
  53.     arrayLength = s.length();
  54. }
  55.  
  56. void superlong::give()
  57. {
  58.     for (int i = arrayLength - 1; i >= 0; i--)
  59.         cout << intArray[i];
  60. }
  61.  
  62. void superlong::give(string& s)
  63. {
  64.     for (int i = arrayLength - 1; i >= 0; i--)
  65.         s += intArray[i];
  66. }
  67.  
  68. int superlong::length()
  69. {
  70.     return arrayLength;
  71. }
  72.  
  73. superlong superlong::operator+(superlong op2)
  74. {
  75.     superlong temp;
  76.     string s = "";
  77.     op2.give(s);
  78.     temp.get(s);
  79.     for (int i = 0; i < max(op2.length(), arrayLength); i++)
  80.         temp.intArray[i] += intArray[i];
  81.     for (int i = 0; i < max(op2.length(), arrayLength); i++)
  82.         if (temp.intArray[i] > 9)
  83.         {
  84.             temp.intArray[i+1] += intArray[i] / 10;
  85.             temp.intArray[i] %= 10;
  86.         }
  87.         return temp;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment