Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class BigInt{
  6. private:
  7.     int *p,nr_cif;
  8. public:
  9.     //BigInt(char *s);
  10.     BigInt();
  11.     BigInt(int x);
  12.     friend ostream & operator <<(ostream&os,BigInt &r);
  13. };
  14.  
  15. BigInt::BigInt()
  16. {
  17.     nr_cif=0;
  18.     p=NULL;
  19. }
  20. BigInt::BigInt(int x)
  21. {
  22.     int i=1,uc,aux,nr=0;
  23.     aux=x;
  24.     do
  25.     {
  26.         aux/=10;
  27.         nr++;
  28.     }while(aux);
  29.  
  30.     p=new int[nr];
  31.     aux=x;
  32.      while(aux)
  33.     {
  34.         uc=aux%10;
  35.         aux/=10;
  36.         p[i++]=uc;
  37.     }
  38.     nr_cif=nr;
  39. }
  40.  
  41. ostream & operator <<(ostream & os,BigInt & r)
  42. {
  43.     for(int i=r.nr_cif;i>=1;i--)
  44.         cout<<r.p[i];
  45.     return os;
  46. }
  47.  
  48. int main()
  49. {
  50.     int x;
  51.     BigInt w(56);
  52.     cout<<w;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement