|
ex4-12p.cpp - Example 4-12 Point and Line classes - Point Source file (ex4-12p.cpp) |
// File: ex4-12p.cpp � Point class source file
#include <cmath>
#include <iostream>
using namespace std;
#include "ex4-12p.h"
#include "ex4-12l.h"
Point::Point(void)
{
x = 0.0;
y = 0.0;
}
Point::Point(double x1, double y1)
{
x = x1;
y = y1;
}
Point::Point(const Point& p)
{
x = p.x;
y = p.y;
}
Point::Point(const Point& p, const Point& q)
{
x = (p.x + q.x) / 2.;
y = (p.y + q.y) / 2.;
}
Point::Point(const Line& l, const Line &m)
{
if (l.slope() == m.slope()) // parallel or coincident Lines
{
x = HUGE_VAL;
y = HUGE_VAL;
}
else {
x = (m.get_b() * l.get_c() - m.get_c() * l.get_b()) /
(l.get_b() * m.get_a() - m.get_b() * l.get_a());
y = (l.get_a() * m.get_c() - m.get_a() * l.get_c()) /
(l.get_b() * m.get_a() - m.get_b() * l.get_a());
}
}
void Point::print(void) const
{
cout << '(' << x << ',' << y << ')';
}
void Point::set_x(double x1)
{
x = x1;
}
void Point::set_y(double y1)
{
y = y1;
}
double Point::get_x(void) const
{
return x;
}
double Point::get_y(void) const
{
return y;
}
double Point::distance_to_Point(const Point& p) const
{
return sqrt(square(p.x - x) + square(p.y - y));
}
CIS27: Programming in C++ Instructor: Joe Bentley