I need to Multiply my HugeInteger by 10... And I\'m really stuck on how I should
ID: 3619970 • Letter: I
Question
I need to Multiply my HugeInteger by 10... And I'm really stuck on how I should do it. I think I need to shift all numbers over by one but I just cant seem to get it working...Here's what I have so far (With certain unrelated parts removed):
class HugeInteger {
public:
// CONSTRUCTORS
HugeInteger( long = 0 );
HugeInteger( const char * );
//.....
HugeInteger x10(); //multiply a HugeInteger by 10
//....
// OUTPUT and MISC functions
void print();
char* getDigits();
private:
// indexes are 0 thru 40, 39 chars and an overflow digit
char digits[41];
};
HugeInteger::HugeInteger(long L)
{
for(int i = 0; i < 41; i++)
{
int digit = L % 10;
digits[i] = digit + '0';
L = L / 10;
}
}
HugeInteger::HugeInteger(const char * digitsIn)
{
//must prefill w/0's
for(int i = 0; i < 41; i++)
{
digits[i] = '0';
}
//rea; fill/copy digits
for(int i = 0, j = strlen(digitsIn) - 1; j >= 0; i++, j--)
{
digits[i] = digitsIn[j];
}
}
//......
void HugeInteger::print()
{
char temp[41];
temp[40] = 0; //null term
for( int i = 0, j = 39; i < 40; i++, j--)
{
temp[i] = digits[j];
}
cout << temp;
}
char* HugeInteger::getDigits()
{
return digits;
}
void main()
{
HugeInteger A( 45658234568 );
HugeInteger B( "7834" );
HugeInteger C( 12 );
//...
}
Explanation / Answer
please rate - thanks changes are in redRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.