Assignment 2 - Big Ints

Objective

In C++, integers have size limits, which are dependent on the machine and compiler. On cinnamon, an integer is 4 bytes. The biggest integer type, long long, is 8 bytes or 64 bits. This type can hold values up to 2^64 - 1, or 18446744073709551615. If we want to store values larger than this, we can't use any built in type to do it.

Your task for this assignment is to write a class, called BigInt that can store non-negative numbers of any size, from 0 all the way up without limit (although, at some point, a computer can run out of memory). Your class will store the digits of the number in a dynamic array, and provide a number of operators to allow users of the class to use it like a built-in int.

The use of this class is demonstrated in this main program which you can use to test your BigInt class. For this program, you aren't writing your own main function, you can simply use the one provided.

Details

1. The BigInt class should store the number as a dynamic array of digits. Your class must allocate and de-allocate memory correctly, without memory leaks or errors. You also should not allocate more memory than is necessary.
2. Your class should have a default constructor (one with no parameters) that sets the BigInt to the value of 0.
3. There must be another constructor that takes an unsigned int as a parameter and sets the BigInt to the value of the parameter.
4. A third constructor must take a C-String as a parameter and set the BigInt to the value of the string (you can assume that the string contains only digits). This will allow us to create BigInts that won't fit in standard integers such as:
BigInt large("10000000000000000000000000");
5. Your class should have a copy constructor, destructor and assignment operator.
6. In order to print BigInt objects, you must overload the output operator <<. This should print the number itself as if it were an int. Don't output any extra text.
7. Likewise, your class should overload the input operator >> to allow for inputting BigInt objects. To do this, you can assume the user will enter fewer than 100 digits and will not enter any non-digits. Your operator should initially read in the number as a string and convert it into the BigInt.
8. You should overload each of the six comparison operators (<, <=, >, >=, ==, !=). Each of these should return a boolean value, and use the usual meaning of comparison for numbers.
9. You must overload the addition operator, to add two BigInt objects. The operator should return a BigInt object for the sum. You should use the same algorithm that you use to add numbers using pencil and paper - and remember to carry!
10. All BigInts will be non-negative!

Tips

• Start this program early!
• You can store your digits as integers or characters. For example the digit 7 can be stored as an actual 7, or as '7' (ASCII code 55). Using integers will make the addition easier, using characters will make I/O easier.
• You can make the digit in location 0 the most significant digit or the least significant digit. Some functions will be easier one way and others the other way. Be sure to be consistent!
• I would suggest writing the functions in the following order:
1. The constructors.
2. The output operator.
3. The copy constructor, assignment operator and destructor.
4. The comparison operators.
6. The input operator.
• Test each function after writing it.

Extra Credit

For extra credit, also provide an overload of the multiplication operator to multiply two BigInt objects and return the product as a BigInt object.

General Requirements

• No global variables other than constants.
• All member data of a class must be private.