Create class HugeInt that is capable of representing positive (non-negative) 30-digit decimal values (this will be able to represent values from 0 to 1030). The 30-digit number can be represented internally as array of integer whereby each digit takes values from zero to nine. The class must have conversion constructor that convert int or char value to HugeInt. Then overload the following operators
a. Stream insertion (<<) and extraction (>>) operators.
b. Arithmetic operators (+,-,/,*). Each operation must also support operation with mix operands (integer and HugeInt objects).
c. Relational operators (==,<=,>=,!=). Each operation must also support operation with mix operands (integer and HugeInt objects).
d. Define a function factorial(X) that calculate factorial of X, whereby X is a HugeInt object.
int main()
{
HugeInt a; //HugeInt object initialized to zero
HugeInt b(12345);
HugeInt c(“100200101002005550”);
HugeInt result;
cin >> a;
result = a+b;
cout << a << “+” << b << “ = “ << result << endl;
result = c – b;
cout << result << endl;
result = c / b;
cout << result << endl;
result = c * b;
cout << result << endl;
if (a ==
cout << “Equal” << endl;
else
cout << “Not Equal” << endl;
if (a >=
cout << “Greater” << endl;
else
cout << “Less” << endl;
if (a <=
cout << “Less” << endl;
else
cout << “Greater” << endl;
if (a !=
cout << “Not Equal” << endl;
else
cout << “Equal” << endl;
factorial(
return 0;
}

New Topic/Question
Reply




MultiQuote



|