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

I need help with the operator+ function. Please provide code and some comments s

ID: 3539304 • Letter: I

Question

I need help with the operator+ function. Please provide code and some comments so I can understand the flow. The add_assign (operator+=) is already completed and listed below. The BigInt class (private variable is _digits) is also completed. Please contact me if you need any additional information.


BigInt operator+(const BigInt&, const BigInt&)
{
//The BigInt object which the function is called on does not have its value changed (no side effect). Create a BigInt object that is //a copy of the left operand object. To the created BigInt object add the value of the parameter, use add_assign. Return the //BigInt object that was created.

return *this;
}


Explanation / Answer

i use this operator in program that describe its functionality and mechanism


BigInt::BigInt(const char* right) {
//Initialize
for (int i = 0; i < 100; i++) {
this->numArr[i] = 0;
}

//Pass to olOp=
this->operator=(right);
}

ostream &operator<<(ostream &stream, BigInt temp)
{
//Display useful numbers
for (int i = 0; i < 100; i++) {
stream << temp.numArr[i];
}

return stream;
}

BigInt::BigInt() {
//Initialize all values of numArr to 0
for (int i = 0; i < 100; i++) {
numArr[i] = 0;
}
}

//Overloaded = Operator
BigInt BigInt::operator=(const char* inputString) {
int origin = 100 - strlen(inputString);

//Check negative
if (inputString[origin-1] == '-') { //-83
//Change minus to a 0
this->numArr[origin-1]=0;

}

//Assign digitized Cstrings to BigInt's numArr
for (int i = origin, k = 0; i<100; i++, k++) {
char tempChar = inputString[k];
this->numArr[i] = atoi(&tempChar);
}
this->toTensComplement();
return* this;
}

char* BigInt::print(){

for (int i = 0; i<100; i++) {
cout << numArr[i];
}
cout << endl;
return "";
}

BigInt BigInt::add(BigInt right) {
//Declaration
BigInt tempInt = "0";

//Loop from right to left
for (int i = 100; i>0; i--) {
tempInt.numArr[i] += this->numArr[i] + right.numArr[i];
if (tempInt.numArr[i] > 9) {
//Reduce by 10
tempInt.numArr[i] -= 10;
tempInt.numArr[i-1] = tempInt.numArr[i-1]+1;
}
}
return tempInt;
}