Possible duplicate:
Department with really big rooms
I need to overload the / operator to work on two HugeInt objects that are defined simply as an array of 30 shorts. This is homework, by the way, but for several days I was looking for my brain in this problem.
I have already overloaded the * operator:
HugeInt HugeInt::operator*(const HugeInt &op2){ HugeInt temp; short placeProducts[hugeIntSize + 1][hugeIntSize] = {0}; short product; int carry = 0; int k, leftSize, rightSize, numOfSumRows; leftSize = getDigitLength(); rightSize = op2.getDigitLength(); if(leftSize <= rightSize) { numOfSumRows = leftSize; for(int i = (hugeIntSize - 1), k = 0; k < numOfSumRows; i--, k++) { for(int j = (hugeIntSize - 1); j >= k; j--) { product = integer[i] * op2.integer[j] + carry; if (product > 9) { carry = product / 10; product %= 10; } else { carry = 0; } placeProducts[k][j - k] = product; } } } else { numOfSumRows = rightSize; for(int i = (hugeIntSize - 1), k = 0; k < numOfSumRows; i--, k++) { for(int j = (hugeIntSize - 1); j >= k; j--) { product = integer[j] * op2.integer[i] + carry; if (product > 9) { carry = product / 10; product %= 10; } else { carry = 0; } placeProducts[k][j - k] = product; } } } sumProductsArray(placeProducts, numOfSumRows); for(int i = 0; i < hugeIntSize; i++) { temp.integer[i] = placeProducts[hugeIntSize][i]; } return temp;}
But how do I overload / op? My main problem is not C ++ code or syntax, but what my algorithm divides. When I multiply, I can make it a number. I store each product (aka 1 digit of the lower value of each digit above, and then a 10-digit number, each number higher, using my transfer algorithm) in my 2-dimensional array. Each time I get a new product, it shifts to the left by n + 1, which "multiplies" it by the required power of 10. Then I just summarize all the columns.
I canโt understand for my whole life how to code the long separation method. Since I am dealing with two arrays, it should be digit by digit, and I suspect that it can be as simple as reversing the multiplication algorithm. Nested loops and subtraction? Do I need a variable for private and reminder? Is there a better method? I just have to be directed in the right direction.
source share