Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

List and explain the activities of project planning.

Answered: 1 week ago

Question

4. Choose appropriate and powerful language

Answered: 1 week ago

Question

2. Choose an appropriate organizational pattern for your speech

Answered: 1 week ago