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

FeetInches Class Copy Constructor and multiply Function Add a copy constructor t

ID: 3821539 • Letter: F

Question

FeetInches Class Copy Constructor and multiply Function Add a copy constructor to the FeetInches class. This constructor should accept a FeetInches object as an argument. The constructor should assign to the feet attribute the value in the argument's feet attribute, and assign to the inches attribute the value in the argument's inches attribute. As a result, the new object will be a copy of the argument object. Next, add a multiply member function to the Feet Inches class. The multiply function should accept a FeetInches object as an argument. The argument object's feet and inches attributes will be multiplied by the calling object's feet and inches attributes, and a FeetInches object containing the result will be returned.

Explanation / Answer

HI, As per the Question description.

I have implemented both constructor and function.

Please let me know in case of any issue.

class FeetInches{
  
   private:
       int feet;
       int inches;

   public:

       // copy constructor
       FeetInches(const FeetInches &copy){

           feet = copy.feet;
           inches = copy.inches;
       }

       FeetInches multiply(const FeetInches &other){

           int f = feet*other.feet;
           int i = inches*other.inches;

           FeetInches obj;
           obj.feet = f;
           obj.inches = i;

           return obj;
       }
}

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