// BigInt.cpp // BigInt stores an integer. // This version stores only non negative integers. // The integers may grow to very large size. The // vector that stores the integer grows to match // the size of the number. // If BigInt has not been initialized, it prints // its value as #UNK. // tom bailey 16 feb 00 /* The storage for a BigInt contains bool known; vector digit; // digit[0] is the units digit */ #include #include using namespace std; #include "BigInt.h" // constructors // post: this BigInt is #unknown BigInt::BigInt() : known( false ) { } // pre: n >= 0 // post: this BigInt represents n BigInt::BigInt( long n ) { if( n<0 ) known = false; else { known = true; while( n>0 ) { digit.push_back( n%10 ); n /= 10; } } } // post: this BigInt is a copy of bigint BigInt::BigInt( const BigInt & bigint ) : known( bigint.known ) { if( known ) for( short i=0; i 0 ) digit.push_back( carry ); } return *this; } // assignment // post: this BigInt is a copy of rhs const BigInt & BigInt::operator=( const BigInt & rhs ) { if( this != &rhs ) { known = rhs.known; digit.resize( 0 ); if( known ) for( short i=0; i=0; --i ) outf << digit[i]; } // input/output operators ostream & operator<<( ostream & outf, const BigInt & bigint ) { bigint.print( outf ); return outf; }