// CSE333 14wi final exam - pair class header file // sample solution #include #include using namespace std; #ifndef _Pair_h_ #define _Pair_h_ // simple pair class that defines element-wise addition on pairs template class Pair { public: // Construct new pair with given first and second values Pair(T first, T second) : first_(first), second_(second) { } // accessors: return first and second items from pair T first() const { return first_; } T second() const { return second_; } T munge() const; // !!!! // return a new Pair that is the element-wise sum of its arguments Pair operator+(const Pair &other) const { return Pair( first_ + other.first_, second_ + other.second_); } // copy assignment Pair &operator=(const Pair &rhs); // !!!! private: // instance variables: two values of type T T first_, second_; }; // print pair contents to cout template ostream& operator<<(ostream& o, const Pair &p) { o << "(" << p.first() << ", " << p.second() << ")"; return o; } #endif // _Pair_h_