From 1c8251ad16c2bd531d2a6a6ecf75cd7f79cb6bcb Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Thu, 5 Oct 2023 09:32:17 +0200 Subject: [PATCH] Exercice 1.3 - TP 1 --- tp/include/polygone.h | 35 +++++++++++++++++++++++++++-------- tp/src/main.cpp | 4 ++++ tp/src/polygone.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/tp/include/polygone.h b/tp/include/polygone.h index 5bdca7b..b9cfba2 100644 --- a/tp/include/polygone.h +++ b/tp/include/polygone.h @@ -4,14 +4,33 @@ #include "figure.h" #include -class Polygone : public Figure -{ - public: - Polygone(u_int64_t nb_cotes); - virtual std::string afficherCaracteristiques() override; - virtual int perimetre() override; - private: - u_int64_t _nbcotes; +class Polygone : public Figure { +public: + Polygone(u_int64_t nb_cotes); + virtual std::string afficherCaracteristiques() override; + virtual int perimetre() override; + +protected: + u_int64_t _nbcotes; +}; + +class Rectangle : public Polygone { +public: + Rectangle(uint hauteur, uint longueur); + virtual std::string afficherCaracteristiques() override; + virtual int perimetre() override; + +private: + uint _hauteur, _longueur; +}; + +class Carre : public Polygone { +public: + Carre(uint cote); + virtual std::string afficherCaracteristiques() override; + virtual int perimetre() override; +private: + uint _cote; }; #endif // HEADER_POLYGONE \ No newline at end of file diff --git a/tp/src/main.cpp b/tp/src/main.cpp index 8a477f9..6b4a6ca 100644 --- a/tp/src/main.cpp +++ b/tp/src/main.cpp @@ -5,4 +5,8 @@ int main(void) { Polygone coolPoly(5); std::cout << coolPoly.afficherCaracteristiques() << std::endl; + Rectangle rect(4,8); + std::cout << rect.afficherCaracteristiques() << std::endl; + Carre car(2); + std::cout << car.afficherCaracteristiques() << std::endl; } \ No newline at end of file diff --git a/tp/src/polygone.cpp b/tp/src/polygone.cpp index 47256ef..37643ce 100644 --- a/tp/src/polygone.cpp +++ b/tp/src/polygone.cpp @@ -15,4 +15,37 @@ std::string Polygone::afficherCaracteristiques() int Polygone::perimetre() { return 0; +} + +Rectangle::Rectangle(uint hauteur, uint longueur) + : Polygone(4) + , _hauteur(hauteur) + , _longueur(longueur) +{ +} + +std::string Rectangle::afficherCaracteristiques() +{ + return std::string("Nombre de cotes : 4\tPerimetre :"+std::to_string(perimetre())); +} + +int Rectangle::perimetre() +{ + return _longueur * _hauteur; +} + +Carre::Carre(uint cote) + : Polygone(4) + , _cote(cote) +{ +} + +std::string Carre::afficherCaracteristiques() +{ + return std::string("Nombre de cotes : 4\tPerimetre :"+std::to_string(perimetre())); +} + +int Carre::perimetre() +{ + return _cote * _cote; } \ No newline at end of file