Szükség van néhány matematikai fogalom megvalósítására. Egyenlőre a legfontosabb ilyen a pont. A tér egy pontját le lehet írni 3 koordinátájával. Itt nem érzem szükségét műveletek megvalósítására. A pont nyelvi szinten csak egy struktúra. Túlterheltem a stream operátorokat az egyszerűbb kezelhetőség kedvéért.
// global_math.h
struct point
{
point(double X = 0, double Y = 0, double Z = 0);
point(const point& p);
friend std::ostream& operator<<(std::ostream& out, point p);
friend std::istream& operator>>(std::istream& is, point& p);
point& operator=(const point &new_p);
double x,y,z;
};
// global_math.cpp
point::point(double X, double Y, double Z)
{
x = X;
y = Y;
z = Z;
}
point::point(const point &p)
{
x = p.x;
y = p.y;
z = p.z;
}
std::ostream& operator<<(std::ostream& out, point p)
{
out << p.x << " " << p.y << " " << p.z;
return out;
}
std::istream& operator>>(std::istream& is, point& p)
{
double a = 0;
double b = 0;
double c = 0;
char ch = 0;
is >> a >> ch;
if (ch == ',') is >> b >> ch;
if (ch == ',') is >> c;
if (is) p = point(a,b,c);
return is;
}
point& point::operator=(const point &new_p)
{
if (this != &new_p)
{
x = new_p.x;
y = new_p.y;
z = new_p.z;
}
return *this;
}

