Question: We wish to implement a BigNumber class that represents nonnegative integers with up to 100 digits. To make this work, we will use an array
We wish to implement a BigNumber class that represents nonnegative integers with up to 100 digits. To make this work, we will use an array of digits as the underlying representation. In particular, we will use an array of char, where each char represents an actual number from 0 to 9, not the ASCII characters '0' to '9'. That means when you implement the stream insertion operator you'll need to cast each array element to an int. So out << int(digits[i]) rather than out << digits[i].
Below it the code that will go in your BigNumber.h. You'll want to add the implementation file BigNumber.cpp where you implement all the prototypes in BigNumber.h. You'll also need to implement a Driver.cpp to with a main to test your functions.
class BigNumber
{
friend ostream &operator<<(ostream &, const BigNumber &); // stream insertion operator
// output the number as we would normally read it e.g. output 17 means the number seventeen.
private:
char digits[100]; // to hold the digits with digits[i] representing the 10^i's place.
int numDigits; // number of digits in the number, e.g 5 has one digit but 45 has two. ZERO should have zero digits
public:
BigNumber(int value = 0); // default constructor.
int getNumDigits() const; // return numDigits
bool isZero() const; // return true iff *this is equal to ZERO
bool operator< (const BigNumber & c) const; // less than
bool operator>= (const BigNumber & c) const; // greather than or equal
bool operator<= (const BigNumber & c) const; // less than or equal
bool operator== (const BigNumber & c) const; // equal
bool operator!= (const BigNumber & c) const; // not equal
};
//OUTPUT SHOULD BE AN INTEGER
UPLOAD THREE FILES: BigNumber.h and BigNumber.cpp and Driver.cpp. I should be able to load the three files in Visual Studio and everything will compile fine. I will also run your code with my driver so be sure your class will work correctly when tested extensively.
Your Driver.cpp will look something like this:
#include "BigNumber.h"
#include
using namespace std;
int main()
{
BigNumber n(123);
cout << n << endl;
// (etc.)
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
