I'm very new to classes and while I have all other code written, I am stuck lacking some implementation at the end of two of my member functions.
Here is my header:
class bignum
{
public:
// Constructors.
bignum();
bignum(int num_digits);
bignum(const string &digits);
bignum(const bignum &other);
// Destructors.
~bignum();
// Assignment operator.
bignum &operator=(const bignum &other);
// Accessors
int digits() const;
int as_int() const;
string as_string() const;
void print(ostream &out) const;
bignum add(const bignum &other) const;
bignum multiply(const bignum &other) const;
bool equals(const bignum &other) const;
int PublicNumberTest;
private:
// Pointer to a dynamically-allocated array of integers.
int *digit;
// Number of digits in the array, not counting leading zeros.
int ndigits;
};
#endif
and here is one of my member functions:
bignum bignum::multiply(const bignum& other) const{
bignum product;
bignum row;
int carry = 0;
int sum = 0;
int j = 0;
int *temp_row = new int[];
for (int i = 0; i < ndigits-1; i++){
carry = 0;
temp_row[i] = 0;
for (j; j < other.digits - 1; j++){
sum = digit[i] * other.digit[j] + carry;
temp_row[i + j] = sum % 10;
carry = sum / 10;
}
if (carry>0)
temp_row[i + j] = carry;
row = row operator+temp_row //This is what I don't understand. How can I
product = product.add(row); //assign the contents of temp_row?
}
}
There is another, but it is basically the same problem. I have an array that I would like to copy to the contents of and place inside of my...class? I guess? Thanks for reading.