// CBigInt001.cpp
// 04/07/2004
// Author: AOU
//////////////////////////////////////////////////////////////////////
// include files
//////////////////////////////////////////////////////////////////////
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
//////////////////////////////////////////////////////////////////////
// constants
//////////////////////////////////////////////////////////////////////
const int MAX_DIGITS = 50; //artificial limit
const int TEST_COUNT = 20;
/*
const char *TEST_DATA[] =
{
"0", "1", "12", "123", "1234", "123450", "1234506", "12345067",
"123450670", "1234506708", "1234506708", "Hello", "PSU",
"9", "99", "999", "9999", "99999", "999999", "9999999",
"10", "200", "3000", "40000", "500000", "6000000", "70000000",
"800000000", "9000000000", "1090000000000", "11900000000000",
"129000000000000", "1390000000000000", "14900000000000000"
};
*/
const char *TEST_DATA[] =
{
"0", "1", "12", "123", "1234", "123450", "1234506", "12345067"
};
const int TEST_DATA_COUNT = sizeof(TEST_DATA)/sizeof(TEST_DATA[0]);
//////////////////////////////////////////////////////////////////////
// class CDigit
//////////////////////////////////////////////////////////////////////
class CDigit
{
private:
CDigit * _prev;
CDigit * _next;
char _digit;
public:
CDigit(void);
CDigit(char d);
friend ostream & operator << (ostream &bob, const CDigit &d);
};
//////////////////////////////////////////////////////////////////////
// class CBigInt
//////////////////////////////////////////////////////////////////////
class CBigInt
{
private:
CDigit * _first;
CDigit * _last;
char _sign;
unsigned long int _size;
void initialize(void);
public:
CBigInt(void);
void display(void);
CBigInt(char d[]);
CBigInt(char code);
void displayMinimized(void);
bool shiftLeft(void);
friend void add(CBigInt x, CBigInt y, CBigInt &z);
void displayScientific(void);
CBigInt(short int x);
// [SHRT_MIN, SHRT_MAX] = [-32767,32767]
CBigInt(unsigned short int x);
// [0, USHRT_MAX] = [0, 65535]
CBigInt(long int x);
// [LONG_MIN, LONG_MAX] = [-2147483647, 2147483647]
CBigInt(unsigned long int x);
// [0, ULONG_MAX] = [0, 4294967295]
void displayWithSeparatorForThousands(void);
friend ostream & operator << (ostream &bob, const CBigInt &bi);
CBigInt(const CBigInt &bi);
friend bool isEqual(const CBigInt &bi1, const CBigInt &bi2);
bool isEqual(const CBigInt &bi2);
bool operator ==(const CBigInt &bi2);
bool operator < (const CBigInt &bi2);
bool operator <= (const CBigInt &bi2);
bool operator > (const CBigInt &bi2);
bool operator >= (const CBigInt &bi2);
bool operator != (const CBigInt &bi2);
bool shiftRight(void);
bool shiftRight(int d);
bool shiftLeft(int d);
CBigInt add(const CBigInt &y);
CBigInt operator +(const CBigInt &y);
};
void driver_CDigit_ConstructorDefault(void);
void main(void)
{
driver_CDigit_ConstructorDefault();
}
void driver_CDigit_ConstructorDefault(void)
{
CDigit d;
}
CDigit::CDigit(void)
{
_prev = NULL;
_next = NULL;
_digit = 0;
}
|