#include <iostream>
#include <cmath>
#include <string>
using namespace std;
class BigInt
{
private:
string str;// to hold string representation of BigInt
bool isPositive;// for indicating the sign
int len;// total # of digits in BigNum
int lastLen;// length of last < 4 digit #
int Nsubs;// # of 4 digit #'s
int* pInt;// pointer to array of integers, which will be used to dynamically allocate
// Nsubs + 2 integers for the array. This should make the array large enough
// for worst case. z may be one digit longer than the longest of x or y
// due to carrying of a digit following the summation of x and y
// private functions
void addMags(const BigInt& x, const BigInt& y);// this->Nsubs must be right
void subtractMags(const BigInt& larger, const BigInt& smaller);// this->Nsubs must be right
void findCorrectLength(void);// reduces Nsubs to eliminate leading pInt[] == 0
public:
// functions
void INIT_userEntry(void);// prompts user for value
void fillIntArray(void);// parses string into integer elements
void to_string(void);// builds up string from integer elements
void printElements(void);// lists elements and other info
int getLength(void);
bool isLowerMagnitude(const BigInt& x) const;// for working with magnitudes only
bool isLowerOrEqualMag(const BigInt& x) const;
//** operators **
// assignment
BigInt& operator=(const BigInt& x);// use this form for +=, -=, *=
BigInt& operator=(const std::string& strVal);
BigInt& operator=(int x);
// addition
BigInt operator+(const BigInt& x) const;
// subtraction
BigInt operator-(const BigInt& x) const;
// multiplication
BigInt operator*(const BigInt& x) const;// BigInt * BigInt
BigInt operator*(int x) const;// BigInt * int
friend BigInt operator*(int x, const BigInt& BigX);// int * BigInt
// division
BigInt operator/(const BigInt& x) const;// BigInt / BigInt - returns quotient
BigInt operator%(const BigInt& x) const;// BigInt % BigInt - returns remainder
BigInt operator/( int x) const;// BigInt / int
BigInt operator%( int x) const;// BigInt % int
// comparison
bool operator<(const BigInt& x) const;
// constructors
BigInt();// NULL construction (no allocation to pInt)
BigInt( int length);// for given # of digits
BigInt(const std::string& strVal);// for given string
BigInt(const BigInt& x);// copy
// destructor
~BigInt();// deletion of pInt handled here
};
BigInt& BigInt::operator=(const BigInt& x)
{
len = x.len;
lastLen = x.lastLen;
Nsubs = x.Nsubs;
isPositive = x.isPositive;
str.assign( x.str );
// pInt
if( pInt != NULL )
delete [] pInt;// out with the old
pInt = new int[x.Nsubs + 2];// in with the new
for( int j=0; j<=Nsubs; j++)
this->pInt[j] = x.pInt[j];// values copied
return( *this );
}// end of =
BigInt& BigInt:: operator=(const std::string& strVal)
{
if( strVal[0] == '-' )
{
str.assign( strVal.begin()+1, strVal.end() );
isPositive = false;
}
else
{
str.assign( strVal );
isPositive = true;
}
len = str.length();
lastLen = len%4;
Nsubs = len/4;
if( pInt != NULL )
delete [] pInt;
pInt = new int[ Nsubs + 2];// array allocated
for(int j=0; j<(Nsubs + 2); j++)
pInt[j] = 0;
fillIntArray();// the data is ready, why not do it now?
findCorrectLength();
return( *this );
}// end of =
BigInt& BigInt::operator=(int x)
{
if( x >= 0 )
isPositive = true;// no "negative zero"
else
{
isPositive = false;
x *= -1;// work with positive # below
}
if( x > 0 )
len = 1 + static_cast<int>( log10( static_cast<double>(x) ) );
else// x == 0
len = 1;
Nsubs = len/4;
lastLen = len%4;
// pInt
if( pInt != NULL )
delete [] pInt;// out with the old
pInt = new int[Nsubs + 2];// in with the new
for( int j=0; j<=Nsubs; j++)
{
pInt[j] = x%10000;// values copied
x = x/10000;
}
return( *this );
}// end of =
BigInt BigInt:: operator+(const BigInt& x) const
{
// z = *this + x
BigInt z( len > x.len? len:x.len );// z will have len = greatest of the 2
if( this->isPositive )
{
if( x.isPositive )
{
z.addMags( *this, x );
z.isPositive = true;
}
else// x is negative
{
if( this->isLowerMagnitude(x) )
{
z.subtractMags( x, *this );
z.isPositive = false;
}
else
{
z.subtractMags( *this, x );
z.isPositive = true;
}
}
}
else// this is negative
{
if( x.isPositive )
{
if( this->isLowerMagnitude(x) )
{
z.subtractMags( x, *this );
z.isPositive = true;
}
else
{
z.subtractMags( *this, x );
z.isPositive = false;
}
}
else// x is negative
{
z.addMags( *this, x );
z.isPositive = false;
}
}
z.findCorrectLength();
return z;
}// end of +
BigInt BigInt:: operator-(const BigInt& x) const
{
// z = *this - x
BigInt z( len > x.len? len:x.len );// z will have len = greatest of the 2
if( this->isPositive )
{
if( x.isPositive )
{
if( this->isLowerMagnitude(x) )
{
z.subtractMags( x, *this );
z.isPositive = false;
}
else
{
z.subtractMags( *this, x );
z.isPositive = true;
}
}
else// x is negative
{
z.addMags( *this, x );
z.isPositive = true;
}
}
else// this is negative
{
if( x.isPositive )
{
z.addMags( *this, x );
z.isPositive = false;
}
else// x is negative
{
if( this->isLowerMagnitude(x) )
{
z.subtractMags( x, *this );
z.isPositive = true;
}
else
{
z.subtractMags( *this, x );
z.isPositive = false;
}
}
}
z.findCorrectLength();
return z;
}// end of -
BigInt BigInt:: operator*(const BigInt& x) const// BigInt * BigInt
{
int j=0, k=0;// for looping
int carry=0;
int term=0;
// z = y * x where y = this
BigInt z( len + x.len - 1 );// z will have len = sum of the 2 lengths
if( x.isPositive )
z.isPositive = this->isPositive;
else
z.isPositive = !this->isPositive;
for( j=0; j<= this->Nsubs; j++)
{
for( k=0; k<= x.Nsubs; k++)
{
term = this->pInt[j]*x.pInt[k];
z.pInt[k+j] += term%10000;
z.pInt[j+k+1] += term/10000;
}
}
for( j=0; j< z.Nsubs; j++)// new
{
z.pInt[j+1] += z.pInt[j]/10000;
z.pInt[j] = z.pInt[j]%10000;
}
z.findCorrectLength();
return z;
}// end of *
// working
BigInt BigInt:: operator*(int x) const// BigInt * int
{
int j=0;// for looping
bool xIsPos = x < 0 ? false : true;
if( !xIsPos )x *= -1;
// z = y * x where y = this
int xlen = 0;// fix?
if( x > 0 )
xlen = 1 + static_cast<int>( log10( static_cast<double>(x) ) );
else// x == 0
xlen = -len;
BigInt z( len + xlen );// retVal
if( xIsPos )
z.isPositive = this->isPositive;
else
z.isPositive = !this->isPositive;
if( x != 0 )
{
int xLow = x%10000;
int xHigh = x/10000;
int term=0;
for( j=0; j<= this->Nsubs; j++)
{
term = this->pInt[j]*xLow;
z.pInt[j] += term%10000;
z.pInt[j+1] += term/10000;
if( xHigh )
{
term = this->pInt[j]*xHigh;
z.pInt[j+1] += term%10000;
z.pInt[j+2] += term/10000;
cout << "xHigh = " << xHigh << endl;
}
}
for( j=0; j< z.Nsubs; j++)// new
{
z.pInt[j+1] += z.pInt[j]/10000;
z.pInt[j] = z.pInt[j]%10000;
}
}// end if x != 0
z.findCorrectLength();
return z;
}// end of *
BigInt operator*(int x, const BigInt& BigX)// int * BigInt
{
int j=0;// for looping
bool xIsPos = x < 0 ? false : true;
if( !xIsPos )x *= -1;
// z = x * BigX
int xlen = 0;// fix?
if( x > 0 )
xlen = 1 + static_cast<int>( log10( static_cast<double>(x) ) );
else// x == 0
xlen = -BigX.len;
BigInt z( BigX.len + xlen );// retVal
if( xIsPos )
z.isPositive = BigX.isPositive;
else
z.isPositive = !BigX.isPositive;
if( x != 0 )
{
int xLow = x%10000;
int xHigh = x/10000;
int term=0;
for( j=0; j<= BigX.Nsubs; j++)
{
term = BigX.pInt[j]*xLow;
z.pInt[j] += term%10000;
z.pInt[j+1] += term/10000;
if( xHigh )
{
term = BigX.pInt[j]*xHigh;
z.pInt[j+1] += term%10000;
z.pInt[j+2] += term/10000;
cout << "xHigh = " << xHigh << endl;
}
}
for( j=0; j< z.Nsubs; j++)// new
{
z.pInt[j+1] += z.pInt[j]/10000;
z.pInt[j] = z.pInt[j]%10000;
}
}// end if x != 0
z.findCorrectLength();
return z;
}// end of *
BigInt BigInt::operator/( int x) const// BigInt / int
{
BigInt BigX;
BigX = x;
return ( *this/BigX );
}
BigInt BigInt::operator%( int x) const// BigInt % int
{
BigInt BigX;
BigX = x;
return ( *this%BigX );
}
// 5th version = 4th version stripped of test output
BigInt BigInt::operator/(const BigInt& x) const// BigInt / BigInt
{
// Q = *this/x
int j=0, k=0;// for looping
double fSm = 10000.0;// base
int dN = this->Nsubs - x.Nsubs;// *this is divided / x is divisor
if( dN < 0 )
dN = 0;// can't give negative value to constructor
BigInt Q( 4*dN );// retVal = quotient
BigInt trial( 4*this->Nsubs );
BigInt diff( *this );
diff.isPositive = true;// regardless of this->isPositive
dN = this->Nsubs - x.Nsubs;// reset value
if( this->isLowerMagnitude(x) )
Q = 0;
else// non-trivial division
{
if( x.isPositive )// deal with sign
Q.isPositive = this->isPositive;
else
Q.isPositive = !this->isPositive;
double qnum = 0.0;
double qden = 1.0;
if( x.Nsubs == 0 )
qden = (double)x.pInt[x.Nsubs]*fSm;
else
qden = (double)x.pInt[x.Nsubs]*fSm + (double)x.pInt[x.Nsubs-1];
int qt = 1;
for( j=dN; j>=0; j--)// each term in quotient
{
if( diff.Nsubs == 0 )// new
qnum = (double)diff.pInt[ diff.Nsubs ];
else
qnum = (double)diff.pInt[ diff.Nsubs ]*fSm + (double)diff.pInt[ diff.Nsubs - 1];
if( diff.Nsubs-trial.Nsubs > 0 )
qnum *= 10000.0;
qt = (int)(qnum/qden);
// find new diff
for( k=0; k<=x.Nsubs; k++)// trials most signif subs = x
trial.pInt[k+j] = x.pInt[k];
for(k=0; k<j; k++)// trials remaining subs = 0
trial.pInt[k] = 0;
if( qt > 0 )
diff = diff - trial*qt;
if( trial.isLowerOrEqualMag(diff) )// new
{
diff = diff - trial;
qt++;
}
Q.pInt[j] = qt;// quotient term
trial.Nsubs--;
}// diff = remainder at end of this
}
Q.findCorrectLength();
return Q;
}// end of /
BigInt BigInt::operator%(const BigInt& x) const// BigInt % BigInt
{
// rem = *this%x
int j=0, k=0;// for looping
double fSm = 10000.0;// base
int dN = this->Nsubs - x.Nsubs;// *this is divided / x is divisor
if( dN < 0 )
dN = 0;// can't give negative value to constructor
BigInt rem( 4*dN );// retVal = quotient
BigInt trial( 4*this->Nsubs );
BigInt diff( *this );
diff.isPositive = true;// regardless of this->isPositive
dN = this->Nsubs - x.Nsubs;// reset value
if( this->isLowerMagnitude(x) )
{
rem = x;
if( x.isPositive )// deal with sign
rem.isPositive = this->isPositive;
else
rem.isPositive = !this->isPositive;
}
else// non-trivial division
{
if( x.isPositive )// deal with sign
rem.isPositive = this->isPositive;
else
rem.isPositive = !this->isPositive;
double qnum = 0.0;
double qden = 1.0;
if( x.Nsubs == 0 )
qden = (double)x.pInt[x.Nsubs]*fSm;
else
qden = (double)x.pInt[x.Nsubs]*fSm + (double)x.pInt[x.Nsubs-1];
int qt = 1;
for( j=dN; j>=0; j--)// each term in quotient
{
if( diff.Nsubs == 0 )// new
qnum = (double)diff.pInt[ diff.Nsubs ];
else
qnum = (double)diff.pInt[ diff.Nsubs ]*fSm + (double)diff.pInt[ diff.Nsubs - 1];
if( diff.Nsubs-trial.Nsubs > 0 )
qnum *= 10000.0;
qt = (int)(qnum/qden);
// find new diff
for( k=0; k<=x.Nsubs; k++)// trials most signif subs = x
trial.pInt[k+j] = x.pInt[k];
for(k=0; k<j; k++)// trials remaining subs = 0
trial.pInt[k] = 0;
if( qt > 0 )
diff = diff - trial*qt;
if( trial.isLowerOrEqualMag(diff) )// correct for sometimes excess remainder
{
diff = diff - trial;
qt++;
}
rem.pInt[j] = qt;// quotient term
trial.Nsubs--;
}// diff = remainder at end of this
rem = diff;
}
rem.findCorrectLength();
return rem;
}// end of %
bool BigInt::operator<(const BigInt& x) const
{
if( this->isPositive && x.isPositive )// both are positive
return this->isLowerMagnitude(x);
if( !this->isPositive && !x.isPositive )// both are negative
return x.isLowerMagnitude(*this);
if( !this->isPositive && x.isPositive )
return true;
if( this->isPositive && !x.isPositive )
return false;
return false;
}// end of <
bool BigInt::isLowerMagnitude(const BigInt& x) const
{
if( this->Nsubs < x.Nsubs )
return true;
if( this->Nsubs > x.Nsubs )
return false;
// at this point this->Nsubs == x.Nsubs
for(int j = this->Nsubs; j >= 0; j--)// from most signif. subint to least signif. subint
{
if( this->pInt[j] < x.pInt[j] )
return true;
else if( this->pInt[j] > x.pInt[j] )
return false;
}
return false;// because they are ==
}// end of isLowerMagnitude()
bool BigInt::isLowerOrEqualMag(const BigInt& x) const
{
if( this->Nsubs < x.Nsubs )
return true;
if( this->Nsubs > x.Nsubs )
return false;
// at this point this->Nsubs == x.Nsubs
for(int j = this->Nsubs; j >= 0; j--)// from most signif. subint to least signif. subint
{
if( this->pInt[j] < x.pInt[j] )
return true;
else if( this->pInt[j] > x.pInt[j] )
return false;
}
return true;// because they are ==
}// end of isLowerOrEqualMag()
// private
void BigInt::addMags(const BigInt& x, const BigInt& y)
{
// *this = x + y
this->pInt[0] = x.pInt[0] + y.pInt[0];// new form
for(int j=1; j<= this->Nsubs; j++)
{
this->pInt[j] = this->pInt[j-1]/10000;
this->pInt[j-1] = this->pInt[j-1]%10000;
if( j <= x.Nsubs )
this->pInt[j] += x.pInt[j];
if( j <= y.Nsubs )
this->pInt[j] += y.pInt[j];
}
return;
}// end of addMags()
// private
void BigInt::subtractMags(const BigInt& larger, const BigInt& smaller)
{
// *this = larger - smaller
int term=0;
int borrow=0;
term = larger.pInt[0] - smaller.pInt[0];
if( this->Nsubs == 0 )
this->pInt[0] = term;
for(int j=1; j<= this->Nsubs; j++)
{
if( term < 0 )
{
borrow = 1;
term += 10000;
}
else
borrow = 0;
this->pInt[j-1] = term;
term = 0;
if( j <= larger.Nsubs )
term += larger.pInt[j] - borrow;
if( j <= smaller.Nsubs )
term -= smaller.pInt[j];
}
this->pInt[this->Nsubs] = term;
return;
}// end of subtractMags()
// private
void BigInt::findCorrectLength(void)// reduces Nsubs to eliminate leading pInt[] == 0
{
while( pInt[Nsubs] == 0 )// eliminate most significant Nsubs==0
Nsubs--;
if( Nsubs < 0 )Nsubs = 0;// may have z == 0
int lastSub = pInt[Nsubs];
lastLen = 0;
while( lastSub != 0 )// find lastLen
{
lastSub /= 10;
lastLen++;
}
len = 4*Nsubs + lastLen;
return;
}// end of findCorrectLength()
BigInt::BigInt()// NULL construction
{
len = lastLen = Nsubs = 0;
isPositive = true;
pInt = NULL;// no array allocated
}// end of default constructor
BigInt::BigInt( int length)// constructor if given the # of digits
{
len = length;
lastLen = len%4;
Nsubs = len/4;
pInt = new int[ Nsubs + 2];// array allocated
// init these values
for(int j=0; j<(Nsubs + 2); j++)
pInt[j] = 0;
isPositive = true;
}
BigInt::BigInt(const std::string& strVal)// given string
{
if( strVal[0] == '-' )
{
str.assign( strVal.begin()+1, strVal.end() );
isPositive = false;
}
else
{
str.assign( strVal );
isPositive = true;
}
len = str.length();
lastLen = len%4;
Nsubs = len/4;
pInt = new int[ Nsubs + 2];// array allocated
for(int j=0; j<(Nsubs + 2); j++)
pInt[j] = 0;
fillIntArray();
findCorrectLength();
}
BigInt::BigInt(const BigInt& x)// copy
{
len = x.len;
lastLen = x.lastLen;
Nsubs = x.Nsubs;
isPositive = x.isPositive;
pInt = new int[ Nsubs + 2];// array allocated
// init these values
for(int j=0; j<(Nsubs + 2); j++)
pInt[j] = x.pInt[j];
}// end of copy constructor
BigInt::~BigInt()// destructor
{
if( pInt != NULL )
delete [] pInt;
}
void BigInt::INIT_userEntry(void)// prompts user for value
{
string strVal;
cout << "Enter a big number: ";
cin >> strVal;
if( strVal[0] == '-' )
{
str.assign( strVal.begin()+1, strVal.end() );
isPositive = false;
}
else
{
str.assign( strVal );
isPositive = true;
}
len = str.length();
lastLen = len%4;
Nsubs = len/4;
if( pInt != NULL )
delete [] pInt;
pInt = new int[ Nsubs + 2];// array allocated
for(int j=0; j<(Nsubs + 2); j++)
pInt[j] = 0;
fillIntArray();
findCorrectLength();
return;
}// end of INIT_userEntry()
void BigInt::fillIntArray(void)
{
char sub_str[5];
for(int j=1; j<= Nsubs; j++)// all of the full 4 char cases
{
str.copy( sub_str, 4, len - 4*j );// last arg reveals reason for indexing from 1 not 0
sub_str[4] = '\0';
pInt[j-1] = atoi( sub_str );
}
if( lastLen )
{
str.copy( sub_str, lastLen, 0 );// this generates a warning about unsafe parameters
sub_str[ lastLen ] = '\0';// it works because the correct values are being used
pInt[ Nsubs ] = atoi( sub_str );
}
return;
}// end of fillIntArray()
void BigInt::to_string(void)
{
int dgt[4];// digits from least to most significant
int j=0, k=0, chCnt = 0;
str.clear();
if( (Nsubs == 0)&&(pInt[0] == 0) )// case: *this == 0
{
str = "0";
isPositive = true;// no "negative" zero
cout << str << endl;
return;
}
int temp = pInt[Nsubs];
for( j=0; j<4; j++)
{
dgt[j] = temp%10;
temp /= 10;
}
bool leadZeros = true;
for( j=3; j>=0; j--)
{
if( dgt[j] > 0 )
leadZeros = false;
if( !leadZeros )
str += dgt[j] + '0';
}
for( j=(Nsubs-1); j>= 0; j--)// all of the full 4 char cases, in reverse order
{
temp = pInt[j];
for( k=0; k<4; k++)
{
dgt[k] = temp%10;
temp /= 10;
}
for( k=3; k>=0; k--)
str += dgt[k] + '0';
}
len = str.length();
lastLen = len%4;// modify?
if( !isPositive )
cout << "-";
cout << str << endl;// << endl;
return;
}// end of to_string()
void BigInt::printElements(void)
{
for(int j=0; j< Nsubs; j++)
{
cout << " pInt[" << j << "] = ";
// show leading zeros
if( pInt[j] < 1000 )
cout << "0";
if( pInt[j] < 100 )
cout << "0";
if( pInt[j] < 10 )
cout << "0";
cout << pInt[j] << endl;
}
// no lead zeros for most significant element
cout << " pInt[" << Nsubs << "] = " << pInt[Nsubs] << endl;
// other data
cout << "len = " << len << " ";
cout << "lastLen = " << lastLen << " ";
cout << "Nsubs = " << Nsubs << " ";
if( isPositive )
cout << "sign is: +" << endl;
else
cout << "sign is: -" << endl;
return;
}// end of printElements()
int BigInt::getLength(void)
{
return len;
}
//*** test program ***
int main()
{
int j=0;// for looping
//** testing constructors **
BigInt x("-876543");// from string
cout << "x = "; x.to_string();
BigInt z;// NULL construction
z = "234";// assign from string
BigInt y(x*z);// copy constructor with use of BigInt*BigInt operator
cout << "y = "; y.to_string();// -876543*234 = -205111062
//** testing multiplication of BigInt*int **
z = 2;// assign integer value
for( int j=3; j<=100; j++)// find 100! THE CRUCIAL TEST
z = z*j;
cout << endl << "100! = "; z.to_string();
//** testing addition and subtraction of BigInts **
int k=0;// for looping
// find 30!
BigInt fact30("2");
for( k=3; k<=30; k++)
fact30 = fact30*k;
cout << "30! = "; fact30.to_string();
// find 40!
BigInt fact40("2");
for( k=3; k<=40; k++)
fact40 = fact40*k;
cout << "40! = "; fact40.to_string();
// find 50!
BigInt fact50("2");
for( k=3; k<=50; k++)
fact50 = k*fact50;// using int*BigInt operator
cout << "50! = "; fact50.to_string();
// perform a series of additions and subtractions of BigInts
z = fact30 - fact50;// z = 30!-50!
cout << " 30!-50! = "; z.to_string();
z = z - fact30;// z = ( 30!-50! ) - 30! = -50!
cout << "-50! = "; z.to_string();
z = z + fact40;// z = -50! + 40!
cout << "-50!+40! = "; z.to_string();
z = z + fact50;// z = ( -50!+40! ) + 50! = 40!
cout << "40! = "; z.to_string();
//** testing division **
BigInt numer, denom;
BigInt Q, rem;
// test #1
numer = 2;// generating values below
for( j=3; j<=30; j++)// 30!
numer = numer*j;
rem = 4567;
numer = numer + rem;// 30! + 4567
denom = 21;
for( j=22; j<=30; j++)// 30!/20!
denom = denom*j;// Q = 20! = 2432902008176640000, rem = 4567 expected
cout << endl << "** test #1 of division **" << endl;
cout << "numer = "; numer.to_string();
cout << "denom = "; denom.to_string();
Q = numer/denom;
cout << "quotient = "; Q.to_string();
rem = numer%denom;
cout << "remainder = "; rem.to_string();
// test #2
numer = "5735405000000";
denom = "654321";// Q = 8765430, rem = 76970 expected
cout << endl << "** test #2 **" << endl;
cout << "numer = "; numer.to_string();
cout << "denom = "; denom.to_string();
Q = numer/denom;
cout << "quotient = "; Q.to_string();
rem = numer%denom;
cout << "remainder = "; rem.to_string();
// test #3
numer = "49086430016543088";
denom = "8765432";// Q = 5600001234, rem = 0 expected
cout << endl << "** test #3 **" << endl;
cout << "numer = "; numer.to_string();
cout << "denom = "; denom.to_string();
Q = numer/denom;
cout << "quotient = "; Q.to_string();
rem = numer%denom;
cout << "remainder = "; rem.to_string();
// test #4
numer = "56159300";
denom = "123";// Q = 456579, rem = 83 expected
cout << endl << "** test #4 **" << endl;
cout << "numer = "; numer.to_string();
cout << "denom = "; denom.to_string();
Q = numer/denom;
cout << "quotient = "; Q.to_string();
rem = numer%denom;
cout << "remainder = "; rem.to_string();
// test #4 repeat with denom as integer
numer = "56159300";
int denomAsInt = 123;// Q = 456579, rem = 83 expected
cout << endl << "** test #4 with denom as integer **" << endl;
cout << "numer = "; numer.to_string();
cout << "denom = " << denomAsInt << endl;
Q = numer/denomAsInt;
cout << "quotient = "; Q.to_string();
rem = numer%denomAsInt;
cout << "remainder = "; rem.to_string();
cout << endl;
return 0;
}