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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.