Consider the class HugeInt. The class enables operations on integers larger than
ID: 3902009 • Letter: C
Question
Consider the class HugeInt. The class enables operations on integers larger than the largest 32 bit integer.( About 2 billions).
a) Test all capabilities of this class and describe precisely how it operates and what restrictions it has.
b) Overload multiplication and division for this class. Overload the relational (> and <), assignment (=) and equality (==) operators for this class.
Please help solve the problem using c++. The link to HugeInt is here:
https://www.chegg.com/homework-help/c-how-to-program-6th-edition-chapter-19-problem-9e-solution-9780136123569?trackid=29e9b088&strackid=602b1804&ii=8
Explanation / Answer
The class basically works on string. It takes string as big int input and internally converts it to integer. You can see its constructor where it is converting string to integer. Whenever the input string already has a character which is digit like 0-9 then it simply copies to integer array else it subtracts ascii value and stores.
It has restriction which basically disallows it to check erraneous character. For example, the code will do unwanted things if the input string has characters like #,$, etc. I think the code will fail to compile as it is accessing private member directly in operator+.
Overload =:
HugeInt::operator= (HugeInt rhs){
for (int i = 0; i < digits; i++)
this.integer[i] = rhs.integer[i]
}
Overload <:
HugeInt::operator< (HugeInt rhs) {
for (int i = 0; i < digits; i++) {
if (rhs.integer[i] == this.integer[i])
continue;
else if (rhs.integer[i] < this.integer[i])
return True;
else return False;
}
Overload >:
HugeInt::operator> (HugeInt rhs) {
for (int i = 0; i < digits; i++) {
if (rhs.integer[i] == this.integer[i])
continue;
else if (rhs.integer[i] > this.integer[i])
return True;
else return False;
}
==:
HugeInt::operator==(HugeInt rhs)
for (int i = 0; i < digits; i++) {
if (rhs.integer[i] == this.integer[i])
continue;
else return false;
}