Question
Could you complete this without adding any header file? ------------------------------------------------------------------------------- You'll be working with big numbers. These numbers are too big to fit into an
Could you complete this without adding any header file?
-------------------------------------------------------------------------------
You'll be working with big numbers. These numbers are too big to fit into an int type, or even into a long long! We'll be working with integers that are up to 100 digits in length. To store these, it will take a special class with some interesting methods. Here is an outline of the BigInt class you should use:
#include
#include
using namespace std;
class BigInt {
private:
int arr[100];
public:
BigInt() { }
// this constructor should convert str into an array of ints,
// storing the values on the RIGHT SIDE of the array :)
BigInt(string str) {
}
// this constructor should save the num array into arr verbatim
BigInt(int num[100]) {
}
// this function gets the digit at 'index' from arr
int get(int index) {
}
// this function should add the argument "num"
// to the private array and return the sum
BigInt add(BigInt num) {
}
// this function should subtract the argument "num"
// from the private array and return the difference
BigInt sub(BigInt num) {
}
// this function will print the BigInt with NO leading zeroes
void print() {
}
};
In main, please get input from the user in the form of two strings and use those strings to construct two BigInt's. You may assume that the first input is larger than the second (so that you don't have to worry about negative numbers from subtraction). Next, echo the numbers that you input, so that you know you did the input correctly. Then, output the sum and difference of these two numbers. You will need to use the other constructor and 'get' function along the way. This is more challenging than it may first appear.
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