From ffb3cb79cdc9eca6cd97ba8919d6895a10b7c822 Mon Sep 17 00:00:00 2001 From: Trifon Trifonov Date: Wed, 30 Mar 2022 10:01:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D0=B8=20?= =?UTF-8?q?=D0=B7=D0=B0=20=D0=B8=D0=B7=D0=B2=D0=B8=D0=BA=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=B8=20=D0=BD=D0=B0=20=D1=87?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD-=D0=B4=D0=B0=D0=BD=D0=BD=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=B5=D0=BA=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lectures/1/geometry/main.cpp | 3 ++- lectures/1/geometry/point2d.cpp | 6 ++++++ lectures/1/geometry/point2d.hpp | 1 + lectures/1/geometry/point3d.cpp | 14 ++++++++++++-- lectures/1/geometry/point3d.hpp | 3 ++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lectures/1/geometry/main.cpp b/lectures/1/geometry/main.cpp index 21efb4f..b755358 100644 --- a/lectures/1/geometry/main.cpp +++ b/lectures/1/geometry/main.cpp @@ -17,7 +17,8 @@ void testGeometry() { void testGeometry3D() { Point3D p(1, 3, 8); p.printnl(); - Point3D q; + Point3D q = p; + q.printnl(); q.read(); p.translate(q); std::cout << p.distanceToOrigin() << std::endl; diff --git a/lectures/1/geometry/point2d.cpp b/lectures/1/geometry/point2d.cpp index 576dd49..20c134b 100644 --- a/lectures/1/geometry/point2d.cpp +++ b/lectures/1/geometry/point2d.cpp @@ -3,15 +3,21 @@ #include "point2d.hpp" Point2D::Point2D() { + std::clog << "Point2D::Point2D()\n"; setX(0); setY(0); } Point2D::Point2D(double _x, double _y) { + std::clog << "Point2D::Point2D(...)\n"; setX(_x); setY(_y); } +Point2D::Point2D(Point2D const& other) : x(other.x), y(other.y) { + std::clog << "Point2D::Point2D(Point2D const&)\n"; +} + // селектор за разстояние до центъра на координатната система double Point2D::distanceToOrigin() const { //return distanceTo(Point2D()); diff --git a/lectures/1/geometry/point2d.hpp b/lectures/1/geometry/point2d.hpp index d526326..6d89180 100644 --- a/lectures/1/geometry/point2d.hpp +++ b/lectures/1/geometry/point2d.hpp @@ -8,6 +8,7 @@ class Point2D { // конструктори Point2D(); Point2D(double _x, double _y); + Point2D(Point2D const&); // селектори за координатите double getX() const { return x; } diff --git a/lectures/1/geometry/point3d.cpp b/lectures/1/geometry/point3d.cpp index 83da3c1..4cd434b 100644 --- a/lectures/1/geometry/point3d.cpp +++ b/lectures/1/geometry/point3d.cpp @@ -2,15 +2,25 @@ #include "point3d.hpp" Point3D::Point3D() { + std::clog << "Point3D::Point3D()\n"; setP(Point2D()); setZ(0); } -Point3D::Point3D(double _x, double _y, double _z) { - setP(Point2D(_x, _y)); +Point3D::Point3D(double _x, double _y, double _z) : p(_x, _y) { + std::clog << "Point3D::Point3D(...)\n"; + getP().printnl(); + // setP(Point2D(_x, _y)); setZ(_z); } +/* +Point3D::Point3D(Point3D const& other) : p(other.p), z(other.z) { + // setP(other.getP()); + //setZ(other.getZ()); +} +*/ + Point3D::Point3D(Point2D const& _p, double _z) { setP(_p); setZ(_z); diff --git a/lectures/1/geometry/point3d.hpp b/lectures/1/geometry/point3d.hpp index 89b5384..ec74a35 100644 --- a/lectures/1/geometry/point3d.hpp +++ b/lectures/1/geometry/point3d.hpp @@ -13,9 +13,10 @@ class Point3D { Point3D(); Point3D(Point2D const& _p, double _z); Point3D(double _x, double _y, double _z); +// Point3D(Point3D const&); // селектори - Point2D getP() const { return p; } + Point2D const& getP() const { return p; } double getX() const { return p.getX(); } double getY() const { return p.getY(); } double getZ() const { return z; }