Question: I am trying to write the code for two overloaded operator*. I have to provide the overloaded operators for performing multiplication with BigInt numbers. The

I am trying to write the code for two overloaded operator*. I have to provide the overloaded operators for performing multiplication with BigInt numbers.

The first BigInt::operator* is just for multiplying numbers from 0 to 10 while the second one multiplies all other numbers.

This is what I currently have for the code. I am not sure how to fix it or solve the issue to allow it work correctly.

BigInt BigInt::operator* ( char digit ) const // Multiplication by digit, '0' <= digit <= '9' Single Digits { // add *this # of times and loop through a loop and add it # of times //needs to take the sign of *this to the variable we create if (digit == '0') return BigInt(); // calls default constructor and sets to 0 else if (this->sign == ZERO) return *this; else { BigInt product; product.sign = this->sign; // need loop here for (uint i = 0; i < digits.size(); ++i) { digit[i] } return product; } } BigInt BigInt::operator* ( const BigInt& rhs ) const // Multiplication { BigInt multiply; // ... }

These are the main and .h files I was provided with.

.main file using namespace std; BigInt factorial(BigInt n); int main() { BigInt a(2305), b(-11); char i; for (i = '0'; i <= '9'; ++i) cout << a << " * " << i << " = " << a * i << endl; cout << a << " * " << b << " = " << a * b << endl; while (cin >> a >> b) { cout << a << " * " << b << " = " << a * b << endl; } cout << endl << "Factorials" << endl; BigInt n(0); for ( ; n < BigInt(21); n = n + 1) { if (n < BigInt(10)) cout << ' '; cout << n << "! = " << factorial(n) << endl; } return EXIT_SUCCESS; } BigInt factorial(BigInt n) { if (n == BigInt(0)) return BigInt(1); else return n * factorial(n - 1); } 

.h file #include  #include  #include  using namespace std; typedef enum {NEGATIVE, ZERO, POSITIVE} Sign; bool isInt(string s); class BigInt { friend ostream& operator<<( ostream& output, const BigInt& ); friend istream& operator>>( istream& input, BigInt& ); public: BigInt(); // constructor; digits = 0 BigInt( int num ); // constructor; digits = num BigInt( const string str ); // constructor; digits = str BigInt( const BigInt& other ); // copy constructor bool operator==( const BigInt& rhs ) const; // Equality bool operator< ( const BigInt& rhs ) const; // Less Than BigInt operator+ ( const BigInt& rhs ) const; // Addition BigInt operator- ( const BigInt& rhs ) const; // Subtraction BigInt operator* ( char digit ) const; // Multiplication by digit // '0' <= digit <= '9' BigInt operator* ( const BigInt& rhs ) const; // Multiplication private: Sign sign; // Sign of # deque digits; // Deque of digits of # }; #endif

I would really appreciate the help. Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!