Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

how do i search questions on chegg

Answered: 1 week ago