Question: C++ (Huge Integer Class) Create a class Huge Integer that uses a 40-element array of digits to store integers as large as 40 digits each.

C++ (Huge Integer Class) Create a class Huge Integer that uses a 40-element array of digits to store integers as large as 40 digits each. Provide member functions input, output, add, and subtract. For comparing Huge Integer objects, provide member functions isEqualTo, isNotEqualTo, isGreaterTha, isLessTha, isGreaterThanOrEqualTo, isLessThanOrEqualTo -- each of these is a "predicate" fucntion that simply returns true if the relationship holds between the two Huge Integers and returns false if the relationship does not hold. Also provide predicate funciton is Zero.

The files needed are main.cpp, HugeInteger.h, and HugeInteger.cpp

The main.cpp is provided below:

#include #include "HugeInteger.h" // include definition of class HugeInteger using namespace std;

int main() { HugeInteger n1{7654321}; // HugeInteger object n1 HugeInteger n2{"100000000000000"}; // HugeInteger object n2 HugeInteger n3; // HugeInteger object n3 HugeInteger n4{5}; // HugeInteger object n4 HugeInteger n5; // HugeInteger object n5 // outputs the sum of n1 and n2 n5 = n1.add(n2); cout << n1.toString() << " + " << n2.toString() << " = " << n5.toString() << " ";

// assigns the difference of n2 and n4 to n5 then outputs n5 n5 = n2.subtract(n4); cout << n2.toString() << " - " << n4.toString() << " = " << n5.toString() << " "; // checks for equality between n2 and n2 if (n2.isEqualTo(n2)) { cout << n2.toString() << " is equal to " << n2.toString() << " "; }

// checks for inequality between n1 and n2 if (n1.isNotEqualTo(n2)) { cout << n1.toString() << " is not equal to " << n2.toString() << " "; }

// tests for greater number between n2 and n1 if (n2.isGreaterThan(n1)) { cout << n2.toString() << " is greater than " << n1.toString() << " "; }

// tests for smaller number between n4 and n2 if (n4.isLessThan(n2)) { cout << n4.toString() << " is less than " << n2.toString() << " "; } // tests for smaller or equal number between n4 and n4 if (n4.isLessThanOrEqualTo(n4)) { cout << n4.toString() << " is less than or equal to " << n4.toString() << " "; }

// tests for smaller or equal number between n4 and n2 if (n4.isLessThanOrEqualTo(n2)) { cout << n4.toString() << " is less than or equal to " << n2.toString() << " "; }

// tests for greater or equal number between n3 and n3 if (n3.isGreaterThanOrEqualTo(n3)) { cout << n3.toString() << " is greater than or equal to " << n3.toString() << " "; } // tests for greater or equal number between n2 and n3 if (n2.isGreaterThanOrEqualTo(n3)) { cout << n2.toString() << " is greater than or equal to " << n3.toString() << " "; } // tests for zero at n3 if (n3.isZero()) { cout << "n3 contains " << n3.toString() << " "; } }

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 Databases Questions!