Expand the PointD class discussed in this chapter to include the quadrant information of a point. The

Question:

Expand the PointD class discussed in this chapter to include the quadrant information of a point. The x-axis and y-axis divide the plane into four regions called quadrants. The quadrants are labeled starting at the positive x-axis and going around counterclockwise as shown below:

image text in transcribed

Write the new PointD class as described below. Points falling on the \(x\)-axis and \(y\)-axis are not considered to be in any quadrant, and therefore return the default value, 0 :
A. The PointD class has two private class constants, DEFAULT VALUE of type double and DEFAULT QUADRANT of type int, that should be initialized to 0.0 and 0 , respectively.
B. The PointD class has two private instance data members, \(x\) and \(y\), of type double.
C. The PointD class has one private instance data member quadrant of type int.
D. The first constructor is a default constructor and calls the third constructor (described below), by using the reserved word this, to set the instance data members to the default values.
E. The second constructor receives a PointD object as a formal parameter and stores the \(\mathrm{x}, \mathrm{y}\), and quadrant of the object as the values of the instance data members.
F. Third constructor calls the setPoint method (described below). Its two formal parameters are used as the parameters for the setPoint method.
G. The mutator methods, setX and setY, have one formal parameter and call the setPoint method (described below). The setX method changes the value of data member \(x\) to the value of the parameter. The sety method changes the value of data member \(y\) to the value of the parameter.
H. Another mutator method, setPoint, has two formal parameters and stores these values in the instance data members, \(\mathrm{x}\) and \(\mathrm{y}\). It also sets the correct value for the data member quadrant depending on the values of the two parameters.
I. The accessor methods, getX, getY, and getQuadrant, return the value of the appropriate instance data member.
Next, write a client program to test the PointD class defined above. Call this class Points. The main method should perform the following tasks:

J. Declare five PointD objects.
K. Create five PointD objects using the three different constructors. The points should be in three different quadrants and also the origin.
L. Output the contents of \(\mathrm{x}, \mathrm{y}\), and quadrant for the five objects.
M. Change the value of \(x\) or \(y\) for one of the points using a mutator so that the point will move to a different quadrant.
Here is some sample output:

image text in transcribed

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: