Question: We need to create a new class the BigInt class. We will use overloaded operators so that we can perform mathematical calculations that are familiar.

We need to create a new class the BigInt class.
We will use overloaded operators so that we can perform mathematical calculations that are familiar. We will also create some useful functions like fibo() which will return the Fibonacci value of that number and fact() which will return the factorial.
You can start with this header for the BIgInt class. You may not need all these operators or you may need more. Its up to you. You only need to write the operators that you need to create the solution.
class BigInt
{
private:
vector v;
BigInt fiboHelper(BigInt n, BigInt a =0, BigInt b =1);
public:
BigInt();
BigInt(int);
BigInt(string);
BigInt operator+(BigInt);
BigInt operator-(BigInt);
BigInt operator(int);
BigInt operator*(BigInt);
BigInt operator/(BigInt);
BigInt operator%(BigInt);
BigInt operator++(int);
BigInt operator++();
BigInt operator[](int); // index function
void print();
int size();
BigInt fibo(); // calls fiboHelper
BigInt fact();
friend ostream& operator<<(ostream&, const BigInt&);
friend BigInt operator+(int, BigInt);
}
Here are some rules:
1) You must use vector to store your digits. Digits have the numeric value of 0 through 9 never larger (they can be larger during calculations)
2) When you use operator<<() to print a BigInt, you will print all digits if the size if 12 or less. If there are more than 12 digits in the BigInt, then you will print in exponential notation to 7 significant digits;
a. Example: x =12345678901234
b. cout << x; // output: 1.234567e13
3) When you use the print() function, you will print ALL digits
4) The fibo() function MUST be recursive. I suggest you use tail recursion.
5) Hints:
a. Multiplication is repeated addition
b. Division is repeated subtraction
Below is the testUnit function. You are to copy this function into your main program and call it from main. The BigInt class will also be in your main program. The results should look like the output that I have provided:
Here is the testUnit fuction:
void testUnit()
{
int space =10;
cout <<"\a
TestUnit:
"<"<<((n1==s1)?"true":"false")< before:"< before:"<<++s1<<" after:"<"<< s2* big<"<< big * s2<

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!