Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following class definition (Pair.hpp), Implement the assignment operat

ID: 3856680 • Letter: G

Question

Given the following class definition (Pair.hpp), Implement the assignment operator that should be in the Pair.cpp:

#ifndef _PAIR_HPP_

#define _PAIR_HPP_

#include <iostream>

#include <cstdlib>

using namespace std;

class Pair {

    public:

        Pair();

        Pair(int n1, int n2);

        Pair(const Pair& orig);

        ~Pair();

  Pair& operator=(const Pair&other);            

        friend ostream& operator<<(ostream&strm, const Pair &p);

    private:

        int x, y;

    };

}

#endif

Explanation / Answer

#include "Pair.hpp"

using namespace std;

pair::Pair()

{                 // the empty pair is the default value

   

}

Pair:: Pair(int n1, int n2)

{

N1 =x;    // copy constructor

N2=y;

}

Pair:: Pair(const Pair& orig)

{

x.n1=pair;

pair=y.n2;

}

~Pair()

{

If(pair ==0)

Delete pair;

}

Pair& operator=(const Pair&other)

{ If(pair ==0)

Delete pair;

Return *this;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote