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


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 Huge Integer 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. Additionally, you have to measure experimentally the running times of the operations implemented in your Huge Integer class and compare them with the measured running times of the corresponding operations provided by boost::multiprecision::cpp_int class. SPECIFICATIONS: The class Huge Integer must contain at least the following public methods: 1) Huge Integer add(const Huge Integer& h): Returns a new Huge Integer repre- senting the sum of this Huge Integer and h. 2) Huge Integer subtract(const Huge Integer& h): Returns a new Huge Integer representing the difference between this Huge Integer and h. 3) Huge Integer multiply(const Huge Integer& h): Returns a new Huge Integer representing the product of this Huge Integer and h. This method should not be implemented as repeated addition (calculate m*n by adding m, n time) since it's too slow. 4) int compareTo(const Huge Integer& h): Returns -1 if this Huge Integer is less than h, 1 if this Huge Integer is larger than h, and 0 if this Huge Integer is equal to h. 5) std::string toString(): Returns a string representing the sequence of digits corresponding to the decimal representation of this Huge Integer. Please make sure this method works in both Lab 1&2. The class Huge Integer must contain at least the following public constructors: 1) Huge Integer(const std::string& val) creates a Huge Integer 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) Huge Integer(int n) creates a random Huge Integer 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
