diff --git a/.gitignore b/.gitignore index e69de29..0882681 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,141 @@ +### C++ template +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..adbf927 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.30) +project(Animaux) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(Animaux main.cpp + src/animal.cpp + src/animal.h + src/Mammifere/mammifere.cpp + src/Mammifere/mammifere.h + src/Oiseau/oiseau.cpp + src/Oiseau/oiseau.h + src/Mammifere/chien.cpp + src/Mammifere/chien.h + src/Oiseau/aigle.cpp + src/Oiseau/aigle.h + src/Mammifere/chat.cpp + src/Mammifere/chat.h + src/client.cpp + src/client.h + src/Exception/exception.cpp + src/Exception/exception.h + src/clientBuilder.cpp + src/clientBuilder.h +) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d207c35 --- /dev/null +++ b/main.cpp @@ -0,0 +1,44 @@ +#include +#include "./src/ClientBuilder.h" +#include + + +int main() { + ClientBuilder clientBuilder; + std::vector> clients; + try { + clients.push_back(clientBuilder.nouveau() + .setNomClient("Louis") + .setNomAnimal("Smurf") + .setType("Chien") + .setRace("malamute") + .build()); + + clients.push_back(clientBuilder.nouveau() + .setNomClient("Bob") + .setNomAnimal("Rex") + .setType("Chien") + .setRace("Berger Allemand") + .build()); + try { + clients.push_back(clientBuilder.nouveau() + .setNomClient("Axel") + .setType("Chat") + .setRace("siamois") + .build()); + } catch (const Exception& e) { + std::cout << "------------- Fin des tests qui fail -----------------------------" << std::endl; + std::cerr << "Erreur: " << e.what() << std::endl; + } + } catch (const Exception& e) { + std::cerr << "Erreur: " << e.what() << std::endl; + } + std::cout << "------------- Les tests qui passent -----------------------------" << std::endl; + for (const auto& client : clients) { + client->afficherAnimalAdopte(); + } + std::cout << "Nombre total de clients: " < +#include + + +class Exception : public std::exception { +private: + std::string message; +public: + explicit Exception(std::string message) : message(message) {} + const char *what() const noexcept override { + return message.c_str(); + } + +}; + + + +#endif //EXCEPTION_H diff --git a/src/Mammifere/chat.cpp b/src/Mammifere/chat.cpp new file mode 100644 index 0000000..248dde7 --- /dev/null +++ b/src/Mammifere/chat.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "chat.h" diff --git a/src/Mammifere/chat.h b/src/Mammifere/chat.h new file mode 100644 index 0000000..6979f17 --- /dev/null +++ b/src/Mammifere/chat.h @@ -0,0 +1,28 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef CHAT_H +#define CHAT_H +#include "mammifere.h" + + +class Chat : public Mammifere { +private: + std::string couleur; +public: + Chat(std::string n, int i, bool d, std::string couleur) : Mammifere(n, i, d), couleur(couleur) {}; + void genererCarnetMedical() override { + Mammifere::genererCarnetMedical(); + std::cout << "Couleur: " << couleur << std::endl; + if (domestique) { + std::cout << "Le chat est domestique" << std::endl; + } else { + std::cout << "Le chat n'est pas domestique" << std::endl; + } + } +}; + + + +#endif //CHAT_H diff --git a/src/Mammifere/chien.cpp b/src/Mammifere/chien.cpp new file mode 100644 index 0000000..0744c47 --- /dev/null +++ b/src/Mammifere/chien.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "chien.h" diff --git a/src/Mammifere/chien.h b/src/Mammifere/chien.h new file mode 100644 index 0000000..d637e3d --- /dev/null +++ b/src/Mammifere/chien.h @@ -0,0 +1,28 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef CHIEN_H +#define CHIEN_H +#include "mammifere.h" + + +class chien : public Mammifere { +private: + std::string race; +public: + chien(std::string n, int i, bool d, std::string r) : Mammifere(n, i, d), race(r) {}; + void genererCarnetMedical() override { + Mammifere::genererCarnetMedical(); + std::cout << "Race: " << race << std::endl; + if (domestique) { + std::cout << "Le chien est domestique" << std::endl; + } else { + std::cout << "Le chien n'est pas domestique" << std::endl; + } + } +}; + + + +#endif //CHIEN_H diff --git a/src/Mammifere/mammifere.cpp b/src/Mammifere/mammifere.cpp new file mode 100644 index 0000000..0a7ef87 --- /dev/null +++ b/src/Mammifere/mammifere.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "mammifere.h" diff --git a/src/Mammifere/mammifere.h b/src/Mammifere/mammifere.h new file mode 100644 index 0000000..8a98eea --- /dev/null +++ b/src/Mammifere/mammifere.h @@ -0,0 +1,24 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef MAMMIFERE_H +#define MAMMIFERE_H +#include "../animal.h" + + +class Mammifere : public Animal { +protected: + bool domestique; + +public: + Mammifere(std::string n, int i, bool d) : Animal(n, i), domestique(d) {}; + virtual ~Mammifere() {}; + void genererCarnetMedical() override { + std::cout << "Carnet médical du Mammifere nommé " << name << " (ID: " << id << ")" << std::endl; + } +}; + + + +#endif //MAMMIFERE_H diff --git a/src/Oiseau/aigle.cpp b/src/Oiseau/aigle.cpp new file mode 100644 index 0000000..4c3c8c6 --- /dev/null +++ b/src/Oiseau/aigle.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "aigle.h" diff --git a/src/Oiseau/aigle.h b/src/Oiseau/aigle.h new file mode 100644 index 0000000..801dc64 --- /dev/null +++ b/src/Oiseau/aigle.h @@ -0,0 +1,24 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef AIGLE_H +#define AIGLE_H +#include "oiseau.h" + + +class Aigle : public Oiseau { +private: + int envergure; +public: + Aigle(std::string n, int i, bool v, int e) : Oiseau(n, i, v), envergure(e) {}; + ~Aigle() override {}; + void genererCarnetMedical() override { + Oiseau::genererCarnetMedical(); + std::cout << "Envergure: " << envergure << " cm" << std::endl; + } +}; + + + +#endif //AIGLE_H diff --git a/src/Oiseau/oiseau.cpp b/src/Oiseau/oiseau.cpp new file mode 100644 index 0000000..648aafe --- /dev/null +++ b/src/Oiseau/oiseau.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "oiseau.h" diff --git a/src/Oiseau/oiseau.h b/src/Oiseau/oiseau.h new file mode 100644 index 0000000..f15919d --- /dev/null +++ b/src/Oiseau/oiseau.h @@ -0,0 +1,24 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef OISEAU_H +#define OISEAU_H +#include "../animal.h" + + +class Oiseau : public Animal { +protected: + bool volant; +public: + Oiseau(std::string n, int i, bool v) : Animal(n, i), volant(v) {}; + virtual ~Oiseau() {}; + + void genererCarnetMedical() override { + std::cout << "Carnet médical de l'oiseau nommé " << name << " (ID: " << id << ")" << std::endl; + } +}; + + + +#endif //OISEAU_H diff --git a/src/animal.cpp b/src/animal.cpp new file mode 100644 index 0000000..5b835d7 --- /dev/null +++ b/src/animal.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "animal.h" diff --git a/src/animal.h b/src/animal.h new file mode 100644 index 0000000..2ed5736 --- /dev/null +++ b/src/animal.h @@ -0,0 +1,29 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef ANIMAL_H +#define ANIMAL_H +#include +#include +#include + + +class Animal { +protected: + std::string name; + int id; + +public: + Animal(std::string n, int i) : name(n), id(i) {} + virtual ~Animal() {} + + virtual void genererCarnetMedical() = 0; + std::string getName() const { + return name; + } +}; + + + +#endif //ANIMAL_H diff --git a/src/client.cpp b/src/client.cpp new file mode 100644 index 0000000..d2f2951 --- /dev/null +++ b/src/client.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "client.h" diff --git a/src/client.h b/src/client.h new file mode 100644 index 0000000..19e74a1 --- /dev/null +++ b/src/client.h @@ -0,0 +1,40 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef CLIENT_H +#define CLIENT_H +#include + +#include "animal.h" + + +class Client { +private: + std::string name; + std::unique_ptr animal; + +public: + Client(std::string name, std::unique_ptr animal) : name(name), animal(std::move(animal)) {} + Client(std::string name) : name(name) {} + + void adopterAnimal(std::unique_ptr animal) { + this->animal = std::move(animal); + } + + void afficherAnimalAdopte() const { + if (animal) { + std::cout << "Client: " << name << std::endl; + std::cout << "Animal adopté: " << animal->getName() << std::endl; + animal->genererCarnetMedical(); + } + else { + std::cout << "Client: " << name << std::endl; + std::cout << "Aucun animal adopté." << std::endl; + } + } +}; + + + +#endif //CLIENT_H diff --git a/src/clientBuilder.cpp b/src/clientBuilder.cpp new file mode 100644 index 0000000..b33a0d6 --- /dev/null +++ b/src/clientBuilder.cpp @@ -0,0 +1,5 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#include "clientBuilder.h" diff --git a/src/clientBuilder.h b/src/clientBuilder.h new file mode 100644 index 0000000..e97b450 --- /dev/null +++ b/src/clientBuilder.h @@ -0,0 +1,87 @@ +// +// Created by Louis Gallet on 26/04/2025. +// + +#ifndef CLIENTBUILDER_H +#define CLIENTBUILDER_H +#include + +#include "client.h" +#include "Exception/exception.h" +#include "Mammifere/chat.h" +#include "Mammifere/chien.h" +#include "Oiseau/aigle.h" +#include "animal.h" + +class ClientBuilder { +private: + std::string nomClient; + std::string nomAnimal; + std::string type; + std::string race; + + void reinitialiser() { + nomClient = ""; + nomAnimal = ""; + type = ""; + race = ""; + } +public: + ClientBuilder() { + reinitialiser(); + } + + ClientBuilder& nouveau() { + reinitialiser(); + return *this; + } + + ClientBuilder& setNomClient(const std::string& nom) { + nomClient = nom; + return *this; + } + + ClientBuilder& setNomAnimal(const std::string& nom) { + nomAnimal = nom; + return *this; + } + + ClientBuilder& setType(const std::string& t) { + type = t; + return *this; + } + + ClientBuilder& setRace(const std::string& r) { + race = r; + return *this; + } + std::unique_ptr build() { + if (nomClient.empty()) { + throw Exception("Nom du client non spécifié"); + } + + if (nomAnimal.empty()) { + throw Exception("Nom de l'animal non spécifié"); + } + + std::unique_ptr animal; + + if (type == "Chien") { + animal = std::make_unique(nomAnimal, 1, true, race); + } else if (type == "Aigle") { + animal = std::make_unique(nomAnimal, 2, true, std::stoi(race)); + } else if (type == "Chat") { + animal = std::make_unique(nomAnimal, 3, true, race); + } else { + throw Exception("Type d'animal non reconnu"); + } + + std::unique_ptr client = std::make_unique(nomClient, std::move(animal)); + reinitialiser(); + return client; + } +}; + + + +#endif //CLIENTBUILDER_H