BigInt 형 클래스
BigInt.h



**********************************************************


#include
using namespace std;


class BigInt
{
friend BigInt operator+(const BigInt&, const BigInt&);
public:
BigInt(const char*);
BigInt(unsigned = 0 );
BigInt(const BigInt&);
BigInt& operator= (const BigInt&);
BigInt& operator+=(const BigInt&);
~BigInt(void);
char* getDigits() const{ return digits; }
unsigned getNdigits() const { return ndigits; }
private:
char* digits;
unsigned ndigits;
unsigned size;
BigInt(const BigInt&, const BigInt&);
char fetch(unsigned i) const;
};

inline
BigInt operator+ (const BigInt& left, const BigInt& right)
{
return BigInt(left, right);
}


ostream& operator<< (ostream& os, BigInt& bi)
{
char c;
const char* d = bi.getDigits();
for( int i = bi.getNdigits() - 1 ; i >= 0 ; i-- ){
c = d[i] + '0';
os << c;
}
os << endl;
return os;
}


**********************************************************



BigInt.cpp



**********************************************************



#include "bigint.h"



BigInt::BigInt(unsigned u)
{
unsigned v = u;
for(ndigits = 1 ; (v/=10) > 0 ; ++ndigits){
;
}
digits = new char[size = ndigits];
for( unsigned i = 0 ; i < ndigits ; ++i ){
digits[i] = u%10;
u/=10;
}
}

BigInt::BigInt(const char* s)
{
if( s[0] == '
by DFman | 2005/09/26 13:21 | 유용한 클래스 모음 | 트랙백 | 덧글(1)
<< 이전 다음 >>