Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовая по ООП2 / prj1 / point
.cpp// point.cpp: implementation of the point class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "point.h"
#include <iostream.h>
#include <math.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Point::Point()
{
x = 0;
y = 0;
}
Point::~Point()
{
}
Point::Point(double aX)
{
x = aX;
y = 0;
}
Point::Point(double aX, double aY)
{
// Конструктор с двумя параметрами: координаты X и Y
x = aX;
y = aY;
}
void Point::read()
{
// Вводим координаты из потока
cin >> x >> y;
}
void Point::write()
{
cout << "(" << x << ";" << y << ")";
}
Point Point::operator ++()
{
// Увеличиваем координаты на 1 и возвращаем текущий объект
x++;
y++;
return *this;
}
Point Point::operator ++(int a)
{
// Копируем и возвращаем скопированный объект, а у этой точки увеличиваем координаты на 1
Point p1(x, y);
x++;
y++;
return p1;
}
Point operator-- (Point& p) {
// Уменьшаем координаты точки p на 1 и возвращаем её
p.x--;
p.y--;
return p;
}
Point operator-- (Point& p, int a) {
// Копируем и возвращаем скопированный объект, а у точки p уменьшаем координаты на 1
Point p1(p.x, p.y);
p.x--;
p.y--;
return p1;
}
Point operator- (const Point& a, const Point& b)
{
Point p1(a.x, a.y);
p1.x -= b.x;
p1.y -= b.y;
return p1;
}
Point Point::operator+ (const Point& a)
{
Point p1(x, y);
p1.x += a.x;
p1.y += a.y;
return p1;
}
double Point::radius()
{
return sqrt(x * x + y * y);
}
double Point::angle()
{
double pi = acos(-1);
// Обрабатываем особые точки
if (x == 0 && y == 0)
return 0;
if (y == 0) {
if (x > 0)
return 0;
else
return pi;
}
if (x == 0) {
if (y > 0)
return pi / 2;
else
return - pi / 2;
}
double a = atan(y / x);
if (x < 0)
a = pi - a;
return a;
}