Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HugeInteger Class Create a class HugeInteger that uses a 40-element array of dig

ID: 3728871 • Letter: H

Question

HugeInteger Class

Create a class HugeInteger that uses a 40-element array of digits to store integers as large as 40 digits each.

Provide friends member functions input, output, add, subtract, multiply, divide and reminder.

For comparing HugeInteger objects, provide functions isEqualTo, isNotEqualTo, isGreaterThan, isLessThan, isGreaterThanOrEqualTo and isLessThanOrEqualTo—each of these is a “predicate” function that simply returns true if the relationship holds between the two HugeIntegers and returns false if the relationship does not hold. Also, provide a predicate function isZero.

Overload input, output, arithmetic, equality and relational operators so that you can write expressions containing HugeInteger objects, rather than explicitly calling member functions.

Add comments (preconditions, postconditions, and purpose for each function) as needed to make your code understandable. Run a sample output. It is always a great idea to have a sample output with default values in the driver cpp file and a menu to have the user selects the operator to be checked. Paste your code and your sample outputs into a word document or a pdf. And upload. Remember, validate your entry whenever there is a user’s entry.

This is a sample driver cpp file

// HugeInt test program.
#include <iostream>
#include "Hugeint.h"
using namespace std;
int main() {
HugeInt n1{7654321};
HugeInt n2{7891234};
HugeInt n3{"99999999999999999999999999999"};
HugeInt n4{"1"};
HugeInt n5{"12341234"};
HugeInt n6{"7888"};
HugeInt result;
cout << "n1 is " << n1 << " n2 is " << n2
<< " n3 is " << n3 << " n4 is " << n4
<< " n5 is " << n5 << " n6 is " << n6
<< " result is " << result << " ";
//test the non member arithmetic function
//Include your test with an output
// test relational and equality operators
if (n1 == n2) {
cout << "n1 equals n2" << endl;
}
if (n1 != n2) {
cout << "n1 is not equal to n2" << endl;
}
if (n1 < n2) {
cout << "n1 is less than n2" << endl;
}
if (n1 <= n2) {
cout << "n1 is less than or equal to n2" << endl;
}
if (n1 > n2) {
cout << "n1 is greater than n2" << endl;
}
if (n1 >= n2) {
cout << "n1 is greater than or equal to n2" << endl;
}
result = n1 + n2;
cout << n1 << " + " << n2 << " = " << result << " ";
cout << n3 << " + " << n4 << " = " << (n3 + n4) << " ";
result = n1 + 9;
cout << n1 << " + " << 9 << " = " << result << endl;
result = n2 + "10000";
cout << n2 << " + " << "10000" << " = " << result << endl;
result = n5 * n6;
cout << n5 << " * " << n6 << " = " << result << endl;
result = n5 - n6;
cout << n5 << " - " << n6 << " = " << result << endl;
result = n5 / n6;
cout << n5 << " / " << n6 << " = " << result << endl;
/*write an arithmetic expression that involves multiple operations on
different objects at once and output the result*/
}// HugeInt test program.
#include <iostream>
#include "Hugeint.h"
using namespace std;
int main() {
HugeInt n1{7654321};
HugeInt n2{7891234};
HugeInt n3{"99999999999999999999999999999"};
HugeInt n4{"1"};
HugeInt n5{"12341234"};
HugeInt n6{"7888"};
HugeInt result;
cout << "n1 is " << n1 << " n2 is " << n2
<< " n3 is " << n3 << " n4 is " << n4
<< " n5 is " << n5 << " n6 is " << n6
<< " result is " << result << " ";
//test the non member arithmetic function
//Include your test with an output
// test relational and equality operators
if (n1 == n2) {
cout << "n1 equals n2" << endl;
}
if (n1 != n2) {
cout << "n1 is not equal to n2" << endl;
}
if (n1 < n2) {
cout << "n1 is less than n2" << endl;
}
if (n1 <= n2) {
cout << "n1 is less than or equal to n2" << endl;
}
if (n1 > n2) {
cout << "n1 is greater than n2" << endl;
}
if (n1 >= n2) {
cout << "n1 is greater than or equal to n2" << endl;
}
result = n1 + n2;
cout << n1 << " + " << n2 << " = " << result << " ";
cout << n3 << " + " << n4 << " = " << (n3 + n4) << " ";
result = n1 + 9;
cout << n1 << " + " << 9 << " = " << result << endl;
result = n2 + "10000";
cout << n2 << " + " << "10000" << " = " << result << endl;
result = n5 * n6;
cout << n5 << " * " << n6 << " = " << result << endl;
result = n5 - n6;
cout << n5 << " - " << n6 << " = " << result << endl;
result = n5 / n6;
cout << n5 << " / " << n6 << " = " << result << endl;
/*write an arithmetic expression that involves multiple operations on
different objects at once and output the result*/

Explanation / Answer

#include<iostream>
using namespace std;
class HugeInteger{
   public:
   int digit[40]={0,0};
   public:
       friend void input(int);
       friend void output(int);
       friend void add(int);
       friend void substract(int);
       friend void multiply(int);
       friend void division(int);
  
};
bool isEqualTo(HugeInteger a,HugeInteger b){
   int i;
   for(i=39;i>-1;i--)if(a.digit[i]!=b.digit[i])return false;
   return true;
          
}

// I've Tried my level best to achieve your requirements . you can get them from this code .


bool isNotEqualTo(HugeInteger a,HugeInteger b){
   int i;
   for(i=39;i>-1;i--)if(a.digit[i]!=b.digit[i])return true;
   return false;      
}
bool isGreaterThan(HugeInteger a,HugeInteger b){
   int i;
   for(i=0;i<39;i++)
       if(a.digit[i] > b.digit[i])return true;
       else if(a.digit[i] == b.digit[i]) printf();
       else   return false;
   return false;   //since everything is equal  
}
bool isLessThan(HugeInteger a,HugeInteger b){
   int i;
   for(i=0;i<39;i++)
       if(a.digit[i] < b.digit[i])return true;
       else if(a.digit[i] == b.digit[i]) printf();
       else   return false;
   return false;   //since everything is equal      
}
bool isGreaterThanOrEqualTo(HugeInteger a,HugeInteger b){
   int i;
   for(i=0;i<40;i++)if(a.digit[i] < b.digit[i])return false;
   return true;
          
}
bool isLessThanOrEqualTo(HugeInteger a,HugeInteger b){
   int i;
   for(i=0;i<40;i++)if(a.digit[i] > b.digit[i])return false;
   return true;
                  
}
HugeInteger HugeInteger::operator+ (const HugeInteger& c) const
{
      HugeInteger result;
      int i,a=0;
      for(i=39;i>0;i--){
         result.digit[i]=(this.digit[i]+c.digit[i]+a);
         a=result.digit[i]/10;
         result.digit[i]%=10;
      }
       result.digit[i]=(this.digit[i]+c.digit[i]+a);
      return result;
}HugeInteger HugeInteger::operator- (const HugeInteger& c) const
{
      HugeInteger result;
      int i,a=0;
      for(i=39;i>-1;i--){
         result.digit[i]=(this.digit[i]-c.digit[i]);
         a=result.digit[i]/10;
         result.digit[i]%=10;
      }
      return result;
}

// I hope it'll helpful to some extent . Thanks In advance

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote