You are on page 1of 12

#include<iostream.

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==================
======================"

void biginteger::operator+(biginteger b2) //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];

} //end of adition function

//cout<<"===================SUBTRACTION=============
=====================";

void biginteger::operator-(biginteger b2) //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];

} // end of subraction function

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:

cout<<"=====TO DO PERFORM ADDTION


INFORMATION====\n";

cout<<"==enter integer of object1 as a


integer==\n";

b1.read();

cout<<"==enter integer of object2 as a


integer==\n";

b2.read();

b1+b2;
//addition operator overload

break;

case 2:

cout<<"=====TO DO PERFORM SUBTRACTION INFORMATION====\n";

cout<<"==enter integer of object1 as a integer==\n";

b1.read();

cout<<"==enter integer of object2 as a integer==\n";

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:

cout<<"your choice is wrong";

break;

getch();

You might also like