Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define and implement a class HugeInteger that represents integers of 300 digits and a few simple operations on them, as indicated below. You will continue

Define and implement a class HugeInteger that represents integers of 300 digits and a few simple operations on them, as indicated below.

You will continue to modify and otherwise develop this program in the future assignments. For now define a static constant hugeIntegerSize = 300.

The integers are to be represented, in decimal notation, by a private data structure that consists of

A byte array of decimal digits 0-9, of which the position of a digit equals to the corresponding power of 10.

The integers sign (i.e., plus or minusan enum type).

(Note, that we use the type byte rather than char because we are going to use the native addition and multiplication of digits.)

.

2.1 Basic operations

The following operations should be supported: 2

A constructor HugeInteger(int length) for creating a Huge Integer of given length that consists of zeros.

A constructor HugeInteger(String str) for creating a Huge Integer, given a string of its digits.. For this exercise you will have to use some standard String operations described in the book.

An operation int getLength() for determining the length of a Huge Integer.

An operation byte getDigit(int index) for obtaining a digit of a Huge Integer given its index. The starting index is 0. If the index is out of bounds, then a message should be printed on the screen indicating this fact.

An operation void print(HugeInteger i), which, if the number is negative, prints - followed by the numbers digits. (The + sign is superfluous for positive numbers and meaningless for 0.) Note that the number has to be printed from right to left as the least significant digit is on the left.

An operation String toString() for transforming a Huge Integer to a String. With that, if the number is negative, the first character in the string should be - . (The + sign is superfluous for positive numbers and meaningless for 0.) Note that the number has to be inserted into a string from right to left as its least significant digit is on the left.

An assignment operation, void Assign(HugeInteger i), which copies the value of the operand i. (It might make sense to allow that operation to use any integernot only a Huge Integer.

Boolean operations for equality check as well as greaterThan and lessThan relatation. (Note that the comparison has to be performed digit-by-digit).

Arithmetic operations Add, Subtract, and Mult. All operations have to be performed digit-by-digit, propagating the carry. In case of the overflow, you need to throw an exception. (Mult is the most complex operation, naturally, but at this point you dont have to do anything ingeniousprogram it in the most straight-forward way possible.)

Start thinking about how you would implement the Integer division operation Divide. If you have time, implement it; otherwise, leave it for later. To this end, feel free to use any algorigthm that you can find on the Web, but make sure that you implement it yourself.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Name four requirements for a spin-off to qualify as tax- free.

Answered: 1 week ago

Question

a neglect of quality in relationship to international competitors;

Answered: 1 week ago