BigInt class questions part I

Jan 18, 2013 at 6:20am
Ok so here is a snippet of the code my question is how do i return the value i am adding two int array together inside this method at least this is where i think it should happen. it has been over a year sense any programming classes first one back so any light on the subject wold be great,I am still pretty new at this so explicit explanation would be great,thanks

[code][code]
BigInt BigInt::add(const BigInt& rightOperand) const {
BigInt objToReturn;
//Do add logic here
( this is where i have my array of ints adding )
I dont know why this code below is here except for explanation of the two arrays??

//num1 is the this object
cout << this->numArr[99];
//num2 is the rightOperand object
cout << rightOperand.numArr[99];
when I am done how do i return my temp_arr to the oobjToReturn?
return objToReturn;
Jan 18, 2013 at 12:13pm
so why do you want to return a new value? why not apply the add operation on the current object and return nothing/void?

cout << this->numArr[99];
Are you aware that this will output the 100th element, not the whole array

Edit: and remove the const after add, it doesn't make sense
Last edited on Jan 18, 2013 at 12:20pm
Jan 18, 2013 at 2:28pm
coder777 wrote:
so why do you want to return a new value? why not apply the add operation on the current object and return nothing/void?

Because that's the way an add operation works. The name isn't addEqual.

and remove the const after add, it doesn't make sense

Yes it does.
Jan 19, 2013 at 5:18am
this was code that was given to us by the instructor, I realize the array dose not print out like it is. but how do I get my int array to load into the object to get it to return??? coder777 it is a const on the out side to protect the num array being passed in right or am I thinking wrong???
Jan 22, 2013 at 7:25am
well, ok, const...

what you need to do is assign this to objToReturn:

objToReturn = *this;

to perform the addition you might store each digit in its own field of the array.
You need another variable that tells how many digits are stored.
I suggest that you store the least significant digit first.
so use a loop to add each field. if > 9 -> carry to next field
Topic archived. No new replies allowed.