/********************************************************************* C201 Computer Programming II Fall 2006 Dana Vrajitoru & A class to represent large integer numbers. **********************************************************************/ #ifndef NUMBER_H #define NUMBER_H #include using namespace std; enum Sign_ty {plus_id, minus_id=-1}; const int MAX_SIZE = 50; class Number { private: short int digits[MAX_SIZE]; int size; Sign_ty sign; // Some private class methods: // Add the digits in the two numbers regardless of the sign. void Add_digits(const Number &data); // Subtract the digits in the two numbers regardless of the sign. void Subtract_digits(const Number &data); // Compare the digits in the two number regardless of the sign. The // function returns -1 if the target object is less than the number // data, 0 if they are identical, and +1 if the target object is // larger than the data. int Compare_digits(const Number &data) const; // Multiplication by a single digit. We need this for the operator *. void Multiply(const short int d); // Shifts the digits to the left. This is equivalent to a // multiplication by 10. It moves digits[0] to digits[1], digits[1] // to digits[2], and so on. It must start from the end of the number // (position size -1) and go backwards. It must add a 0 digit at // position 0. void Shift_left(); public: // Constructors // Default constructor: intializes all digits to 0. Number(); // Copy constructor. Number(const Number &data); // Converting a simple number to an object of the class. Number(const int n); // Converting a string to an object of the class. Number(const char *s); // We may need to reset all the digits to 0. void Reset(); // Accessor functions. int length() const; // Operators // Assignment operator. One for each type. Number &operator=(const Number &data); Number &operator=(const int n); Number &operator=(const char *s); // Arithmetic operations. // Addition const Number operator+(const Number &data) const; // Subtraction const Number operator-(const Number &data) const; // Sign change const Number operator-() const; // Multiplication const Number operator*(const Number &data) const; // Division const Number operator/(const Number &data) const; // Modulus const Number operator%(const Number &data) const; // All of these operations with the matching assignment // Arithmetic operations. // Addition Number &operator+=(const Number &data); // Subtraction Number &operator-=(const Number &data); // Multiplication Number &operator*=(const Number &data); // Division Number &operator/=(const Number &data); // Modulus Number &operator%=(const Number &data); // Incrementing operator. It is used as in ++n. Number &operator++(); // Decrementing operator. It is used as in --n. Number &operator--(); // Comparison operators bool operator<(const Number &data) const; bool operator<=(const Number &data) const; bool operator>(const Number &data) const; bool operator>=(const Number &data) const; bool operator==(const Number &data) const; bool operator!=(const Number &data) const; // Input - output operators. friend ostream &operator<<(ostream &out, const Number &data); friend istream &operator>>(istream &in, Number &data); }; #endif