Question: Huge Integer (27%) (as one dimensional array) Deitel showed at tend of chapter 10 this homework assignment Java language supports a BigInteger class so that

Huge Integer (27%) (as one dimensional array)

Deitel showed at tend of chapter 10 this homework assignment

Java language supports a BigInteger class so that there is no overflow problem when you have integers of twenty, thirty digits (however very big integers of like say 2,000 digits will still cause some problem in the speed of calculation and the storage). C# also supports that as shown in .NET.

Instead of the 40 element HugeInteger array that Deitel mentioned, lets start small with 5 digits (which is common int type integer), but we use one dimensional array of 5 elements.

(12%) Create a C# class HugeInteger of 5 element array. Here an int array of 5 elements like {1, 2, 3, 4, 5} can represent either the integer 12345 or the integer 54321. Please clearly state which way you want to do.

Lets suppose your {1, 2, 3, 4, 5} means 54321 using an int array of 5 elements. This is very similar to the sum of two polynomials as in Q4, except if we add {1, 2, 5, 5, 4} and { 1, 2, 5, 5, 4} as two polynomials, we get {2, 4, 10, 10, 8} since the sum of polynomials 4x4 + 5x3 + 5x2 + 2x + 1 and 4x4 + 5x3 + 5x2 + 2x + 1 is 8x4 + 10x3 + 10x2 + 4x + 2, but if we add {1, 2, 5, 5, 4} and { 1, 2, 5, 5, 4} as two HugeIntegers of 5 digits, then we get {2, 4, 0, 1, 9} since 45521 + 45521 = 91042 as a 5 digits integer.

(4%) Define the HugeInteger class with 5 elements arrays. Add either Input method that Deitel suggested or a constructor from integer like HugeInteger (int a), that will convert integer 54321 to the array {1, 2, 3, 4, 5}.

(8%) Create the Sum method of two HugeIntegers of 5 elements (5 digits). Note {1, 2, 5, 5, 4} + {1, 2, 5, 5, 4} = {2, 4, 0, 1, 9}. We do not worry about the overflow case at this moment, i.e. {1, 2, 3, 4, 5} + {1, 2, 3, 4, 5} = {2, 4, 6, 8, 10} or {2, 4, 6, 8, 0, 1}, a HugeInteger array of 6 elements

(15%) Deitel did not seem to consider the case that HugeInteger can be negative such as -54321.

(3%) Enhance class HugeInteger to have an attribute sign, which is 1 for positive integer, -1 for negative integer 9an d1 for zero). You can also define sign to be Boolean.

(12%) Define Subtract method that calculates the difference of two HugeInteger of 5 digits. These two HugeIntegers can be positive or negative. The difference can be positive or negative. Also enhance your Sum method to handle the signs.

Test your subtract method and sum method (now with the sign) with two pairs of HugeIntegers: 54321 32176 (i.e. {1, 2, 3, 4, 5} sub {6, 7, 1, 2, 3}; and -12345 sum 23456, the first number is the negative 12345, or {5, 4, 3, 2, 1; -}, and the second number is the positive 23456, or {6, 5, 4, 3, 2: +}.

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!