4-1 Motivation:

The C++ long int can only take up to 64 bits of information, which may not be enough for some scientic computation. In this project, we will design and implement a class named LargeInt which will overcome these problems. The requirement for this project is to use LargeInt at almost all situations when int is used.

4-2 Requirements:

As int, LargeInt can be zero, positive or negative. Unlike int, LargeInt has innite precision and can hold as many digits as possible. The digits are represented by char, and are stored in a dynamically allocated array.

The size of the array can be larger than the actual number of digits in the number. For example, to add two LargeInt a1 and a2, the resulted LargeInt can have max(a1.len,a2.len) + 1 bytes allocated as the digit array, which is long enough to handle any overow. LargeInt should have the following operators:

4-2-1 Constructors and destructor

There are 3 constructors:

1. default constructor will set the LargeInt to zero

2. copy constructor to take another LargeInt as the argument, because we are working with a dynamically allocated array, you must perform deep copy.

3. constructor to take a long long as the argument, and transfer this long long as digits (char) and store the digits in the array. The argument can be positive, negative, or zero, so your LargeInt must be able to reect the sign of the argument.

C++ allows only one version of destructor, and it should delete the char array.

4-2-2 +, -operators (no need for *, / and %):

These operators should perform exactly as their counter parts in int, i.e.

long long a = 1000000;
LargeInt i1(a);
LargeInt i2(100);
LargeInt i3; i3 = i1 + i2;
cout << i3; // should output 1,000,100;

Each of these operators should take two const LargeInt& as arguments and return a LargeInt. These operators should be designed and implemented as friend operators. It has no requirement to overload these operators. For example:

long long a = 1000000;
LargeInt i1(a);
LargeInt i2; i2 = i1 + 100; //compiler will transfer 100 to a LargeInt,
//so we do not have a + operator to take int as argument.
cout << i2; // should output 1,000,100;

Each of these operators should take a const LargeInt& as argument and return LargeInt&. It has no requirement to overload these operators.

4-2-4 boolean operators !, !=, ==, <, >, <=, >= These operators should perform exactly as their counter parts in int, i.e.

long long a = 1000000;
LargeInt i1(a);
LargeInt i2(100);
if (i2 < i1) cout << "i2 is smaller" << endl;
else cout << "i1 is smaller" << endl;

Each of these operator should take two const LargeInt& as arguments (except the unary operator ! which will take no argument) and return bool. These operators (except !) should be designed and implemented as friend operators. It has no requirement to overload these operators.

4-2-5 incremental operators ++,

These operators should perform exactly as their counter parts in int, and should have two versions (pre-increment and post-increment), i.e.

long long a = 1000000;
LargeInt i1(a);
LargeInt i2(-100);
i1++;
cout << i1; //should output 1,000,001
cout << --i2; //should output -101

4-2-6 << operator

Output the LargeInt in a nice format, i.e.

long long a = 10000000000000000;
LargeInt i1(a);
cout << i1;
//The output should look like:
10,000,000,000,000,000

This operator should be friend (just like what we did in the previous project).

4-2-7 Other requirements:

No need to overload the >> operator.

Comment you code! Indent your code!

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.