Question: C++ coding Description: The range of integers that can be represented in C++ using a primitive data type is only from 263 to 263 1.

C++ coding

Description: The range of integers that can be represented in C++ using a primitive data type is only from 263 to 263 1. What if we need to manipulate integer values beyond this range?

In this assignment you will write a HugeInteger class which is able to represent arbitrar- ily large integer numbers. This class must implement arithmetic operations on integers such as addition, subtraction, multiplication and comparison. You have to implement this class without using C++ predefined classes, unless specified otherwise.

Specifications: The class HugeInteger must contain at least the following public methods:

1) HugeInteger add(const HugeInteger& h): Returns a new HugeInteger repre- senting the sum of this HugeInteger and h.

Additionally, you have to measure experimentally the running times of the operations implemented in your HugeInteger class and compare them with the measured running times of the corresponding operations provided by boost::multiprecision::cpp int class.

The class HugeInteger must contain at least the following public constructors:

  1. 1) HugeInteger(const std::string& val) creates a HugeInteger from the decimal string representation val. The string contains an optional minus sign at the beginning followed by one or more decimal digits. No other characters are allowed in the string.

  2. 2) HugeInteger(int n) creates a random HugeInteger of n digits, the first digit being different from 0; n must be larger or equal to 1.

Each constructor must throw an exception if the argument passed to the constructor does not comply to the specifications. In your solution, you may use C++ API methods for string manipulation and for pseudo-random number generation. You can also use std::vector if necessary.

Plz use class and object to make constructors and finish the add method !! Need a test case and explanations will be better!

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!