Question
MUST BE WRITTEN IN C# Instead of the 40 element HugeInteger array that Deitel mentioned, lets start small with 5 digits (which is common int
MUST BE WRITTEN IN C#
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.
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.
a) (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}.
b) (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
Deitel did not seem to consider the case that HugeInteger can be negative such as -54321.
c) (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.
d) (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: +}.
10.10 (HugeInteger Class) Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods Input, ToString, Add and Subtract. For comparing HugeInteger objects, provide the following methods: IsEqualTo, IsNotEqualTo, IsGrea- terThan, IsLessThan, IsGreaterThanorEqualTo and IsLessThanorEqualTo. Each of these is a meth- od that returns true if the relationship holds between the two HugeInteger objects and returns false if the relationship does not hold. Provide method IsZero. If you feel ambitious, also provide methods Multiply, Divide and Remainder. In the Input method, use the string method ToChar- Array to convert the input string into an array of characters, then iterate through these characters to create your HugeInteger. [Note: The .NET Framework Class Library includes type BigInteger for arbitrary sized integer values.]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started