This commit is contained in:
nihonium 2022-09-14 19:05:27 +03:00
parent 46d1c64684
commit ab6732eded
Signed by: nihonium
GPG key ID: 0251623741027CFC
98 changed files with 10319 additions and 0 deletions

View file

@ -0,0 +1,62 @@
/*
Раздельная компиляция.
В этой части мы вынесем весь код, связанный с нашим классом Point в отдельные файлы.
А также скомпилируем отдельно код, относящийся к нашему классу Point.
Это будет проделано в следующий примерах, а пока тут просто лежит код
класса Point из предыдущих частей.
*/
#include <iostream>
#include <iomanip>
#include <cmath>
using std::cout, std::endl;
struct Point
{
float x, y;
Point operator+(Point b) const
{
Point result = {x + b.x, y + b.y};
return result;
}
float norm() const
{
return std::sqrt(x * x + y * y);
}
Point operator*(float k) const
{
Point result = {k * x, k * y};
return result;
}
void normalize()
{
float normv = norm();
x /= normv;
y /= normv;
}
};
std::ostream& operator<<(std::ostream& out, Point a)
{
out << std::setprecision(2) << "(" << a.x << ", " << a.y << ")";
return out;
}
int main()
{
Point a = {7.2, 3.1};
cout << a.norm() << endl;
}