diff --git a/Algo/Cours/Cpp/docC++.docx b/Algo/Cours/Cpp/docC++.docx new file mode 100644 index 0000000..247e67c Binary files /dev/null and b/Algo/Cours/Cpp/docC++.docx differ diff --git a/Algo/Cours/Cpp/docC++.pdf b/Algo/Cours/Cpp/docC++.pdf new file mode 100644 index 0000000..05a02be Binary files /dev/null and b/Algo/Cours/Cpp/docC++.pdf differ diff --git a/Algo/tp/Cpp/3_tp/bin/exe b/Algo/tp/Cpp/3_tp/bin/exe index 86b8346..373da8d 100755 Binary files a/Algo/tp/Cpp/3_tp/bin/exe and b/Algo/tp/Cpp/3_tp/bin/exe differ diff --git a/Algo/tp/Cpp/3_tp/obj/passager.o b/Algo/tp/Cpp/3_tp/obj/passager.o index 9b2aaf5..bd706a5 100644 Binary files a/Algo/tp/Cpp/3_tp/obj/passager.o and b/Algo/tp/Cpp/3_tp/obj/passager.o differ diff --git a/Algo/tp/Cpp/3_tp/src/passager.cpp b/Algo/tp/Cpp/3_tp/src/passager.cpp index ed88cee..890a7d1 100644 --- a/Algo/tp/Cpp/3_tp/src/passager.cpp +++ b/Algo/tp/Cpp/3_tp/src/passager.cpp @@ -6,7 +6,7 @@ using namespace std; -Passager::Passager(string nom, string prenom) +Passager::Passager(const string &nom, const string &prenom) :nom{nom}, prenom{prenom}, wagonActuel{nullptr} {} diff --git a/Algo/tp/Cpp/3_tp/src/passager.hpp b/Algo/tp/Cpp/3_tp/src/passager.hpp index fecb0e7..89da8d5 100644 --- a/Algo/tp/Cpp/3_tp/src/passager.hpp +++ b/Algo/tp/Cpp/3_tp/src/passager.hpp @@ -18,7 +18,7 @@ private : public : - Passager(std::string nom, std::string prenom); + Passager(const std::string &nom, const std::string &prenom); Wagon* getWagonActuel() const; diff --git a/Algo/tp/Cpp/3_tp/src/train.cpp b/Algo/tp/Cpp/3_tp/src/train.cpp index db6dfe4..e11a0fd 100644 --- a/Algo/tp/Cpp/3_tp/src/train.cpp +++ b/Algo/tp/Cpp/3_tp/src/train.cpp @@ -173,11 +173,11 @@ int Train::monterDansLeTrainAPartirDe(int numeroWagon, Passager& lePassager){ if(codeErreur==-1) return -1; if(codeErreur==0) return numeroWagon; //! Pas oublier de rajouter ça ??!! - unsigned taille = lesWagons.size(); //! unsigned permet d'avoir que des nombres positifs ! + unsigned int taille = lesWagons.size(); //! unsigned permet d'avoir que des nombres positifs ! //? Que se passe-t-il si on a un nombre négatif ??? - //? Pourquoi on le declare pas en int ??? if(numeroWagon <=0 || numeroWagon > (int)taille) return -2; //? Pk on met le int ici ??? + // rajouter (unsigned int) avant le numwagon for(unsigned i = numeroWagon+1; i<=taille; i++){ //? Pourquoi on le declare pas en int ??? codeErreur = monterDansLeTrain(i,lePassager); diff --git a/Algo/tp/Cpp/4_tp/Makefile b/Algo/tp/Cpp/4_tp/Makefile new file mode 100644 index 0000000..88f4002 --- /dev/null +++ b/Algo/tp/Cpp/4_tp/Makefile @@ -0,0 +1,26 @@ +#CC : le compilateur à utiliser +CC=g++ + +#CFLAGS : les options de compilation +CFLAGS= -std=c++17 -Wall + +# les fichiers sources : tous les fichiers présents dans src/ +SRC=$(wildcard src/*.cpp) + +# les fichiers objets (.o) +OBJ=$(patsubst src/%.cpp,obj/%.o,$(SRC)) + + +#edition des liens : génération de l'exécutable à partir des .o +bin/exe: $(OBJ) + $(CC) $(OBJ) -o $@ + +# génération des .o à partir des .cpp et .hpp crrespondants : +obj/%.o: src/%.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +#nettoyage : destruction des .o et de l'exécutable +clean: + rm obj/*.o bin/exe + + diff --git a/Algo/tp/Cpp/4_tp/bin/exe b/Algo/tp/Cpp/4_tp/bin/exe new file mode 100755 index 0000000..59b596f Binary files /dev/null and b/Algo/tp/Cpp/4_tp/bin/exe differ diff --git a/Algo/tp/Cpp/4_tp/src/ingredient.cpp b/Algo/tp/Cpp/4_tp/src/ingredient.cpp new file mode 100644 index 0000000..bd9adae --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/ingredient.cpp @@ -0,0 +1,30 @@ +#include "ingredient.hpp" +#include "quantite.hpp" + + +using namespace std; + +namespace appli { + +Ingredient::Ingredient(const string &aliment, const Quantite &quantite) + : aliment{aliment}, quantite{quantite} +{} + +string Ingredient::getAliment() const { + return aliment; +} + +Quantite Ingredient::getQuantite() const { + return quantite; +} + +ostream &operator<<(ostream &os, const Ingredient &i) { + os << i.getQuantite() << " " << i.getAliment() << endl; + return os; +} + +bool operator==(const Ingredient &i1, const Ingredient &i2) { + return(i1.getAliment() == i2.getAliment()); +} + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/ingredient.hpp b/Algo/tp/Cpp/4_tp/src/ingredient.hpp new file mode 100644 index 0000000..42bae7e --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/ingredient.hpp @@ -0,0 +1,32 @@ +#ifndef INGREDIENT_HPP +#define INGREDIENT_HPP + +#include "quantite.hpp" +#include + + +namespace appli { + + class Ingredient { + std::string aliment; + Quantite quantite; + public: + Ingredient(const std::string &aliment, const Quantite &quantite); + std::string getAliment() const; + Quantite getQuantite() const; + }; + + std::ostream &operator<<(std::ostream &os, const Ingredient &i); + bool operator==(const Ingredient &i1, const Ingredient &i2); +} + +namespace std { + template <> + struct hash { + size_t operator()(const appli::Ingredient &i) const { + return hash()(i.getAliment()); + } + }; +} + +#endif //INGREDIENT_HPP \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/main.cpp b/Algo/tp/Cpp/4_tp/src/main.cpp new file mode 100644 index 0000000..464c0a3 --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/main.cpp @@ -0,0 +1,136 @@ +#include +// #include +#include +#include"unite.hpp" +#include"quantite.hpp" +#include"ingredient.hpp" +#include"recette.hpp" +// #include"recetteAffichage.hpp" + +using namespace std; + +void testUnite(){ + cout << "------------------------------" << endl; + cout << " testUnite() " << endl; + cout << "------------------------------" << endl; + + cout << "Résultat attendu => résultat" << endl; + cout << "kg => " << appli::Unite::KG << endl; + cout << "g => " << appli::Unite::G << endl; + cout << "mL => " << appli::Unite::ML << endl; + cout << "cL => " << appli::Unite::CL << endl; + cout << "dL => " << appli::Unite::DL << endl; + cout << "L => " << appli::Unite::L << endl; + cout << " => " << appli::Unite::UNITE << endl; +} + +void testQuantite(){ + cout << "------------------------------" << endl; + cout << " testQuantite() " << endl; + cout << "------------------------------" << endl; + + cout << "Résultat attendu => résultat" << endl; + cout << "1.0 => " << appli::Quantite{} << endl; + cout << "2.5 => " << appli::Quantite{2.5} << endl; + cout << "1.5L => " << appli::Quantite{1.5, appli::Unite::L} << endl; + + // Partie 3: + // cout << "15L => " << appli::Quantite{15, appli::Unite::L}.normaliser() << endl; + // cout << "1.5L => " << appli::Quantite{15, appli::Unite::DL}.normaliser() << endl; + // cout << "0.15L => " << appli::Quantite{15, appli::Unite::CL}.normaliser() << endl; + // cout << "0.015L => " << appli::Quantite{15, appli::Unite::ML}.normaliser() << endl; + // cout << "15L => " << appli::Quantite{15, appli::Unite::L}.normaliser() << endl; + // cout << "0.8kg => " << appli::Quantite{0.8, appli::Unite::KG}.normaliser() << endl; + // cout << "0.5kg => " << appli::Quantite{500, appli::Unite::G}.normaliser() << endl; + // cout << "2 => " << appli::Quantite{2, appli::Unite::UNITE}.normaliser() << endl; + + // cout << "1.5kg => " << appli::Quantite{1, appli::Unite::KG}+appli::Quantite{500, appli::Unite::G} << endl; + // cout << "0.75L => " << appli::Quantite{5, appli::Unite::DL}+appli::Quantite{250, appli::Unite::ML} << endl; + // cout << "Détection d'erreur ?" << endl; + // cout << appli::Quantite{5, appli::Unite::DL}+appli::Quantite{250, appli::Unite::G} << endl; + +} + +void testIngredient(){ + cout << "------------------------------" << endl; + cout << " testIngredient() " << endl; + cout << "------------------------------" << endl; + + appli::Ingredient i1{"poireaux", appli::Quantite{2.0, appli::Unite::UNITE}}; + appli::Ingredient i2{"pommes de terre", appli::Quantite{300, appli::Unite::G}}; + appli::Ingredient i3{"eau", appli::Quantite{50, appli::Unite::CL}}; + + cout << "Résultat attendu => résultat" << endl; + cout << "2 poireaux => " << i1 << endl; + cout << "300g pommes de terre => " << i2 << endl; + cout << "50cL eau => " << i3 << endl; + + // à compléter + +} + +void testRecette(){ + cout << "------------------------------" << endl; + cout << " testRecette() " << endl; + cout << "------------------------------" << endl; + + appli::Recette r{"Soupe de poireaux", "Faire cuire les légumes puis mixer."}; + + // unordered_set ing; + // ing.insert(appli::Ingredient{"poireaux", appli::Quantite{2, appli::Unite::UNITE}}); + // ing.insert(appli::Ingredient{"pommes de terre", appli::Quantite{300, appli::Unite::G}}); + // ing.insert(appli::Ingredient{"eau", appli::Quantite{50, appli::Unite::CL}}); + + // cout << "Résultat attendu" << endl << "=>" << endl << "résultat" << endl << endl; + // cout << "Soupe de poireaux\n\t300g pommes de terre\n\t50cL eau\n\t2 poireaux" << endl << "=>" << endl; + // afficherNomEtIngredients(r, ing); + + // cout << endl; + // cout << "Soupe de poireaux\n\t300g pommes de terre\n\t50cL eau\n\t2 poireaux\ndescription :\nFaire cuire les légumes puis mixer." << endl << "=>" << endl; + // afficherTout(r, ing); + + // appli::Recette r2{"Crêpes", "Faire fondre le beurre. Mélanger la farine, le sel et le sucre. Y ajouter les oeufs puis le lait et enfin le beurre fondu. Faire cuire à la poêle quelques minutes de chaque côté."}; + + // unordered_set ing2; + // ing2.insert(appli::Ingredient{"farine", appli::Quantite{250, appli::Unite::G}}); + // ing2.insert(appli::Ingredient{"lait", appli::Quantite{0.5, appli::Unite::L}}); + // ing2.insert(appli::Ingredient{"sucre", appli::Quantite{30, appli::Unite::G}}); + // ing2.insert(appli::Ingredient{"oeufs", appli::Quantite{4, appli::Unite::UNITE}}); + // ing2.insert(appli::Ingredient{"sel", appli::Quantite{3, appli::Unite::G}}); + // ing2.insert(appli::Ingredient{"beurre", appli::Quantite{50, appli::Unite::G}}); + + // map> recettes; + // recettes.insert(pair{r,ing}); + // recettes.insert(pair{r2,ing2}); + + // cout << endl; + // cout << "Crêpes\n\t50g beurre\n\t3g sel\n\t4 oeufs\n\t30g sucre\n\t0.5L lait\n\t250g farine\ndescription :\nFaire fondre le beurre. Mélanger la farine, le sel et le sucre. Y ajouter les oeufs puis le lait et enfin le beurre fondu. Faire cuire à la poêle quelques minutes de chaque côté.\nSoupe de poireaux\n\t300g pommes de terre\n\t50cL eau\n\t2 poireaux\ndescription :\nFaire cuire les légumes puis mixer." << endl << "=>" << endl; + // afficherTout(recettes); + + + // cout << endl; + // cout << "Crêpes\nSoupe de poireaux" << endl << "=>" << endl; + // afficherNoms(recettes); + + +} + + +void testLivreRecettes(){ + cout << "------------------------------" << endl; + cout << " testLivreRecettes() " << endl; + cout << "------------------------------" << endl; + + //à compléter + +} + +int main(){ + // testUnite(); + // testQuantite(); + // testIngredient(); + testRecette(); + // testLivreRecettes(); + + return 0; +} \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/quantite.cpp b/Algo/tp/Cpp/4_tp/src/quantite.cpp new file mode 100644 index 0000000..0737c46 --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/quantite.cpp @@ -0,0 +1,25 @@ +#include "quantite.hpp" +#include "unite.hpp" + +using namespace std; + +namespace appli { + +Quantite::Quantite(double nombre, const Unite &unite) + : nombre{nombre}, unite{unite} +{} + +double Quantite::getNombre() const { + return nombre; +} + +Unite Quantite::getUnite() const { + return unite; +} + +ostream &operator<<(ostream &os, const Quantite &q) { + os << q.getNombre() << q.getUnite(); + return os; +} + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/quantite.hpp b/Algo/tp/Cpp/4_tp/src/quantite.hpp new file mode 100644 index 0000000..d733bd3 --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/quantite.hpp @@ -0,0 +1,25 @@ +#ifndef QUANTITE_HPP +#define QUANTITE_HPP + +#include +#include "unite.hpp" + + +namespace appli { + + class Quantite { + double nombre; + Unite unite; + public: + Quantite(double nombre=1, const Unite &unite=Unite::UNITE); + double getNombre() const; + Unite getUnite() const; + Quantite normalier(); + }; + + std::ostream &operator<<(std::ostream &os, const Quantite &q); + // double operator+(const double &n1, const ) +} + + +#endif // QUANTITE_HPP diff --git a/Algo/tp/Cpp/4_tp/src/recette.cpp b/Algo/tp/Cpp/4_tp/src/recette.cpp new file mode 100644 index 0000000..499001c --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/recette.cpp @@ -0,0 +1,24 @@ +#include "recette.hpp" + +using namespace std; + +namespace appli { + +Recette::Recette(const string &nom, const string &description) + : nom{nom}, description{description} +{} + +string Recette::getNom() const { + return nom; +} + +string Recette::getDescription() const { + return description; +} + +ostream &operator<<(ostream &os, const Recette &r) { + os << r.getNom() << " " << r.getDescription(); + return os; +} + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/recette.hpp b/Algo/tp/Cpp/4_tp/src/recette.hpp new file mode 100644 index 0000000..c8ebd29 --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/recette.hpp @@ -0,0 +1,24 @@ +#ifndef RECETTE_HPP +#define RECETTE_HPP + +#include +#include "ingredient.hpp" + + +namespace appli { + + class Recette { + std::string nom; + std::string description; + public: + Recette(const std::string &nom, const std::string &description); + std::string getNom() const; + std::string getDescription() const; + }; +// "operateur prends deux qqt, si q1 == q2 en unité alors on peut construire un nouvelle quantite avec l'unité de q1 ou q2 +// on regarde ce que retourne q1 et q2 normalisé pas d'ajout de kg et litre et donc mettre un message d'erreur en cerr et on return q1" +} + + + +#endif //RECETTE_HPP \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/unite.cpp b/Algo/tp/Cpp/4_tp/src/unite.cpp new file mode 100644 index 0000000..edb22f0 --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/unite.cpp @@ -0,0 +1,25 @@ +#include "unite.hpp" + +using namespace std; +namespace appli { + ostream &operator<<(ostream &os, const Unite &u) { + switch(u) { + case Unite::KG : os << "kg"; + break; + case Unite::G : os << "g"; + break; + case Unite::L : os << "L"; + break; + case Unite::DL : os << "dL"; + break; + case Unite::CL : os << "cL"; + break; + case Unite::ML : os << "mL"; + break; + case Unite::UNITE : os << ""; + break; + }; + return os; + } + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/src/unite.hpp b/Algo/tp/Cpp/4_tp/src/unite.hpp new file mode 100644 index 0000000..5548cbc --- /dev/null +++ b/Algo/tp/Cpp/4_tp/src/unite.hpp @@ -0,0 +1,12 @@ +#ifndef UNITE_HPP +#define UNITE_HPP + +#include + +namespace appli { + enum class Unite{KG, G, L, DL, CL, ML, UNITE}; + + std::ostream &operator<<(std::ostream &os, const Unite &u); +} + +#endif // UNITE_HPP \ No newline at end of file diff --git a/Algo/tp/Cpp/4_tp/tp5_recettes.pdf b/Algo/tp/Cpp/4_tp/tp5_recettes.pdf new file mode 100644 index 0000000..172e512 Binary files /dev/null and b/Algo/tp/Cpp/4_tp/tp5_recettes.pdf differ diff --git a/Algo/tp/Cpp/5_tp/aurevoir.hpp b/Algo/tp/Cpp/5_tp/aurevoir.hpp new file mode 100644 index 0000000..7b5cecb --- /dev/null +++ b/Algo/tp/Cpp/5_tp/aurevoir.hpp @@ -0,0 +1,6 @@ +#ifndef AUREVOIR_HPP +#define AUREVOIR_HPP + +class urevoir { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/5_tp/bonjour.hpp b/Algo/tp/Cpp/5_tp/bonjour.hpp new file mode 100644 index 0000000..44b7c57 --- /dev/null +++ b/Algo/tp/Cpp/5_tp/bonjour.hpp @@ -0,0 +1,6 @@ +#ifndef BONJOUR_HPP +#define BONJOUR_HPP + +class onjour { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/5_tp/nice.hpp b/Algo/tp/Cpp/5_tp/nice.hpp new file mode 100644 index 0000000..09caa1b --- /dev/null +++ b/Algo/tp/Cpp/5_tp/nice.hpp @@ -0,0 +1,6 @@ +#ifndef NICE_HPP +#define NICE_HPP + +class ice { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/6_tp/aurevoir.hpp b/Algo/tp/Cpp/6_tp/aurevoir.hpp new file mode 100644 index 0000000..7b5cecb --- /dev/null +++ b/Algo/tp/Cpp/6_tp/aurevoir.hpp @@ -0,0 +1,6 @@ +#ifndef AUREVOIR_HPP +#define AUREVOIR_HPP + +class urevoir { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/6_tp/bonjour.hpp b/Algo/tp/Cpp/6_tp/bonjour.hpp new file mode 100644 index 0000000..44b7c57 --- /dev/null +++ b/Algo/tp/Cpp/6_tp/bonjour.hpp @@ -0,0 +1,6 @@ +#ifndef BONJOUR_HPP +#define BONJOUR_HPP + +class onjour { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/7_tp/aurevoir.hpp b/Algo/tp/Cpp/7_tp/aurevoir.hpp new file mode 100644 index 0000000..84f4110 --- /dev/null +++ b/Algo/tp/Cpp/7_tp/aurevoir.hpp @@ -0,0 +1,7 @@ +#ifndef AUREVOIR_HPP +#define AUREVOIR_HPP + +class -n A +urevoir { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/7_tp/bonjour.hpp b/Algo/tp/Cpp/7_tp/bonjour.hpp new file mode 100644 index 0000000..0208a48 --- /dev/null +++ b/Algo/tp/Cpp/7_tp/bonjour.hpp @@ -0,0 +1,7 @@ +#ifndef BONJOUR_HPP +#define BONJOUR_HPP + +class -n B +onjour { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/8_tp/bonjour.hpp b/Algo/tp/Cpp/8_tp/bonjour.hpp new file mode 100644 index 0000000..2c5955b --- /dev/null +++ b/Algo/tp/Cpp/8_tp/bonjour.hpp @@ -0,0 +1,7 @@ +#ifndef BONJOUR_HPP +#define BONJOUR_HPP + +class -n B +-n onjour { + +} \ No newline at end of file diff --git a/Algo/tp/Cpp/tp4/.idea/.gitignore b/Algo/tp/Cpp/tp4/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/Algo/tp/Cpp/tp4/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/Algo/tp/Cpp/tp4/.idea/discord.xml b/Algo/tp/Cpp/tp4/.idea/discord.xml deleted file mode 100644 index 30bab2a..0000000 --- a/Algo/tp/Cpp/tp4/.idea/discord.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Algo/tp/Cpp/tp4/.idea/misc.xml b/Algo/tp/Cpp/tp4/.idea/misc.xml deleted file mode 100644 index 53624c9..0000000 --- a/Algo/tp/Cpp/tp4/.idea/misc.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Algo/tp/Cpp/tp4/.vscode/settings.json b/Algo/tp/Cpp/tp4/.vscode/settings.json deleted file mode 100644 index d67b24e..0000000 --- a/Algo/tp/Cpp/tp4/.vscode/settings.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "files.associations": { - "__bit_reference": "cpp", - "__config": "cpp", - "__debug": "cpp", - "__errc": "cpp", - "__functional_base": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__mutex_base": "cpp", - "__node_handle": "cpp", - "__nullptr": "cpp", - "__split_buffer": "cpp", - "__string": "cpp", - "__threading_support": "cpp", - "__tuple": "cpp", - "algorithm": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "exception": "cpp", - "functional": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "iterator": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "utility": "cpp", - "vector": "cpp" - } -} \ No newline at end of file diff --git a/Algo/tp/Cpp/tp4/Makefile b/Algo/tp/Cpp/tp4/Makefile deleted file mode 100644 index e40974c..0000000 --- a/Algo/tp/Cpp/tp4/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -cc=g++ -std=c++17 -g -Wall -Werror -pedantic - -all: tp - -obj/Wagon.o: src/Wagon.cpp src/Wagon.h src/Passager.h - $(cc) -c src/Wagon.cpp -o obj/Wagon.o -obj/Passager.o: src/Passager.cpp src/Passager.h - $(cc) -c src/Passager.cpp -o obj/Passager.o -obj/main.o: src/main.cpp src/Train.h src/Wagon.h src/Passager.h \ - src/TrainExceptions.h - $(cc) -c src/main.cpp -o obj/main.o -obj/Train.o: src/Train.cpp src/Train.h src/Wagon.h src/Passager.h \ - src/TrainExceptions.h - $(cc) -c src/Train.cpp -o obj/Train.o - -tp: obj/Wagon.o obj/Passager.o obj/main.o obj/Train.o - $(cc) obj/Wagon.o obj/Passager.o obj/main.o obj/Train.o -o tp - -clean: - rm -Rf obj/* tp diff --git a/Algo/tp/Cpp/tp4/obj/Passager.o b/Algo/tp/Cpp/tp4/obj/Passager.o deleted file mode 100644 index a89162f..0000000 Binary files a/Algo/tp/Cpp/tp4/obj/Passager.o and /dev/null differ diff --git a/Algo/tp/Cpp/tp4/obj/Train.o b/Algo/tp/Cpp/tp4/obj/Train.o deleted file mode 100644 index 1033691..0000000 Binary files a/Algo/tp/Cpp/tp4/obj/Train.o and /dev/null differ diff --git a/Algo/tp/Cpp/tp4/obj/Wagon.o b/Algo/tp/Cpp/tp4/obj/Wagon.o deleted file mode 100644 index 575a3f8..0000000 Binary files a/Algo/tp/Cpp/tp4/obj/Wagon.o and /dev/null differ diff --git a/Algo/tp/Cpp/tp4/obj/main.o b/Algo/tp/Cpp/tp4/obj/main.o deleted file mode 100644 index dfcb23d..0000000 Binary files a/Algo/tp/Cpp/tp4/obj/main.o and /dev/null differ diff --git a/Algo/tp/Cpp/tp4/src/Passager.cpp b/Algo/tp/Cpp/tp4/src/Passager.cpp deleted file mode 100644 index 80cf871..0000000 --- a/Algo/tp/Cpp/tp4/src/Passager.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "Passager.h" - -using namespace std; - -Passager::Passager(std::string nom, std::string prenom) - : nom{std::move(nom)}, prenom{std::move(prenom)} {} - -/*Passager& Passager::operator=(const Passager& o) { - if (o == *this) return *this; - nom = o.bom; - prenom = o.nom; - return *this; -}*/ - -std::ostream& operator<<(std::ostream& os, const Passager& passager) { - return os << passager.nom << " " << passager.prenom; -} diff --git a/Algo/tp/Cpp/tp4/src/Passager.h b/Algo/tp/Cpp/tp4/src/Passager.h deleted file mode 100644 index f73cba8..0000000 --- a/Algo/tp/Cpp/tp4/src/Passager.h +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -class Passager { -private: - std::string nom; - std::string prenom; -public: - friend std::ostream& operator<<(std::ostream& os, const Passager& passagers); - Passager() = default; - Passager(std::string nom, std::string prenom); - Passager& operator=(const Passager& o) = default; -}; - -std::ostream& operator<<(std::ostream& os, const Passager& passager); - diff --git a/Algo/tp/Cpp/tp4/src/Train.cpp b/Algo/tp/Cpp/tp4/src/Train.cpp deleted file mode 100644 index e96b5f8..0000000 --- a/Algo/tp/Cpp/tp4/src/Train.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include "Train.h" - -#include "TrainExceptions.h" - -// Si des passagers peuvent être à deux endroits à la fois, il va potentiellement falloir le faire descendre deux fois du train. -#define UBIQUITE - -using namespace std; - -Train::Train(int nbWagons) - : lesWagons{} { - for (int i = 1; i <= nbWagons; ++i) { - lesWagons.emplace_back(i); - } -} - -Train::Train(std::initializer_list listeNumerosWagons) - : lesWagons{} { - //lesWagons.reserve(listeNumerosWagons.size()); - for (int numWagon : listeNumerosWagons) { - //lesWagons.push_back(new Wagon{numWagon}); - lesWagons.emplace_back(numWagon); - } -} - -void Train::demarrer() { - roule = true; -} - -void Train::arreter() { - roule = false; -} - -bool Train::isRoule() const { - return roule; -} - -void Train::monterDansLeTrain(int numeroWagon, const Passager& passager) { - if (roule) { - throw RouleException{}; - } - // -> map - for (Wagon& wagon : lesWagons) { - if (wagon.getNumero() == numeroWagon) { - if (!wagon.ajouter(passager)) { - throw WagonPleinException{}; - } - return; - } - } - throw WagonInexistantException{}; -} - -void Train::descendreDuTrain(const Passager& passager) { - if (roule) { - throw RouleException{}; - } -#ifdef UBIQUITE - bool descendu = false; - for (Wagon& wagon : lesWagons) { - descendu |= wagon.enlever(passager); - } - if (!descendu) { - throw PassagerException{}; - } -#else - for (Wagon& wagon : lesWagons) { - if (wagon.enlever(passager)) { - return; - } - } - throw PassagerException{}; -#endif -} - -void Train::deplacerAuWagonSuivant(const Passager& passager) { - if (roule) { - throw RouleException{}; - } - vector::iterator it = lesWagons.begin(); - while (it != lesWagons.end() && !it->enlever(passager)) { - ++it; - } - if (it == lesWagons.end()) { - throw PassagerException{}; - } - ++it; - if (it == lesWagons.end()) { - throw BoutDuTrainException{}; - } - if (it->estPlein()) { - throw WagonPleinException{}; - } - it->ajouter(passager); -} - -void Train::deplacerAuWagonPrecedent(const Passager& passager) { - if (roule) { - throw RouleException{}; - } - vector::reverse_iterator it = lesWagons.rbegin(); - while (it != lesWagons.rend() && !it->enlever(passager)) { - ++it; - } - if (it == lesWagons.rend()) { - throw PassagerException{}; - } - ++it; - if (it == lesWagons.rend()) { - throw BoutDuTrainException{}; - } - if (it->estPlein()) { - throw WagonPleinException{}; - } - it->ajouter(passager); -} - -int Train::monterDansLeTrainAPartirDe(int numeroWagon, const Passager& passager) { - if (roule) { - throw RouleException{}; - } - vector::iterator it = lesWagons.begin(); - while (it != lesWagons.end() && it->getNumero() != numeroWagon) { - ++it; - } - if (it == lesWagons.end()) { - throw WagonInexistantException{}; - } - while (it != lesWagons.end() && it->estPlein()) { - ++it; - } - if (it == lesWagons.end()) { - throw BoutDuTrainException{}; - } - it->ajouter(passager); - return it->getNumero(); -} diff --git a/Algo/tp/Cpp/tp4/src/Train.h b/Algo/tp/Cpp/tp4/src/Train.h deleted file mode 100644 index 3a03bd9..0000000 --- a/Algo/tp/Cpp/tp4/src/Train.h +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#include "Wagon.h" - -class Train { -private: - std::vector lesWagons; - bool roule{}; -public: - explicit Train(int nbWagons); - Train(std::initializer_list listeNumerosWagons); - void demarrer(); - void arreter(); - bool isRoule() const; - void monterDansLeTrain(int numeroWagon, const Passager& passager); - int monterDansLeTrainAPartirDe(int numeroWagon, const Passager& passager); - void descendreDuTrain(const Passager& passager); - void deplacerAuWagonPrecedent(const Passager& passager); - void deplacerAuWagonSuivant(const Passager& passager); -}; - diff --git a/Algo/tp/Cpp/tp4/src/TrainExceptions.h b/Algo/tp/Cpp/tp4/src/TrainExceptions.h deleted file mode 100644 index 29f4413..0000000 --- a/Algo/tp/Cpp/tp4/src/TrainExceptions.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef TRAIN_EXCEPTIONS_HPP -#define TRAIN_EXCEPTIONS_HPP - -class RouleException {}; -class WagonInexistantException {}; -class WagonPleinException {}; -class PassagerException {}; -class BoutDuTrainException {}; - -#endif // TRAIN_EXCEPTIONS_HPP diff --git a/Algo/tp/Cpp/tp4/src/Wagon.cpp b/Algo/tp/Cpp/tp4/src/Wagon.cpp deleted file mode 100644 index 0f6d81b..0000000 --- a/Algo/tp/Cpp/tp4/src/Wagon.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "Wagon.h" - -Wagon::Wagon(int numero) : numero{numero}, lesPassagers{} { - -} - -int Wagon::getNumero() const { - return numero; -} - -bool Wagon::estPlein() const { - return lesPassagers.size() >= capacite; -} - -bool Wagon::ajouter(const Passager& passager) { - if (lesPassagers.size() >= capacite) { - return false; - } - lesPassagers.push_front(&passager); - return true; -} - -bool Wagon::enlever(const Passager& passager) { - std::list::size_type previous = lesPassagers.size(); - lesPassagers.remove(&passager); - return previous != lesPassagers.size(); -} - -int Wagon::debarquer(int nbPassager) { - int c = nbPassager; - while (!lesPassagers.empty() && c > 0) { - lesPassagers.pop_back(); - --c; - } - return nbPassager - c; -} - -std::ostream& operator<<(std::ostream& os, const Wagon& wagon) { - if (wagon.lesPassagers.empty()) { - return os; - } - std::list::const_iterator it = wagon.lesPassagers.cbegin(); - os << **it; - while (++it != wagon.lesPassagers.cend()) { - os << ", " << **it; - } - return os; -} diff --git a/Algo/tp/Cpp/tp4/src/Wagon.h b/Algo/tp/Cpp/tp4/src/Wagon.h deleted file mode 100644 index 53af1fe..0000000 --- a/Algo/tp/Cpp/tp4/src/Wagon.h +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -#include "Passager.h" - -class Wagon { -private: - constexpr static int capacite = 20; - int numero; - std::list lesPassagers; -public: - friend std::ostream& operator<<(std::ostream& os, const Wagon& wagon); - explicit Wagon(int numero); - int getNumero() const; - bool estPlein() const; - bool ajouter(const Passager& passager); - bool enlever(const Passager& passager); - int debarquer(int nbPassager); -}; - -std::ostream& operator<<(std::ostream& os, const Wagon& wagon); diff --git a/Algo/tp/Cpp/tp4/src/main.cpp b/Algo/tp/Cpp/tp4/src/main.cpp deleted file mode 100644 index b64e681..0000000 --- a/Algo/tp/Cpp/tp4/src/main.cpp +++ /dev/null @@ -1,355 +0,0 @@ -#include "Train.h" -#include "TrainExceptions.h" - -#include -#include - -using namespace std; -using Gens = std::array; - -void testsWagon() { - Passager pierre("Dupont", "Pierre"); - Passager paul("Durand", "Paul"); - - cout << "Vérif si wagon gère correctement son numero... "; - Wagon wagon{42}; - cout << (wagon.getNumero() == 42 ? "OK\n" : "ERREUR\n"); - - cout << "Vérif si possible de faire monter 20 personnes dans un wagon... "; - Gens gens; - for (Gens::size_type i{0}; i < gens.size(); ++i) - gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"}; - - bool ajoutOK{true}; - for (const Passager &personne : gens) { - ajoutOK = ajoutOK && wagon.ajouter(personne); - } - cout << (ajoutOK ? "OK\n" : "ERREUR\n"); - //cout << wagon << "\n"; - - cout << "Vérif si impossible de faire monter 1 personne dans un wagon " - "plein... "; - cout << (wagon.ajouter(pierre) ? "ERREUR\n" : "OK\n"); - - cout << "Vérif si possible de faire debarquer 14 personnes sur 20... "; - cout << (wagon.debarquer(14) == 14 ? "OK\n" : "ERREUR\n"); - // cout << wagon; - - cout << "Vérif si possible de faire debarquer les 6 passagers restants... "; - cout << (wagon.debarquer(20) == 6 ? "OK\n" : "ERREUR\n"); - // cout << wagon; - - cout << "Vérif si possible de faire debarquer 1 passager donné... "; - wagon.ajouter(pierre); - cout << (wagon.enlever(pierre) ? "OK\n" : "ERREUR\n"); - - cout << "Vérif si impossible de faire debarquer 1 passager pas dans le " - "wagon... "; - cout << (wagon.enlever(paul) ? "ERREUR\n" : "OK\n"); - - cout << "Vérif si impossible de faire debarquer 1 passager d'un wagon " - "vide... "; - cout << (wagon.enlever(pierre) ? "ERREUR\n" : "OK\n"); -} - -void testMonterDansTrain() { - Passager pierre{"Dupont", "Pierre"}; - Train train(3); - - cout << "Vérif si impossible de monter dans un train qui roule... "; - train.demarrer(); - try { - train.monterDansLeTrain(1, pierre); - cout << "ERREUR\n"; - } catch (const RouleException &) { - cout << " OK\n"; - } - - cout << "Vérif si impossible de monter si numéro de wagon non existant... "; - train.arreter(); - try { - train.monterDansLeTrain(4, pierre); - cout << "ERREUR\n"; - } catch (const WagonInexistantException &) { - cout << "OK\n"; - } - - cout << "Vérif si possible de faire monter 20 personnes dans un wagon " - "existant, non complet et train arrêté... "; - Gens gens; - for (Gens::size_type i{0}; i < gens.size(); ++i) - gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"}; - - try { - for (const Passager &personne : gens) { - train.monterDansLeTrain(1, personne); - } - cout << "OK\n"; - } catch (...) { - cout << "ERREUR\n"; - } - - cout << "Vérif si impossible de monter dans le wagon si déjà complet... "; - try { - train.monterDansLeTrain(1, pierre); - cout << "ERREUR\n"; - } catch (const WagonPleinException &) { - cout << "OK\n"; - } -} - -void testDescendreDuTrain() { - Passager pierre("Dupont", "Pierre"); - Passager paul("Durand", "Paul"); - Train train(3); - - // cout << "Pierre monte dans le wagon 1\n"; - train.monterDansLeTrain(1, pierre); - - cout << "Vérif si impossible de descendre du train qui roule... "; - train.demarrer(); - try { - train.descendreDuTrain(pierre); - cout << "ERREUR\n"; - } catch (const RouleException &) { - cout << " OK\n"; - } - - // cout << "Paul n'est pas dans le train\n"; - cout << "Vérif si impossible de descendre du train sans s'y trouver... "; - train.arreter(); - try { - train.descendreDuTrain(paul); - cout << "ERREUR\n"; - } catch (const PassagerException &) { - cout << "OK\n"; - } - - cout << "Vérif si possible de descendre du wagon existant et train " - "arrêté... "; - try { - train.descendreDuTrain(pierre); - cout << " OK\n"; - } catch (...) { - cout << "ERREUR\n"; - } -} - -void testDeplacerAuWagonSuivant() { - Passager alice("Dups", "Alice"); - Passager pierre("Dupont", "Pierre"); - Passager paul("Durand", "Paul"); - Passager marie("Dumont", "Marie"); - Train train(3); - - // cout << "Pierre monte dans le premier wagon (1)\n"; - train.monterDansLeTrain(1, pierre); - // cout << "Paul monte dans le wagon 2\n"; - train.monterDansLeTrain(2, paul); - // cout << "Marie monte dans le dernier wagon (3)\n"; - train.monterDansLeTrain(3, marie); - // cout << "Alice n'est pas dans le train\n"; - - cout << "Vérif si impossible de déplacer un passager qui n'est pas dans le " - "train... "; - try { - train.deplacerAuWagonSuivant(alice); - cout << "ERREUR\n"; - } catch (const PassagerException &) { - cout << " OK\n"; - } - - cout << "Vérif si impossible de passer au wagon suivant car déjà dans le " - "dernier wagon... "; - try { - train.deplacerAuWagonSuivant(marie); - cout << "ERREUR\n"; - } catch (const BoutDuTrainException &) { - cout << " OK\n"; - } - - Gens gens; - for (Gens::size_type i{0}; i < gens.size() - 1; ++i) - gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"}; - - try { - for (const Passager &personne : gens) - train.monterDansLeTrain(3, personne); - } catch (...) { - cout << "ERREUR le wagon 3 devrait pouvoir contenir 20 passagers !\n"; - } - - cout << "Vérif si impossible de passer au wagon suivant car wagon déjà " - "complet... "; - try { - train.deplacerAuWagonSuivant(paul); - cout << "ERREUR\n"; - } catch (const WagonPleinException &) { - cout << "OK\n"; - } - - cout << "Vérif si possible de passer au wagon suivant (bonnes " - "conditions)... "; - try { - train.deplacerAuWagonSuivant(pierre); - cout << "OK\n"; - } catch (...) { - cout << "ERREUR\n"; - } -} - -void testDeplacerAuWagonPrecedent() { - Passager alice("Dups", "Alice"); - Passager pierre("Dupont", "Pierre"); - Passager paul("Durand", "Paul"); - Passager marie("Dumont", "Marie"); - Train train(3); - - // cout << "Pierre monte dans le premier wagon (1)\n"; - train.monterDansLeTrain(1, pierre); - // cout << "Paul monte dans le wagon 2\n"; - train.monterDansLeTrain(2, paul); - // cout << "Marie monte dans le dernier wagon (3)\n"; - train.monterDansLeTrain(3, marie); - // cout << "Alice n'est pas dans le train\n"; - - cout << "Vérif si impossible de déplacer au wagon précédent un passager " - "qui n'est pas dans le train... "; - try { - train.deplacerAuWagonPrecedent(alice); - cout << "ERREUR\n"; - } catch (const PassagerException &) { - cout << " OK\n"; - } - - cout << "Vérif si impossible de passer au wagon précédent car déjà dans le " - "premier wagon... "; - try { - train.deplacerAuWagonPrecedent(pierre); - cout << "ERREUR\n"; - } catch (const BoutDuTrainException &) { - cout << " OK\n"; - } - - Gens gens; - for (Gens::size_type i{0}; i < gens.size() - 1; ++i) - gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"}; - - try { - for (const Passager &personne : gens) - train.monterDansLeTrain(1, personne); - } catch (...) { - cout << "ERREUR le wagon 1 devrait pouvoir contenir 20 passagers !\n"; - } - - cout << "Vérif si impossible de passer au wagon précédent car wagon déjà " - "complet... "; - try { - train.deplacerAuWagonPrecedent(paul); - cout << "ERREUR\n"; - } catch (const WagonPleinException &) { - cout << "OK\n"; - } - - cout << "Vérif si possible de passer au wagon précédent (bonnes " - "conditions)... "; - try { - train.deplacerAuWagonPrecedent(marie); - cout << "OK\n"; - } catch (...) { - cout << "ERREUR\n"; - } -} - -void testMonterDansLeTrainAPartirDe() { - Passager pierre("Dupont", "Pierre"); - Train train(3); - - cout << "Vérif si impossible de monter à partir d'un numero de wagon non " - "existant... "; - try { - train.monterDansLeTrainAPartirDe(4, pierre); - cout << "ERREUR\n"; - } catch (const WagonInexistantException &) { - cout << "OK\n"; - } - - train.demarrer(); - cout << "Vérif si impossible de monter dans un train qui roule... "; - try { - train.monterDansLeTrainAPartirDe(1, pierre); - cout << "ERREUR\n"; - } catch (const RouleException &) { - cout << "OK\n"; - } - - train.arreter(); - Gens gens; - for (Gens::size_type i{0}; i < gens.size() - 1; ++i) - gens[i] = Passager{"Personne " + to_string(i + 1), "Autogénérée"}; - - // On remplit tous les wagons (on triche un peu) - // Magie de l'informatique, on donne le don d'ubiquité aux gens - try { - for (const Passager &personne : gens) { - train.monterDansLeTrain(1, personne); - train.monterDansLeTrain(2, personne); - train.monterDansLeTrain(3, personne); - } - } catch (...) { - cout << "ERREUR on devrait pouvoir remplir le train !\n"; - } - - cout << "Vérif si impossible de monter dans un train complet... "; - try { - train.monterDansLeTrainAPartirDe(1, pierre); - cout << "ERREUR\n"; - } catch (const BoutDuTrainException &) { - cout << "OK\n"; - } - - try { - for (const Passager &personne : gens) { - train.descendreDuTrain(personne); - } - } catch (...) { - cout << "ERREUR on devrait pouvoir vider le premier wagon !\n"; - } - - cout << "Vérif si on peut monter dans un train où il y a de la place... "; - try { - int pos = train.monterDansLeTrainAPartirDe(2, pierre); - cout << "OK, " << pierre << " est monté dans le wagon " << pos << "\n"; - } catch (...) { - cout << "ERREUR\n"; - } - - cout << "Vérif si le passager peut descendre... "; - try { - train.descendreDuTrain(pierre); - cout << "OK\n"; - } catch (...) { - cout << "ERREUR\n"; - } -} - -int main() { - cout << "---------- TESTS WAGONS ------------\n"; - testsWagon(); - - cout << "---------- TEST MONTER DANS LE TRAIN ------------\n"; - testMonterDansTrain(); - - cout << "---------- TEST DESCENDRE DU TRAIN ------------\n"; - testDescendreDuTrain(); - - cout << "---------- TEST DEPLACER AU WAGON SUIVANT ------------\n"; - testDeplacerAuWagonSuivant(); - - cout << "---------- TEST DEPLACER AU WAGON PRECEDENT ------------\n"; - testDeplacerAuWagonPrecedent(); - - cout << "---------- TEST MONTER DANS LE TRAIN A PARTIR DE " - "------------\n"; - testMonterDansLeTrainAPartirDe(); -} diff --git a/Algo/tp/Cpp/tp4/tp b/Algo/tp/Cpp/tp4/tp deleted file mode 100755 index b4e0fb8..0000000 Binary files a/Algo/tp/Cpp/tp4/tp and /dev/null differ