Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Please leave comments explaining your steps Q3 for reference Q4 (50 pts). Write a Square class having two data values: side length of the
C++ Please leave comments explaining your steps
Q3 for reference
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. Q3 (10 pts). Define a struct named Point having int x and y values representing x and y coordinates of the point. Write a function named distance that accepts two Points as parameters and returns their distance. Distance can be computed as (x1x2)2+(y1y2)2. For instance, running the following code in the main function should print "5.65685". Point p1 ={3,4} Point p2 ={7,0} cout distance (p1,p2) endlStep 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