# data[].attributes.body
Level 1

# data[].attributes.body
#include <iostream>

using namespace std;

template <typename T1, typename T2>

class Pair {

public:

T1 first_values;

T2 second_values;

Pair(T1 a, T2 b) : first_values(a), second_values(b) {} // constructor

~Pair() {}

T1 get_first() { return first_values; }

T2 get_second() { return second_values; }

template <typename ostreamType = ostream>

void print(ostreamType& os) const {

os << "(" << first_values << ", " << second_values << ")";

}

// Overload the == operator

bool operator==(const Pair<T1, T2>& other) const {

return first_values == other.first_values &&

second_values == other.second_values;

cout << " == operator" << endl;

}

};

template <>

class Pair<int, int> {

public:

int first_values;

int second_values;

Pair(int a, int b) : first_values(a), second_values(b) {} // constructor

~Pair() {}

int get_first() { return first_values; }

int get_second() { return second_values; }

template <typename ostreamType = ostream>

void print(ostreamType& os) const {

os << "(" << first_values << ", " << second_values << ")";

}

// Overload the == operator

bool operator==(const Pair<int, int>& other) const {

return first_values == other.first_values &&

second_values == other.second_values;

}

// adding sum() to sum up the two integers

int sum() const { return first_values + second_values; }

};

int main() {

Pair<int, double> p1(10, 1.21);

cout << "Pair<int, double>: (" << p1.get_first() << ", " << p1.get_second()

<< ")" << endl;

p1.print(cout);

cout << endl;

Pair<string, int> p2("test", 10);

cout << "Pair<string, int>: (" << p2.get_first() << ", " << p2.get_second()

<< ")" << endl;

p2.print(cout);

cout << endl;

Pair<double, string> p3(33.44, "test2");

cout << "Pair<double, string>: (" << p3.get_first() << ", " << p3.get_second()

<< ")" << endl;

p3.print(cout);

cout << endl;

cout << endl

<< "**** 2. Test for Overload the == operator to compare two pairs for "

"equity ***"

<< endl;

Pair<int, double> p4(10, 1.21);

p4.print(cout);

cout << endl;

Pair<int, double> p5(30, 2.333);

p5.print(cout);

cout << endl;

Pair<int, int> p7(20, 22);

p5.print(cout);

cout << endl;

if (p1 == p4) {

cout << "the pair p1 and p4 are equal" << endl;

}

if (p1 == p5) {

cout << "the pair p1 and p5 are equal" << endl;

} else {

cout << "the pair p1 and p5 are not equal" << endl;

}

cout << endl << "**** 3. Sum up when the pairs are both integers ***" << endl;

Pair<int, int> p6(50, 49);

cout << "sum :" << p6.sum() << endl;

if (p6 == p7) {

cout << "the pair p6 and p7 are equal" << endl;

} else {

cout << "the pair p6 and p7 are not equal" << endl;

}

return 0;

}