From dd8001847b18696e1774d46c473f929a7618fb02 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 13 Sep 2023 16:20:52 +0200 Subject: [PATCH] Etape 4 --- src/etape4/point2d.cpp | 102 +++++++++++++++++++++++++++++++++++++++++ src/etape4/point2d.h | 18 ++++++++ src/etape4/point3d.h | 22 +++++++++ 3 files changed, 142 insertions(+) create mode 100644 src/etape4/point2d.cpp create mode 100644 src/etape4/point2d.h create mode 100644 src/etape4/point3d.h diff --git a/src/etape4/point2d.cpp b/src/etape4/point2d.cpp new file mode 100644 index 0000000..057905e --- /dev/null +++ b/src/etape4/point2d.cpp @@ -0,0 +1,102 @@ +#include "point2d.h" +#include "point3d.h" +#include + +Point2D::Point2D() + : Point2D(0, 0) +{ +} + +Point2D::Point2D(float x) + : Point2D(x, 0) +{ +} + +Point2D::Point2D(float x, float y) + : _x(x) + , _y(y) +{ +} + +Point2D::~Point2D() +{ +} + +void Point2D::Saisie(float x, float y) +{ + _x = x; + _y = y; +} + +void Point2D::Affiche() +{ + std::cout << "[POINT] X= " << _x << "\tY=" << _y << std::endl; +} + +Point2D Point2D::operator+(const Point2D& other) +{ + return { this->_x + other._x, this->_y + other._y }; +} + +Point2D Point2D::operator*(int other) +{ + return { this->_x * other, this->_y * other }; +} + +Point3D::Point3D() + : Point2D() + , _z(0.0f) +{ +} + +Point3D::Point3D(float x, float y, float z) + : Point2D(x, y) + , _z(z) +{ +} + +Point3D::Point3D(Point2D point, float z) + : Point2D(point) + , _z(z) +{ +} + +Point3D::~Point3D() +{ +} + +void Point3D::Saisie(float x, float y, float z) +{ + Point2D::Saisie(x, y); + _z = z; +} + +void Point3D::Affiche() +{ + std::cout << "[POINT] X= " << _x << "\tY=" << _y << "\tZ= " << _z << std::endl; +} + +Point3D Point3D::operator+(const Point3D& other) +{ + return { this->_x + other._x, this->_y + other._y, this->_z + other._z }; +} + +Point3D Point3D::operator*(int left) +{ + return { this->_x*left, this->_y*left , this->_z*left }; +} + +int main(void) +{ + Point2D pointA(2.0f, 3.0f); + Point3D pointB(pointA, 4.0f), pointC(7.8f, 6.0f, 1.2f), pointD(1.0f,1.0f,1.0f); + pointA.Affiche(); + pointB.Affiche(); + pointC.Affiche(); + pointC.Saisie(500.0f, 30.0f, 15.76f); + pointC.Affiche(); + auto pointE = pointB+pointD; + pointE.Affiche(); + (pointD*3).Affiche(); + return 0; +} \ No newline at end of file diff --git a/src/etape4/point2d.h b/src/etape4/point2d.h new file mode 100644 index 0000000..743c8c8 --- /dev/null +++ b/src/etape4/point2d.h @@ -0,0 +1,18 @@ +#ifndef HEADER_POINT2D +#define HEADER_POINT2D + +class Point2D { + public: + Point2D(); + Point2D(float x); + Point2D(float x, float y); + ~Point2D(); + void Saisie(float x, float y); + void Affiche(); + Point2D operator+(const Point2D& other); + Point2D operator*(int left); + protected: + float _x,_y; +}; + +#endif \ No newline at end of file diff --git a/src/etape4/point3d.h b/src/etape4/point3d.h new file mode 100644 index 0000000..06da85c --- /dev/null +++ b/src/etape4/point3d.h @@ -0,0 +1,22 @@ +#ifndef HEADER_POINT3D +#define HEADER_POINT3D + +#include "point2d.h" + +class Point3D : public Point2D +{ + public: + Point3D(); + Point3D(float x, float y, float z); + Point3D(Point2D point,float z); + ~Point3D(); + void Saisie(float x, float y, float z); + void Affiche(); + // Bonus avec les operateurs. + Point3D operator+(const Point3D& other); + Point3D operator*(int left); + private: + float _z; +}; + +#endif \ No newline at end of file