Question
. - Square.cpp and Square.h files for the Question 4 and SquareDriver.cpp file that contains the main function where Square objects are created and the
. - Square.cpp and Square.h files for the Question 4 and SquareDriver.cpp file that contains the main function where Square objects are created and the methods are called.
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.
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started