## 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.