Professional Documents
Culture Documents
h>
#include<conio.h>
#include<string.h>
class biginteger
private:
char integer[100];
int arr1[100];
int arr2[100];
int size;
public:
int len;
void read();
void operator+(biginteger );
void operator-(biginteger );
};
void biginteger::read()
int i;
cout<<"enter integer=\n";
cin>>integer;
size=strlen(integer);
cout<<"size iength=\n"<<size<<"\n";
for(i=0;integer[i]!=NULL;i++)
if(integer[i]=='0')
arr1[i]=0;
if(integer[i]=='1')
arr1[i]=1;
if(integer[i]=='2')
arr1[i]=2;
if(integer[i]=='3')
arr1[i]=3;
if(integer[i]=='4')
arr1[i]=4;
if(integer[i]=='5')
arr1[i]=5;
if(integer[i]=='6')
arr1[i]=6;
if(integer[i]=='7')
arr1[i]=7;
if(integer[i]=='8')
arr1[i]=8;
if(integer[i]=='9')
arr1[i]=9;
for(i=size;i<100;i++)
{
arr1[i]=0;
//cout<<"================ADDITION==================
======================"
int temp=0;
int j,c,d;
if(size==b2.size)
len=size;
else
{
if(size>b2.size)
c=size-b2.size;
for(j=(b2.size-1);j>=0;j--)
b2.arr1[j+c]=b2.arr1[j];
for(j=0;j<c;j++)
{
b2.arr1[j]=0;
len=size;
else
d=b2.size-size;
for(j=size;j>=0;j--)
arr1[j+d]=arr1[j];
for(j=0;j<d;j++)
arr1[j]=0;
len=b2.size;
cout<<"len="<<len<<"\n";
for(j=len-1;j>=0;j--)
arr2[j]=arr1[j]+b2.arr1[j]+temp;
if(j==0)
{
arr2[j]=arr2[j];
break;
if(arr2[j]>9)
temp=1;
arr2[j]=arr2[j]%10;
else
{
temp=0;
cout<<"==================ADDITION
IS================================\n\t";
for(j=0;j<=len-1;j++)
cout<<arr2[j];
//cout<<"===================SUBTRACTION=============
=====================";
int temp=0;
int j,c,d;
if(size==b2.size)
len=size;
else
{
if(size>b2.size)
c=size-b2.size;
for(j=(b2.size-1);j>=0;j--)
b2.arr1[j+c]=b2.arr1[j];
for(j=0;j<c;j++)
b2.arr1[j]=0;
len=size;
else
d=b2.size-size;
for(j=size;j>=0;j--)
{
arr1[j+d]=arr1[j];
for(j=0;j<d;j++)
arr1[j]=0;
len=b2.size;
}
}
cout<<"len="<<len<<"\n";
if(size>=b2.size)
for(j=len-1;j>=0;j--)
if((arr1[j]-temp)>=b2.arr1[j])
arr2[j]=(arr1[j]-temp)-b2.arr1[j];
temp=0;
else
arr1[j]= arr1[j]+10;
arr2[j]=(arr1[j]-temp)-
b2.arr1[j];
temp=1;
else
for(j=len-1;j>=0;j--)
if((b2.arr1[j]-temp)>=arr1[j])
{
arr2[j]=(b2.arr1[j]-temp)-arr1[j];
temp=0;
else
b2.arr1[j]=b2.arr1[j]+10-
temp;
arr2[j]=b2.arr1[j]-arr1[j];
temp=1;
}
cout<<"===================SUBTRACTION=============
==================\n\t";
for(j=0;j<=len-1;j++)
cout<<arr2[j];
void main()
clrscr();
biginteger b1,b2;
int choice;
//clrscr();
cout<<"=================enter
your choice ===============\n";
cout<<"\t1-addtion\n";
cout<<"\t2-subtration\n";
cout<<"\t3-multipication\n";
cout<<"\t4-divide\n";
cout<<"======enter any
number:-" ;
cin>>choice;
switch(choice)
{
case 1:
b1.read();
b2.read();
b1+b2;
//addition operator overload
break;
case 2:
b1.read();
b2.read();
b1-b2;
//SUBTRACTION operator overload
break;
}
/*case 3:
cout<<"TO
DO PERFORM MULTIPICATION INFORMATION\n";
b1*b2; //
MULTIPICATION OPERATOR overload
break;
case 4:
cout<<"TO
DO PERFORM DIVISION INFORMATION\n";
b1+b2;
//DIVISION operator overload
break;
} */
default:
break;
getch();