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: 3727470 • 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

The assignment says "uses a 40-element array of digits to store integers". I read that as saying that HugeInteger has an int bigNumber[40] and I would expect the constructor to initialize it to all zeroes.

Input() will fill in bigNumber from the user's input. For example "123" from the user would result in
bigNumber[37] == 1
bigNumber[38] == 2
bigNumber[39] == 3

#include <iostream>

const int ARRAY_SIZE = 40;

class HugeInteger
{
public:
HugeInteger(); //constructor
void input();   
private:
int bigNumber[ARRAY_SIZE];
};

//
// Default Constructor
//
HugeInteger::HugeInteger()
{
// Clear bigNumber to zeroes
}
//
// Get a value from the user
//
void HugeInteger::input()
{
// Get a string from the user
// Make sure the string contains nothing but numbers
// Don't worry about negative numbers at first, we'll do that shortly
// Fill in bigNumber from the user's input
}//end input function

void main() {
HugeInteger a; a.input();
}

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