diff --git a/src/etape3/point2d.cpp b/src/etape3/point2d.cpp new file mode 100644 index 0000000..8606372 --- /dev/null +++ b/src/etape3/point2d.cpp @@ -0,0 +1,56 @@ +#include +#include "point2d.h" + +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}; +} + +int main(void) +{ + Point2D pointA(2.0f,3.0f); + Point2D pointB(1.0f); + Point2D pointC; + pointA.Saisie(4.31f, 5.45f); + + pointA.Affiche(); + pointB.Affiche(); + pointC.Affiche(); + Point2D A(1,2), B(3,4),C; + C = A + B; + C.Affiche(); + C = A*5; + C.Affiche(); + return 0; +} \ No newline at end of file diff --git a/src/etape3/point2d.h b/src/etape3/point2d.h new file mode 100644 index 0000000..78fb06f --- /dev/null +++ b/src/etape3/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); + private: + float _x,_y; +}; + +#endif \ No newline at end of file