diff --git a/Algo/tp/Cpp/3_tp/Makefile b/Algo/tp/Cpp/3_tp/Makefile new file mode 100644 index 0000000..88f4002 --- /dev/null +++ b/Algo/tp/Cpp/3_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/3_tp/src/passager.cpp b/Algo/tp/Cpp/3_tp/src/passager.cpp new file mode 100644 index 0000000..c4582f0 --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/passager.cpp @@ -0,0 +1,16 @@ +#include "passager.hpp" +#include +#include + +using namespace std; + +Passager::Passager(string nom, string prenom) + :nom{nom}, prenom{prenom} +{} + +Wagon Passager::getWagonActuel() const { + return *wagonActuel; +} + + + diff --git a/Algo/tp/Cpp/3_tp/src/passager.hpp b/Algo/tp/Cpp/3_tp/src/passager.hpp new file mode 100644 index 0000000..ac0dd1f --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/passager.hpp @@ -0,0 +1,25 @@ +#ifndef PASSAGER_HPP +#define PASSAGER_HPP + +#include +#include "wagon.hpp" + +class Passager { +private : + + std::string nom; + std::string prenom; + + Wagon *wagonActuel; + +public : + + Passager(std::string nom, std::string prenom); + + Wagon getWagonActuel() const; + + ~Passager(); +}; + + +#endif // PASSAGER_HPP \ No newline at end of file diff --git a/Algo/tp/Cpp/3_tp/src/test.cpp b/Algo/tp/Cpp/3_tp/src/test.cpp new file mode 100644 index 0000000..eea10aa --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/test.cpp @@ -0,0 +1,30 @@ +#include "wagon.hpp" +#include "passager.hpp" +#include "train.hpp" +#include +#include + + +using namespace std; + +void testPassager(void) { + Passager lePassager("Passager 1", "Prenom 1"); + cout << lePassager.getNom() << endl; +} + +void testWagon(void) { + Wagon leWagon("Wagon 1"); + cout << leWagon.getNom() << endl; +} + +void testTrain(void) { + Train leTrain("Train 1"); + cout << leTrain.getNom() << endl; +} + +int main() { + testPassager(); + testWagon(); + testTrain(); + return 0; +} \ No newline at end of file diff --git a/Algo/tp/Cpp/3_tp/src/train.cpp b/Algo/tp/Cpp/3_tp/src/train.cpp new file mode 100644 index 0000000..a20d33e --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/train.cpp @@ -0,0 +1,25 @@ +#include "train.hpp" +#include +#include +#include + +using namespace std; + +Train::Train(string nom) + :nom{nom} +{} + +int Train::ajouter(Wagon leWagon) { + lesWagons->push_back(leWagon); + return 0; +} + +int Train::enlever(Wagon leWagon) { + lesWagons->remove(leWagon); + return 0; +} + +Train::~Train() { + delete lesWagons; +} + diff --git a/Algo/tp/Cpp/3_tp/src/train.hpp b/Algo/tp/Cpp/3_tp/src/train.hpp new file mode 100644 index 0000000..7132b37 --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/train.hpp @@ -0,0 +1,27 @@ +#ifndef TRAIN_HPP +#define TRAIN_HPP + +#include + +#include "wagon.hpp" + +class Train { +private : + + std::string nom; + std::list *lesWagons; + +public : + + Train(std::string nom); + + int ajouter(Wagon leWagon); + int enlever(Wagon leWagon); + + ~Train(); + }; + + + + +#endif // TRAIN_HPP \ No newline at end of file diff --git a/Algo/tp/Cpp/3_tp/src/wagon.cpp b/Algo/tp/Cpp/3_tp/src/wagon.cpp new file mode 100644 index 0000000..035e18d --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/wagon.cpp @@ -0,0 +1,27 @@ +#include "wagon.hpp" +#include +#include + +Wagon::Wagon(int numero) + :numero{numero} +{} + +int Wagon::ajouter(Passager lePassager) { + if(lesPassagers->size() == capacite) { + return -1; + } + lesPassagers->push_back(lePassager); + return 0; +} + +int Wagon::enlever(Passager lePassager) { + if(lesPassagers->size() == 0) { + return -1; + } + lesPassagers->remove(lePassager); + return 0; +} + +// ostream &operator<<(ostream &s, const Passager &p) { + +// } \ No newline at end of file diff --git a/Algo/tp/Cpp/3_tp/src/wagon.hpp b/Algo/tp/Cpp/3_tp/src/wagon.hpp new file mode 100644 index 0000000..7d62cc4 --- /dev/null +++ b/Algo/tp/Cpp/3_tp/src/wagon.hpp @@ -0,0 +1,30 @@ +#ifndef WAGON_HPP +#define WAGON_HPP + +#include +#include +#include "passager.hpp" + +class Wagon { + +private : + + int numero; + + std::list *lesPassagers; + +public : + + static const int capacite = 20; + + Wagon(int numero); + + int ajouter(Passager lePassager); + int enlever(Passager lePassager); + + ~Wagon() = default; //~Wagon(){}; +}; + +std::ostream &operator<<(std::ostream &s, const Passager &p); + +#endif // WAGON_HPP \ No newline at end of file diff --git a/Algo/tp/Cpp/3_tp/tp3_list_vector_train.pdf b/Algo/tp/Cpp/3_tp/tp3_list_vector_train.pdf new file mode 100644 index 0000000..8f88874 Binary files /dev/null and b/Algo/tp/Cpp/3_tp/tp3_list_vector_train.pdf differ