1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#ifndef BIG_INTEGER_H
#define BIG_INTEGER_H
#include "BigIntegerException.h"
/**
Recall from integer type that covers largest range is
long long, which is from –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807. You don't want these limitation
on how large number you can use.
Your task is to design this BigInteger class and implement
its operators to overcome this limitation of long long type.
Here are your tasks:
1. constructors:
a. default constructor: should store number 0
b. constructor with one string argument: store value
and throw NumberFormatException if argument is
a empty string or string with non-numeric characters
c. copy construtor: to clone a copy of an object instead
of just a pointer (see shadow copy behavior)
2. destructor: as a rule of thumb, when you allocate memory,
clean up memory.
3. toString: return the number in a string format
4. operator+: to add two BigInteger objects
5. operator*: to multiply two BigInteger objects
With all above requirements, design an internal/private data
members that are approriate to all above functions. See the
test cases (BigIntegerTest) to see its expected usage.
*/
class BigInteger {
private:
string *ptr;
string *temp;
public:
// default constructor
BigInteger();
// constructor with one string argument
BigInteger(string value) throw (NumberFormatException);
// copy constructor
BigInteger(const BigInteger& bigInt);
// assignment operator
BigInteger& operator=(const BigInteger& bigInt);
// destructor
~BigInteger();
// print the number without leading zero
std::string toString();
// addition operator
friend BigInteger operator+(const BigInteger& leftNum, const BigInteger& rightNum);
// multiplication operator
friend BigInteger operator*(const BigInteger& leftNum, const BigInteger& rightNum);
};
#endif
| |