So ive been trying to figure this out on my own and searching the books and the net and still no success. Can anyone give me some input with this thing.
#pragma once
#include<iostream>
#include<cstring>
using namespace std;
class hugeint{
friend ostream &operator<<(ostream &, const hugeint &);
public:
hugeint(long = 0);
hugeint(const char *);
hugeint operator+(const hugeint &);
hugeint operator+(int);
hugeint operator+(const char *);
hugeint operator*(const hugeint &);
hugeint operator*(const char *);
hugeint operator*(int);
hugeint operator/(const hugeint &);
hugeint operator/(const char *);
hugeint operator/(int);
//hugeint operator==(const hugeint &);
//hugeint operator==(const char *);
//hugeint operator==(int);
private:
short integer[30];
};
hugeint::hugeint(long value){
for(int i=0; i<29; i++)
integer[i]=0;
for(int j=29; value !=0 && j>=0; j--){
integer[j]=value % 10;
value /=10;
}
}
hugeint::hugeint(const char *string){
for(int i=0; i<=29; i++)
integer[i]=0;
int length=strlen(string);
for(int j=30 - length, k=0; j<=29; j++, k++)
if(isdigit(string[k])) integer[j] = string[k] -'0';
}
hugeint hugeint::operator+(const hugeint &op2){
hugeint temp;
int carry=0;
for(int i=29; i>=0; i--){
temp.integer[i]=integer[i]+op2.integer[i]+carry;
if(temp.integer[i]>9){
temp.integer[i] %=10;
carry=1;
}
else
carry=0;
}
return temp;
}
hugeint hugeint::operator +(int op2){
return *this + hugeint(op2);
}
hugeint hugeint::operator +(const char *op2){
return *this + hugeint(op2);
}
//Multi
hugeint hugeint::operator*(const hugeint &op2){
hugeint temp;
int carry = 0;
int counter = 0;
hugeint reset;
int position = 29;
for(int i=29; i>0; i--)
{
temp.integer[i]=this->integer[i] * op2.integer[i]+carry;
if(temp.integer[i]>9)
{
temp.integer[i] %=10;
carry=1;
return temp;
}
else
carry=0;
}
return temp;
}
hugeint hugeint::operator *(int op2){
return *this * hugeint(op2);
}
hugeint hugeint::operator *(const char *op2){
return *this * hugeint(op2);
}
ostream& operator<<(ostream &output, const hugeint &num){
int i;
for(i=0;(num.integer[i]==0)&&(i<=29);i++);
if(i==30)
output<<0;
else
for( ; i<=29; i++)
output<<num.integer[i];
return output;
}