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

C++ PROGRAMMING Consider the following declaration: (8, 9) template class strang

ID: 3820862 • Letter: C

Question

C++ PROGRAMMING

Consider the following declaration: (8, 9) template class strange {. .. private: type a; type b;}; Write a statement that declares sObj to be an object of type strange such that the private member variables a and b are of type int. Write a statement that shows the declaration in the class strange to overload the operator == as a member function. Assume that two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator == for the class strange, which is overloaded as a member function.

Explanation / Answer

a. The object declaration is as follows,

strange<int> sObj;

b. bool operator==(strange &rhs)const;

c. Definition of == operator

template <class type>
class strange
{
  
   private:
   type a, b;

   bool operator==(strange &rhs)const
   {
       if(a==rhs.a && b==rhs.b)
           return true;
           else return false;
   }
}

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