13523 - Infinitely Big Integer: Big Integer Implementation   

Description

The problem "Infinitely Big Integer" is splitted into two subproblems:

  1. Darray Implementation (3/10)
  2. Big Integer Implementation (7/10)

You should solve the former, Darray Implementation, first.

You may have practiced the problem Big Integer before. Instead of using traditional int, we store the integer in a char array. However, it still has size limitation because we declare a static array for the class. In this problem, we'll use the Darray in problem 13522 - Infinitely Big Integer: Darray Implementation as the data array in class INT to handle arbitary large numbers as long as the memory of the computer is enough.

The following is the structure of INT.

class INT {
    public:
        void operator+=(INT&);
        friend std::istream &operator>>(std::istream &, INT &);
        friend std::ostream &operator<<(std::ostream &, INT &);
    private:
        Darray data;
};

For simplicity, you only need to implement three functions, <<, >> and +=. The streaming operators are used for cin and cout. The operator += does the same as the traditional operator +=. For instance, A += B, A will be the value of A+B and B remains the same. Note that all the parameters are passed by reference, which is different from the previous problem.

Your function.cpp should contain the implementation of both Darray and INT. If you passed the subproblem 1 first, just copy and paste the Darray. For example:

// function.cpp
#include "function.h"
// Darray
void Darray::pushback(int x) { ... }
...

// INT
void INT::operator+= (INT &b) { ... }
...

It is okay if you have problems with the popback function in subproblem 1 as long as the Darray has basic functionality to pass the test cases, because Darray in INT is fully controlled by you.

The following is an alternative main.cpp to test your code:

#include <iostream>
#include "function.h"
using namespace std;
int main() {
    INT a, b;
    cin >> a;
    cin >> b;
    a += b;
    cout << "a + b = " << a << endl;
    return 0;
}

 

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

13523.cpp

Partial Judge Header

13523.h

Tags




Discuss