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
|
#include "doubly_linked_list.h"
using namespace std;
class big_number
{
public:
// constructors (work like init() methods)
big_number();
big_number(int i);
big_number(const big_number& m);
big_number(const string& s, unsigned int base);
// assignment operator
// big_number a = 98; big_number b = 0; ... b = a;
big_number& operator=(const big_number& m);
// destructor (works like destr() method)
~big_number();
// self-assigning arithmetic operators
big_number& operator+=(const big_number& addend);
big_number& operator-=(const big_number& subtractand);
big_number& operator*=(const big_number& multiplicand);
big_number& operator/=(const big_number& divisor);
// positive modulus
big_number& operator%=(const big_number& divisor);
// overload prefix increment
big_number& operator++();
// overload prefix decrement
big_number& operator--();
// input and output operators
friend std::ostream& operator<<(std::ostream& os, const big_number& bignum);
friend std::istream& operator>>(std::istream& is, big_number& bignum);
// arithmetic operators
friend big_number operator+(const big_number& a, const big_number& b);
friend big_number operator-(const big_number& a, const big_number& b);
friend big_number operator*(const big_number& a, const big_number& b);
friend big_number operator/(const big_number& a, const big_number& b);
friend big_number operator%(const big_number& a, const big_number& b);
// hard to do without fast multiplication
friend big_number factorial(const big_number& a);
// comparison operators
friend bool operator>(const big_number& a, const big_number& b);
friend bool operator>=(const big_number& a, const big_number& b);
friend bool operator<(const big_number& a, const big_number& b);
friend bool operator<=(const big_number& a, const big_number& b);
friend bool operator==(const big_number& a, const big_number& b);
friend bool operator!=(const big_number& a, const big_number& b);
private:
node* head_ptr;
node* tail_ptr;
unsigned int digits;
bool positive;
unsigned int base;
// helper functions can go here
};
|