Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started