Question: how to fix add function based on the test cases and output. BigInteger BigInteger::add ( const BigInteger& N ) const { / / Initializing variables
how to fix add function based on the test cases and output. BigInteger BigInteger::addconst BigInteger& N const
Initializing variables to store the result and carry
BigInteger result;
int carry ;
Creating copies of the List objects to avoid modifying the originals
List thisDigits digits;
List NDigits Ndigits;
Initialize cursors for both BigIntegers
thisDigits.moveBack; Move to the back to start from the end
NDigits.moveBack;
For finding out the sign of the result
int resultSign signum;
Scroll through the digits of the two BigInteger numbers one by one
while thisDigitsposition NDigits.position carry
Calculating sum of digits plus carry
int sum carry;
if thisDigitsposition
sum thisDigits.peekPrev;
thisDigits.movePrev;
if NDigitsposition
sum NDigits.peekPrev;
NDigits.movePrev;
Update the report and add the total to the result
carry sum base;
result.digits.insertAfterabssum base;
Set the sign of the result
result.signum resultSign;
Changing the sign based on result
if resultSign
result.signum carry : ;
else if carry && result.signum
result.signum result.signum;
else if carry && result.signum
result.signum result.signum;
return result;
These are the test cases: case Addtest:
Adding numbers fall into one of cases, denote pos positive number,
neg negative number
pos pos pos
pos neg
neg pos
neg neg neg
A BigInteger;
B BigInteger;
pos pos pos
D BigInteger;
C A B;
if C D
return ;
add a positive and a negative integer
pos neg
B BigInteger;
C A B;
if Csign
return ;
pos neg
B BigInteger;
D BigInteger;
C A B;
if Csign
return ;
if C D
return ;
pos neg
B BigInteger;
D BigInteger;
C A B;
if Csign
return ;
if C D
return ;
neg neg neg
A BigInteger;
D BigInteger;
C A B;
if C D
return ;
return ;
This is teh output: A
B
C
Killed
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
