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

Solve this problem in C++. Thank you! Rectangle r2(10, 5); int multiplier{ 0 };

ID: 3815045 • Letter: S

Question

Solve this problem in C++. Thank you!

Rectangle r2(10, 5);
int multiplier{ 0 };

//write the function to overload the multiplication ("*=") operator for an object of the Rectangle class.

//The code below prompts a user to enter a number that will be passed in to your overloaded operator function.
//The function should then multiply the length of the rectangle's object by this number and set the object's new length equal to the product of this operation.
//The function should also multiple the width of the rectangle's object by this number and set the object's new width equal to the product of this operation.

//The following error check MUST be incorporated in your function to receive full credit: If the multiplier is less than or equal to zero, instead of modifying the object's length and width, the function should print out the following error message:"Multiplier must be a positive integer"

cout << " Enter an integer that you want to multiply the length and width of rectangle r2 by: ";
cin >> multiplier;
r2 *= multiplier;
cout << "The new rectangle's dimensions are: Length: " << r2.getLength() << " Width: " << r2.getWidth() << endl;

Explanation / Answer

HI, Please find my implementation of required method.

Please let me know in case of any issue.

Rectangle& operator =*(int mul) {

   if(mul <= 0){
       cout<<"Multiplier must be a positive integer"<<endl;
       return *this;
   }
  
   this->length = mul*length;
   this->width = mul*width;

   return *this;

}

Rectangle::

Rectangle r2(10, 5);
int multiplier = 0;
//write the function to overload the multiplication ("*=") operator for an object of the Rectangle class.
//The code below prompts a user to enter a number that will be passed in to your overloaded operator function.
//The function should then multiply the length of the rectangle's object by this number and set the object's new length equal to the product of this operation.
//The function should also multiple the width of the rectangle's object by this number and set the object's new width equal to the product of this operation.
//The following error check MUST be incorporated in your function to receive full credit: If the multiplier is less than or equal to zero, instead of modifying the object's length and width, the function should print out the following error message:"Multiplier must be a positive integer"
cout << " Enter an integer that you want to multiply the length and width of rectangle r2 by: ";
cin >> multiplier;
r2 *= multiplier;
cout << "The new rectangle's dimensions are: Length: " << r2.getLength() << " Width: " << r2.getWidth() << endl;