feat: ✨ Finish TP
This commit is contained in:
parent
d247a05e2a
commit
cf9eb0bdd7
141
.gitignore
vendored
141
.gitignore
vendored
@ -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
|
||||
|
25
CMakeLists.txt
Normal file
25
CMakeLists.txt
Normal file
@ -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
|
||||
)
|
44
main.cpp
Normal file
44
main.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
#include "./src/ClientBuilder.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
int main() {
|
||||
ClientBuilder clientBuilder;
|
||||
std::vector<std::unique_ptr<Client>> 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: " <<clients.size() << std::endl;
|
||||
std::cout << "---- Travail de Louis Gallet ----" << std::endl;
|
||||
std::cout << "---- GALL08010500 ----" << std::endl;
|
||||
|
||||
}
|
BIN
screenshot/ca_marche.png
Normal file
BIN
screenshot/ca_marche.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 145 KiB |
5
src/Exception/exception.cpp
Normal file
5
src/Exception/exception.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "exception.h"
|
24
src/Exception/exception.h
Normal file
24
src/Exception/exception.h
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#ifndef EXCEPTION_H
|
||||
#define EXCEPTION_H
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
|
||||
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
|
5
src/Mammifere/chat.cpp
Normal file
5
src/Mammifere/chat.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "chat.h"
|
28
src/Mammifere/chat.h
Normal file
28
src/Mammifere/chat.h
Normal file
@ -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
|
5
src/Mammifere/chien.cpp
Normal file
5
src/Mammifere/chien.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "chien.h"
|
28
src/Mammifere/chien.h
Normal file
28
src/Mammifere/chien.h
Normal file
@ -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
|
5
src/Mammifere/mammifere.cpp
Normal file
5
src/Mammifere/mammifere.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "mammifere.h"
|
24
src/Mammifere/mammifere.h
Normal file
24
src/Mammifere/mammifere.h
Normal file
@ -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
|
5
src/Oiseau/aigle.cpp
Normal file
5
src/Oiseau/aigle.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "aigle.h"
|
24
src/Oiseau/aigle.h
Normal file
24
src/Oiseau/aigle.h
Normal file
@ -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
|
5
src/Oiseau/oiseau.cpp
Normal file
5
src/Oiseau/oiseau.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "oiseau.h"
|
24
src/Oiseau/oiseau.h
Normal file
24
src/Oiseau/oiseau.h
Normal file
@ -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
|
5
src/animal.cpp
Normal file
5
src/animal.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "animal.h"
|
29
src/animal.h
Normal file
29
src/animal.h
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#ifndef ANIMAL_H
|
||||
#define ANIMAL_H
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
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
|
5
src/client.cpp
Normal file
5
src/client.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "client.h"
|
40
src/client.h
Normal file
40
src/client.h
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
#include <string>
|
||||
|
||||
#include "animal.h"
|
||||
|
||||
|
||||
class Client {
|
||||
private:
|
||||
std::string name;
|
||||
std::unique_ptr<Animal> animal;
|
||||
|
||||
public:
|
||||
Client(std::string name, std::unique_ptr<Animal> animal) : name(name), animal(std::move(animal)) {}
|
||||
Client(std::string name) : name(name) {}
|
||||
|
||||
void adopterAnimal(std::unique_ptr<Animal> 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
|
5
src/clientBuilder.cpp
Normal file
5
src/clientBuilder.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#include "clientBuilder.h"
|
87
src/clientBuilder.h
Normal file
87
src/clientBuilder.h
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// Created by Louis Gallet on 26/04/2025.
|
||||
//
|
||||
|
||||
#ifndef CLIENTBUILDER_H
|
||||
#define CLIENTBUILDER_H
|
||||
#include <string>
|
||||
|
||||
#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<Client> 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> animal;
|
||||
|
||||
if (type == "Chien") {
|
||||
animal = std::make_unique<chien>(nomAnimal, 1, true, race);
|
||||
} else if (type == "Aigle") {
|
||||
animal = std::make_unique<Aigle>(nomAnimal, 2, true, std::stoi(race));
|
||||
} else if (type == "Chat") {
|
||||
animal = std::make_unique<Chat>(nomAnimal, 3, true, race);
|
||||
} else {
|
||||
throw Exception("Type d'animal non reconnu");
|
||||
}
|
||||
|
||||
std::unique_ptr<Client> client = std::make_unique<Client>(nomClient, std::move(animal));
|
||||
reinitialiser();
|
||||
return client;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //CLIENTBUILDER_H
|
Loading…
x
Reference in New Issue
Block a user