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

7) 8 pts. Add the signature for the postfix++ operor class LongPtr t public: Lon

ID: 3914828 • Letter: 7

Question

7) 8 pts. Add the signature for the postfix++ operor class LongPtr t public: LongPtr(const long & d = 0, int size= 1) : m ptr(new long[size]), m size(size) LongPtr& operator++O; //prefix // Add the signature for the postfix + operator here. long getlongO freturn mptr;): private: long *mptr; int msize; J; LongPtr& LongPtr::operator++O t for (int ?=0;imusize ;i++) muptr [i]++; return *this; 8) 18 pts. Write the body of the Postfix + operator in terms of the prefix ++ operator. 4 pts. LongPtr only needs one change and it will be const correct. What is that change? 9) 10)4 pts. What else is missing from the LongPtr Class? (Hint: LongPtr has a pointer)

Explanation / Answer

class LongPtr{

public:

       LongPtr(const long & d, int size=1):

             m_ptr(new long[size]),m_size(size)

       { for(int i=0;i<size;i++) m_ptr[i]=d;};

       LongPtr& operator++(); // prefix

       LongPtr operator++(int); // postfix // 7

       long *get_long() const // since this function doesn't change the value of m_ptr // 9

       {

             return m_ptr;

       }

       ~LongPtr() // 10 Destructor to delete the pointer when the object is destroyed

       {

             delete[] m_ptr;

       }

private :

       long * m_ptr;

       int m_size;

};

LongPtr& LongPtr::operator++()

{

       for(int i=0;i<m_size;i++)

             m_ptr[i]++;

       return (*this);

}

LongPtr LongPtr::operator++(int) // 8

{

LongPtr temp = *this;    

++(*this); // this will call prefix++ operator

       return temp ;

}

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