Defining a 2D Point Solution

$30.00 $24.00

Quantity

You'll get a: . zip file solution : immediately, after Payment

Description

This problem will give you an opportunity to create class representing a point in 2D Cartesian space in both C++ and Java. This will enable you to become familiar with the two languages and explore the similarities and differences in the languages.

Begin by implementing the C++ version after lecture 2, then create the Java implementation after lecture 3.

Important note: There are a number of implementations of a 2D point available on the web in both C++ and Java. By doing this exercise yourself, without consulting them, you will gain valuable experience implementng classes in C++ and Java that you will not gain by simply copying someone else’s code.

C++ Version

Define a C++ class Point2D in the C++ namespace “CS_5004” The class represents a point in 2D Cartesian space.

Define the following private fields:

Field name

Type

Description

const x

float

the X coordinate of the point

const y

float

the Y coordinate of the point

Define the following public methods:

Method name

Type

Parameters

Description

Point2D

none

  • float x (default: 0.0)

  • float y (default: 0.0)

Constructor initializes instance this.x, and this.y to x, and y

Point2D

none

  • const Point2D& point

Constructor intializes x and y to x and y of point (copy constructor)

getX
const

float

none

Returns the x coordinate of the point

getY
const

float

none

Returns the y coordinate of the point

getDistance
const

float

  • const Point2D& point

Returns the distance between a point and this point

operator +
const

Point2D

  • const Point2D& point

Infix binary operator returns Point2D representing sum of this point and another point. The sum of two points is another point whose x and y values are the sum of the two point x, and y values.

operator –
const

Point2D

  • const Point2D& point

Infix binary operator returns Point2D representing difference of this point and another point The difference of two points is another point whose x and y values are the difference of the two point x and y values.

operator –
const

Point2D

none

Prefix unary operator returns Point2D representing a point with then negative of this point’s coordinates

operator ==
const

bool

  • const Point2D& point

Infix binary operator returns true if a point is equal to this point

operator !=
const

bool

  • const Point2D& point

Infix binary operator returns true if a point is not equal to this point

For more on this operation, see Addition of Coordinates.

Define the class in “Point2D.h” and implement the class methods in “Point2D.cpp”. Create CUnit tests and and main program in the file “Point2D_test.cpp” . Exercise the functionality of the Point2D class by creating points using both constructors, measuring their distances, and testing points for equality.

Hint: There is no need to allocate instances of Point2D in the heap for this problem. Simply declare them as local variables in the unit tests.

The class, fields, and function definitions, and test functions should have complete Doxygen style docuumentation.

Java Version

Define a Java class Point2D in the package “edu.northeastern.cs_5004” The class represents a point in 3D Cartesian space. Define the following private fields:

Field name

Type

Description

final x

float

the X coordinate of the point

final y

float

the Y coordinate of the point

Define the following public methods:

Method name

Type

Parameters

Description

Point2D

none

none

Constructor initializes this.x and this.y to 0.0

Point2D

none

  • float x

  • float y

Constructor initializes instance this.x and this.y to x, and y

Point2D

none

  • Point2D point

Constructor intializes x and y to x and y of point (copy constructor)

getX

float

none

Returns the x coordinate of the point

getY

float

none

Returns the y coordinate of the point

getDistance

float

  • Point2D point

Returns the distance between a point and this point

plus

Point2D

  • Point2D

Returns Point2D representing sum of this point and another point. The sum of two points is another point whose x and y values are the sum of the two point x and y values.

minus

Point2D

  • Point2D point

Returns Point2D representing difference of this point and another point The difference of two points is another point whose x and y values are the difference of the two point x and y values.

minus

Point2D

none

Returns Point2D representing a point with then negative of this point’s coordinates

equals

bool

  • Object obj

Returns true if ‘obj’ is a Point2D that is equal to this point. Note that direct comparison of floats does not work correctly for float values of infinity and NaN (not-a-number). Try boxing x and y values as Float and calling equals() for each with other x and y values.

hashCode

int

none

Returns int hash code for this point. Required when implementing equals(). A simple implemementation calls the utility function Objects.hash(f1,f2).

For more on this operation, see Addition of Coordinates.

Define the class and implement its methods in “Point2D.java” in the subdirectory “edu/northeastern/cs_5004′. Create a JUnit test class with a main program in the file in “Point2D_main.java” that exercises the functionality of the Point2D class by creating points using both constructors, measuring their distances, and testing points for equality..

The class, fields, and function definitions, and test functions should have complete “Javadoc” style documentation. This follows the same style as we used with DOxygen for C and C++.

0