Write a console program that implements this class. In main, write a “driver pro
ID: 3619997 • Letter: W
Question
Write a console program that implements this class. In main, write a “driver program” that fully tests the functionality of the class.class HugeInteger {
public:
// CONSTRUCTORS
HugeInteger( long = 0 ); // limited to $4,294,967,296
HugeInteger( const char * );
// ARITHMETIC OPERATIONS
// addition operator; HugeInt + HugeInt
HugeInteger add( const HugeInteger & );
// addition operator; HugeInt + long
HugeInteger add( long );
// addition operator;
// HugeInt + string that represents large integer value
HugeInteger add( const char * );
// multiply by ten (because its easy to do in base ten)
HugeInteger x10();
// make more x10's for other parameter types,
// also division by ten
// COMPARISON OPERATIONS
bool isEqualTo( HugeInteger & );
bool isNotEqualTo( HugeInteger & );
bool isGreaterThan(HugeInteger & );
bool isLessThan( HugeInteger & );
bool isGreaterThanOrEqualTo( HugeInteger & );
bool isLessThanOrEqualTo( HugeInteger & );
bool isZero(); // return FALSE if zero
// OUTPUT and MISC functions
void print();
bool leadingZeros;
private:
// the data!
// indexes are 0 thru 40, 39 chars and an overflow digit
char digits[41];
};
This is what I have the rest I am so confused.
#include <iostream>
using namespace std;
class HugeInteger {
public:
// CONSTRUCTORS
HugeInteger( long = 0 ); // limited to $4,294,967,296
HugeInteger( const char * );
// ARITHMETIC OPERATIONS
// addition operator; HugeInt + HugeInt
HugeInteger add( const HugeInteger & );
// addition operator; HugeInt + long
HugeInteger add( long );
// addition operator;
// HugeInt + string that represents large integer value
HugeInteger add( const char * );
// multiply by ten (because its easy to do in base ten)
HugeInteger x10();
// make more x10's for other parameter types,
// also division by ten
// COMPARISON OPERATIONS
bool isEqualTo( HugeInteger & );
bool isNotEqualTo( HugeInteger & );
bool isGreaterThan(HugeInteger & );
bool isLessThan( HugeInteger & );
bool isGreaterThanOrEqualTo( HugeInteger & );
bool isLessThanOrEqualTo( HugeInteger & );
bool isZero(); // return FALSE if zero
// OUTPUT and MISC functions
void print();
bool leadingZeros;
private:
// the data!
// 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;
}
}
void HugeInteger::print()
{
char temp[41];
temp[40]=0;
for (int i=0, j=39; i<40; i++,j--)
temp[i] = digits[j];
cout<<temp;
}
HugeInteger::HugeInteger(const char *digitsIn)
{
for(int i=0;i<41;i++)
digits[i]='0';
for(int i=0,j=strlen(digitsIn)-1; j>=0; i++,j--)
digits[i]=digitsIn[j];
}
HugeInteger HugeInteger::add(const HugeInteger & HugeIn)
{
HugeInteger temp;
int carry = 0;
for(int i=0; i<41; i++)
{
int sum=digits[i]-'0'+HugeIn.digits[i]+carry;
temp.digits[i]=sum%10 + '0';
carry = sum/10;
}
return temp;
}
HugeInteger HugeInteger::add(long)
{
HugeInteger temp;
HugeInteger Bob;
temp=this ->add(Bob);
return temp;
}
void main()
{
HugeInteger a(123456789);
a.leadingZeros=false;
a.print();
cout<<" ";
HugeInteger b("1,2,3,4");
HugeInteger c("5,6,7,8");
HugeInteger d;
d=b.add(c);
d.print();
cout<<" ";
}
Explanation / Answer
please rate - thanks I did a few of them to get you startedRelated 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.