Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

2) HugeInteger subtract(const HugeInteger& h): Returns a new HugeInteger representing the difference between this HugeInteger and h.

3) HugeInteger multiply(const HugeInteger& h): Returns a new HugeInteger representing the product of this HugeInteger and h. This method should not be implemented as repeated addition (calculate m*n by adding m, n time) since its too slow.

4) int compareTo(const HugeInteger& h): Returns -1 if this HugeInteger is less than h, 1 if this HugeInteger is larger than h, and 0 if this HugeInteger is equal to h.

5) std::string toString(): Returns a string representing the sequence of digits corresponding to the decimal representation of this HugeInteger. Please make sure this method works in both Lab 1&2. The class HugeInteger must contain at least the following public constructors:

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) 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

Please provide as much explaination as possible for the solution.

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

Students also viewed these Databases questions