Funktionen: Point point.cc

#include "point.h"

int Point::number=0;

Point::Point(const int X)
{ 
  number++;
  assign(X,X); 
}

Point::Point(const int X, const int Y)
{       
  number++;
  assign(X,Y); 
}

Point::Point(const Point &p)
{
  number++;
  x=p.x;
  y=p.y;
}

Point::~Point()
{
  number--;
}

void Point::assign(const int X, const int Y)
{
  x=X; y=Y;
}

float Point::distance(const Point& p)
{
  int xDiff, yDiff;
  xDiff=x-p.x;
  yDiff=y-p.y;
  return sqrt(xDiff * xDiff + yDiff * yDiff);
}

Point operator+(const Point p, const Point q)
{
  return Point(q.x+p.x, q.y+p.y);
}

ostream& operator << (ostream& s, const Point& p)
{
  return s << '(' << p.x << ',' << p.y << ')';
}

previous up next


© 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 12/16/1998