Problem

(Geometry: find the bounding rectangle) A bounding rectangle is the minimum rectangle that...

(Geometry: find the bounding rectangle) A bounding rectangle is the minimum rectangle that encloses a set of points in a two-dimensional plane, as shown in Figured. Write a function that returns a bounding rectangle for a set of points in a two-dimensional plane, as follows:

const int SIZE = 2 ;

Rectang1e2D getRectang1e(const double points[][SIZE]);

The Rectang1e2D class is defined in Programming Exercise. Write a test program that prompts the user to enter five points and displays the bounding rectangle’s center, width, and height. Here is a sample run:

Figured

Programming Exercise. (Geometry: The Rectangle2D class) Define the Rectangle2D class that contains:

■ Two double data fields named x and y that specify the center of the rectan­gle with constant get functions and set functions. (Assume that the rectangle sides are parallel to x- or y- axes.)

■ The double data fields width and height with constant get functions and set functions.

■ A no-arg constructor that creates a default rectangle with (0 , 0) for (x , y) and 1 for both width and height.

■ A constructor that creates a rectangle with the specified x , y , width , and height.

■ A constant function getArea() that returns the area of the rectangle.

■ A constant function getPerimeter() that returns the perimeter of the rectangle.

■ A constant function contains(double x, double y) that returns true if the specified point (x , y) is inside this rectangle. See Figurea.

■ A constant function contains(const Rectangle2D &r) that returns true if the specified rectangle is inside this rectangle. See Figureb.

■ A constant function overlaps(const Rectangle2D &r) that returns true if the specified rectangle overlaps with this rectangle. See Figurec.

Figure (a) A point is inside the rectangle. (b) A rectangle is inside another rectangle.

(c) A rectangle overlaps another rectangle. (d) Points are enclosed inside a rectangle.

Draw the UML diagram for the class. Implement the class. Write a test program that creates three Rectangle2D objects r1(2, 2, 5.5, 4.9) , r2(4,5, 10.5, 3.2)) , and r3(3, 5, 2.3, 5.4) , and displays r1 ’s area and perimeter, and displays the result of r1.contains(3, 3) , r1.contains(r2) , and r1. overlaps(r3).

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT