Манипулирование с целыми числами произвольной длины - (реферат)
p>coutaa[128],
bb[128];
cout cin >>aa;
cout cin >>bb;
cout=r;
r ;
a=aa;
b=bb;
r if (a if (a>b) rb ";
if (a if (a>=b) r=b ";
if (a! =b) r if (a==b) r r
}
}
programm2;
#define COUNT unsigned int
#define TRUE 1
#define FALSE 0
#define ILLEGAL 10
enum
{
PLUS,
MINUS
};
extern class unlim
{
public:
unlim(char*);
unlim();
unlim(unlim&);
~unlim();
unlim
&operator = (char*),
&operator = (unlim&);
friend int
operator == (unlim&, unlim&),
operator ! = (unlim&, unlim&),
operator > (unlim&, unlim&),
operator >= (unlim&, unlim&),
operator < (unlim&, unlim&),
operator friend unlim
operator + (unlim&), // unary
operator - (unlim&), // unary
operator + (unlim&, unlim&), // binary
operator - (unlim&, unlim&), // binary
operator * (unlim&, unlim&),
abs(unlim&);
friend ostream
&operator private:
struct descriptor
{
char
*body;
COUNT
len,
HowMany;
};
descriptor
*pv; //pointer to value descriptor
char
sign,
digit(COUNT number);
char
&operator [](COUNT i) {return pv->body[i]; }
void
init0(), //init by zero
NotDigit(), //message "no digit" & init0
optimize(), //optimize length of body
error(char*); //display error message
};
inline int operator ==(unlim &a, unlim &b)
{
return ! (a! =b);
}
inline int operator ! (a! =b);
inline int operator >=(unlim &a, unlim &b)
{
return ! (a }
inline int operator >(unlim &a, unlim &b)
{
return ! (a }
inline unlim operator +(unlim &x)
{
return x;
}
programm3;
#include
#include
#include
#include
#define COUNT unsigned int
#define TRUE 1
#define FALSE 0
#define ILLEGAL 10
enum
{
PLUS,
MINUS
};
class unlim
{
public:
unlim(char*);
unlim();
unlim(unlim&);
~unlim();
unlim
&operator = (char*),
&operator = (unlim&);
friend int
operator == (unlim&, unlim&),
operator ! = (unlim&, unlim&),
operator > (unlim&, unlim&),
operator >= (unlim&, unlim&),
operator < (unlim&, unlim&),
operator friend unlim
operator + (unlim&), // unary
operator - (unlim&), // unary
operator + (unlim&, unlim&), // binary
operator - (unlim&, unlim&), // binary
operator * (unlim&, unlim&),
abs(unlim&);
friend ostream
&operator private:
struct descriptor
{
char
*body;
COUNT
len,
HowMany;
};
descriptor
*pv; //pointer to value descriptor
char
sign,
digit(COUNT number);
char &operator [](COUNT i) {return pv->body[i]; }
void
init0(), //init by zero
NotDigit(), //message "no digit" & init0
optimize(), //optimize length of body
error(char*); //display error message
};
inline void unlim: :error(char *message)
{
cout }
void unlim: :init0()
{
(pv->body)=new char;
*(pv->body)=0;
(pv->len)=1;
sign=PLUS;
}
char unlim: :digit(COUNT number)
{
if ( number>=(pv->len) )
return ILLEGAL;
char byte=(pv->body)[number/2];
if (number%2==0)
return byte%10;
else
return byte/10;
}
unlim: :unlim()
{
pv=new descriptor;
init0();
(pv->HowMany)=1;
}
unlim: :~unlim()
{
if ( --(pv->HowMany)==0 )
{
delete pv->body;
delete pv;
}
}
char DecVal(char symbol)
{
if ( isdigit(symbol) )
return symbol-'0';
return ILLEGAL;
}
unlim: :unlim(char *string)
{
pv=new descriptor;
(pv->HowMany)=1;
COUNT Length=strlen(string);
if (Length==0)
{
error("Empty string assigned. Value=0");
init0();
return;
}
else
{
COUNT LeftLimit=0;
switch (string[0])
{
case '-':
sign=MINUS;
LeftLimit=1;
break;
case '+':
LeftLimit=1;
default:
sign=PLUS;
}
if (Length-LeftLimit==0)
{
error("Sign without value. Value=0");
init0();
return;
}
else
{
while (string[LeftLimit]=='0')
LeftLimit++;
if ( (Length-=LeftLimit)==0 )
{
init0();
return;
}
COUNT DestLength=Length/2+Length%2;
(pv->body)=new char[DestLength];