How does this program work? and what is cout<<point::count???
#include "stdafx.h"
#include "iostream"
#include "math.h"
using std::cin;
using std::cout;
using std::endl;
//*************************************************
class Point
{
private:
double x;
double y;
public:
static int count;
Point(double = 0, double = 0);
//Point(const Point &);
~Point();
void setX(double);
void setY(double);
double getX();
double getY();
void print();
double operator+();
friend double operator-(Point, Point);
};
//*************************************************
Point::Point(double a, double b)
{
setX(a);
setY(b);
count++;
}
//------------------------------------
Point::~Point()
{
count--;
}
//------------------------------------
/*Point::Point(const Point &p)
{
x = p.x;
y = p.y;
//*this = p;
count++;
}*/
//------------------------------------
void Point::setX(double a)
{
x = a;
}
//------------------------------------
void Point::setY(double b)
{
y = b;
}
//------------------------------------
double Point::getX()
{
return x;
}
//------------------------------------
double Point::getY()
{
return y;
}
//------------------------------------
void Point::print()
{
cout << "P(" << x << "," << y << ")";
}
//------------------------------------
double Point::operator+()
{
return sqrt(x*x + y*y);
}
//------------------------------------
//------------------------------------
//------------------------------------
//------------------------------------
//********************************************
double operator-(Point p, Point q)
{
double a, b;
a = p.x - q.x; //a = p.getX() - q.getX();
b = p.y - q.y;
return sqrt(a*a + b*b);
}
int Point::count = 0;
int main()
{
Point p(2, -3), q(-4, 3);
cout << Point::count;
//cout << p.count;
//cout << q.count;
cout << endl << +q; // q.dist();
double k = q-p; //distance (p,q);
cout << endl << k;
cin.get();
return 0;
}
Last edited on