For this lab we are going to start off with a fairly simple class. This class is going to contain a point on a plane and this class is going to contain a X coordinate and Y coordinate. The class is also going to contain a member function that returns the distance between two points.
Using Eclipse create a Lab4 project on your system, download the Point.h file into your project.
The Point.h file declares the class and you will create a Point.cpp that contains your implementation of the constructors and member functions.
Write the necessary member functions as declared in the Point.h file.
Write a main.cpp file that instantiates your Point class and tests the various class member functions.
A portion of your grade will include how well you test your class.
Tar the entire Lab4 project, name the resulting tar file with your short name_lab4.tar, and submit.
Do not modify the public portion of the Point.h class declaration. At this time there are no requirements to add private member functions and variables.
I have part of the .cpp file written
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#ifndef POINT_H_
#define POINT_H_
#include <iostream>
class Point {
public:
/**
* Constructor and destructor
*/
Point(const double x, const double y);
virtual ~Point();
/**
* Get the x value
*/
double getX() const;
/**
* Get the y value
*/
double getY() const;
/**
* Return the distance between Points
*/
double distance(const Point &p) const;
/**
* Output the Point as (x, y) to an output stream
*/
friend std::ostream& operator <<(std::ostream&, const Point&);
private:
double x;
double y;
};
#endif /* POINT_H_ */
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include "Point.h"
using namespace std;
Point::Point(double x, double y) : x(x), y(y)
{
}
double Point::getX() const
{
return x;
}
double Point::getY() const
{
return y;
}
double Point::distance(const Point &p) const
{
int distance = y-x;
return distance;
}
Point::~Point() {
// TODO Auto-generated destructor stub
}
|