/*******************************************************/
//R.A. Hillyard
//point.cpp
//Last Modified 11/11/2001
//
// another example of a simple class
/*******************************************************/
#include<iostream>
#include<cmath>
using namespace std;
class Point //class definition goes before main
{
public: //member functions
void output();
void input();
//mutator function to set data member values
void setPoint(int xCord, int yCord);
//accessor functions to get data member values
int getX();
int getY();
private: //member data variables
int x;
int y;
};
int main()
{
Point p1, p2, p3; //declare 3 objects of type Point
double dist; //distance between two points
p1.setPoint(3, 4);
p2.setPoint(3, -4);
p3.input();
cout << "Value of points:\n";
p1.output(); cout << endl;
p2.output(); cout << endl;
p3.output(); cout << endl;
dist = sqrt(pow(p1.getX() - p3.getX(), 2) + pow(p1.getY() - p3.getY(),2));
cout << "The distance between p1 and p3 = " << dist << endl;
return 0;
}
/************************************************/
void Point::output()
{ cout << "x = " << x << " y = " << y; }
/************************************************/
void Point::input()
{
cout << "Enter a x and y coordinate: ";
cin >> x >> y;
}
/************************************************/
void Point::setPoint(int xCord, int yCord)
{
x = xCord;
y = yCord;
}
/************************************************/
int Point::getX()
{ return x; }
/************************************************/
int Point::getY()
{ return y; }
/************************************************/
/**************Program Output********************/
Enter a x and y coordinate: 0 0
Value of points:
x = 3 y = 4
x = 3 y = -4
x = 0 y = 0
The distance between p1 and p3 = 5