Rectangle Class
Understand the implementation of a Rectangle class with different operations.
We'll cover the following
Problem
Design a class called Rectangle
containing data members top
, left
, bottom
, and right
to represent its coordinates. Implement the following functions in the Rectangle class.
areaPeri( ):
Calculates and sets the area and perimeter of Rectangle
in the reference parameters passed to this method
topLeft( ): Returns the top-left
point of the rectangle
bottomRight( ): Returns the bottom-right
point of the rectangle
centerPoint( ): Returns the center
point of the rectangle
deflateRect( ): Decreases the width
and height
of the rectangle equally from all sides using the x
and y
parameter passed to this function. After deflateRect( ), the center remains the same
inflateRect( ): Increases the width
and height
of the rectangle equally from all sides using the x
and y
parameter passed to this function. After inflateRect( ), the center remains same
equalRect( ): Determines whether a rectangle is equal to another
height( ): Calculates the height
of the rectangle
width( ): Calculates the width
of the rectangle
isRectEmpty( ): Checks if the rectangle is empty (width and/or height = 0)
isRectNull( ): Determines whether all data members are all equal to 0
ptInRect( ): Checks if a specified point lies within the rectangle
setRect( ): Sets the dimensions of the rectangle
setRectEmpty( ): Sets the rectangle to an empty rectangle (all coordinates 0)
size( ): Calculates the size of the rectangle
intersectRect( ): Sets the rectangle equal to intersection of two rectangles
unionRect( ): Sets the rectangle equal to union of two rectangles
Coding solution
Here is a solution to the problem above.
Get hands-on with 1400+ tech skills courses.