Question: Q4 (50 pts). Write a Square class having two data values: side length of the square as integer and bottom-left point of the square (as

 Q4 (50 pts). Write a Square class having two data values:side length of the square as integer and bottom-left point of the

Q4 (50 pts). Write a Square class having two data values: side length of the square as integer and bottom-left point of the square (as a Point). An example square with side length 1 and bottom-left point (0,0) is shown below. Assume the sides of the squares are parallel to x and y coordinates. You should use point struct defined in Q3. Include the following functions in the class. a. (10 pts) Write two constructors. Default constructor should set side length to 5 and bottom-left point to (0,0) point. Explicit-value constructor should accept three parameters and sets those values as side length and (x,y) coordinates of the bottom-left point. However, if the side length is less than or equal to 0 , the constructor should print an error message and sets it to 10 . b. (10 pts) Write getters and setters for the side length and bottom-left point such as getSideLength, setSideLength, getBottomLeftX, setBottomLeftX, getBottomLeftY, and setBottomLeftY. If the parameter of setSideLength is not positive, do not change the side length and print an error message. c. (5 pts) Write two functions getArea and getCircumference that returns the area and circumference of the square, respectively. d. (10 pts) Write a function named contains that takes a Point as parameter and returns true if the point is inside the square, false otherwise. e. (10 pts) Write a function named intersects that takes a Square s as parameter and returns true if the square object intersects with the Square s, false otherwise. f. (5 pts) Write a function named display to print the square objects by displaying all data members. For a square with side length 3 and bottom-left (4,5), it should display: " side length: 3 , bottom-left point: (4,5)". The function returns nothing. An example driver class and its output are given below. Side length cannot be negative. Default value (5) is used. side length: 5, bottom-left point: (0,0) side length: 3, bottom-left point: (2,4) side length: 2 , bottom-left point: (2,1) side length: 5 , bottom-left point: (5,8) 5 2 1 Side length cannot be negative. side length: 2 , bottom-left point: (2,1) side length: 10 , bottom-left point: (10,10) 25 12 Square a contains p1 Square b does not contains p1 Square a intersects with Square b Square b does not intersect with Square c Square d intersects with Square a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!