Question
No use of vector,,, an incomplete class is given in description,,,, no sign convention when adding or subtraction,,,, all number user input are positive and
No use of vector,,, an incomplete class is given in description,,,, no sign convention when adding or subtraction,,,, all number user input are positive and second BigInteger is always smaaler than the first one.,,, Read the description carefully....
Problem: Big Integer Arithmetic
This problem asks you to create a custom data type to handle large integer arithmetic, by creating a custom C++ class called BigInt. C++ has a number of types to handle integer data, including ints, short ints and long ints, and their signed and unsigned variants. However, the maximum positive number that one can store in the largest of these, which is an unsigned long int, is 18,446,744,073,709,551,615. This number, as you can see, has 20 digits. In many scientific and engineering applications, this does not suffice to hold values required for complex computations. Anything about 1020 would be too big to hold in the unsigned long int type. So your task in this assignment is to create a C++ class called BigInt which will allow basic arithmetic operations on positive integer values of up to 300 digits, storing integers from 0 to 9999 ...9 (300 9s). The three operations you have to do are addition, subtraction and multiplication. Specific tasks are these:
Add two BigInt objects, and store the result in another BigInt, using the + operator.
Add an int to a BigInt object, and store the result in another BigInt, also using the +operator.
Subtract one BigInt object from another, and store the result in another BigInt, using the operator. The second BigInt can always be smaller or equal to the first BigInt. In other words, the results shall never be negative.
Subtract an int from a BigInt object, and store the result in another BigInt, also using the operator. Should be obvious in this case that the results shall never be negative.
Multiply two BigInt objects, and store the result in another BigInt, using the * operator. The resulting BigInt shall not exceed 300 digits.
Multiply a BigInt object with an int, and store the result in another BigInt, using the * operator. Again, the resulting BigInt shall not exceed 300 digits.
Overload the >> and << operators to input and output BigInt objects to streams, respectively. Of course, they have to be overloaded as friend functions.
To start, heres a bare skeleton of the BigInt class. You are welcome to start with this, but do not have to. As a hint, you have to remember your basic school-level arithmetic, and implement this in a C++ class to solve this problem.
// Complete this below
class BigInt {
private:
int digits[300];
...
public:
BigInt();
BigInt( string value );
...
BigInt operator+(BigInt b);
BigInt operator-(BigInt b);
BigInt operator*(BigInt b);
friend ostream& operator<<(ostream &os, BigInt b);
...
};
The program will run as follows:
Ask the user to input two BigInts.
Output the results of addition, subtraction, and multiplication of these two BigInts
Then, ask the user to input a BigInt and an integers
Output the results of addition, subtraction, and multiplication of the BigInt and int
See the example output below.
Example (user input is bold):
(Comment: After compiling and running the program should look like this)
Enter the first BigInt:
222222222222222222222222222222
Enter the second BigInt:
111111111111111111111111111111
Adding: 333333333333333333333333333333
Subtracting: 111111111111111111111111111111
Multiplying: 24691358024691358024691358024641975308641975308641975308642
------------
Enter a BigInt:
222222222222222222222222222222
Enter an int: 4
Adding: 222222222222222222222222222226
Subtracting: 222222222222222222222222222218
Multiplying: 888888888888888888888888888888
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