//file CBigInt003.cpp
//date 01/28/2005
//author aou
#include <iostream>
using namespace std;
const int MAX_DIGITS = 50;
const int BASE = 10;
class CBigInt
{
private:
int _base;
char _sign;
char _digits[MAX_DIGITS];
//...
public:
CBigInt(void);//constructor/auto-initializer
void display(void);
void initialize(void);
CBigInt(char s[]); //CBigInt bi("+12345");
//void input(void);
//add(a, b, c);
//add(a, b);
//add(b);
//CBigInt abs(void);
//CBigInt pow(int expo);
//...
};
void main(void)
{
CBigInt a("667627001667627001667627001"), b, c;
a.display();
//cin >> a; a.input();
//cin >> b;
//cin >> c;
//c = a + b; add(a, b, c);
//cout << c; c.display();
}
CBigInt::CBigInt(char s[])
{
initialize();
/*
if (s[0] == '-')
_sign = '-';
else
_sign = '+';
*/
_sign = '+';
/*
j = MAX_DIGITS-1
for i = length(s)-1 to 0
digits[j] = s[i]
j--
end for
*/
int j = MAX_DIGITS-1;
for (int i = strlen(s)-1; i>=0; i--)
{
_digits[j] = s[i];
j--;
}
}
void CBigInt::display(void)
{
cout << _sign;
for (int i=0; i<=MAX_DIGITS-1; i++)
cout << _digits[i];
cout << '[' << _base << "]\n";
}
void CBigInt::initialize(void)
{
_base = BASE;
_sign = '+';
for (int i=0; i<=MAX_DIGITS-1; i++)
_digits[i] = '0';
}
CBigInt::CBigInt(void)
{
_base = BASE;
_sign = '+';
for (int i=0; i<=MAX_DIGITS-1; i++)
_digits[i] = '0';
}
/*
Output:
+00000000000000000000000667627001667627001667627001[10]
Press any key to continue
*/
|