Answer to Question #284250 in C++ for Mehtab

Question #284250

Implement a class named Rectangle that contains following private members:



 Two double data fields that specify the width and height of the rectangle. A string data field, named color, that specifies the color of a rectangle.



You should provide a no-argument constructor that creates a default rectangle having width and



height of 2 units and color set to black. You should also provide an overloaded constructor that



creates a rectangle with the specified width and height. In addition you should provide methods



to only set the color of the rectangle. Further, you should provide a member function named



getArea() that returns the area of this rectangle and a function named getPerimeter() that returns



the perimeter.



Write a test program that creates two Rectangle objects. Assign width 10 and height 20 to the



first object and width 34.5 and height 15.9 to the second object. Assign color red to all



Rectangle objects and find their areas and perimeters.

1
Expert's answer
2022-01-03T04:27:41-0500
public class Rectangle {
  private double width;
  private double height;

   // Default Constructor
   public Rectangle() {
   }
   // Constructor
   public Rectangle(double width, double height) {
   }
   // Calculate area
   public double getArea() {
   }
   // Calculate perimeter
   public double getPerimeter() {
   }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog