Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would you overload the == operator in C++? With a BigInt array and an int? T

ID: 3718437 • Letter: H

Question

How would you overload the == operator in C++? With a BigInt array and an int?
This is what I have as the method parameters
bool BigInteger:: operator==(const int& n)const { }
Just wondering about the logic of comparing a BigInt array versus an int n How would you overload the == operator in C++? With a BigInt array and an int?
This is what I have as the method parameters
bool BigInteger:: operator==(const int& n)const { }
Just wondering about the logic of comparing a BigInt array versus an int n How would you overload the == operator in C++? With a BigInt array and an int?
This is what I have as the method parameters
bool BigInteger:: operator==(const int& n)const { }
Just wondering about the logic of comparing a BigInt array versus an int n

Explanation / Answer

bool BigInteger:: operator==(const int& n)const
{
   int i = NUMDIGITS-1;
   int t = n;
   while ( i > 0 && t > 0){ // compring from right end
        if(digits[i] != t%10)
            return false;
        i--;
        n = n/10;
   }

   return true;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote