parent
f8eaeab343
commit
a28a6b96b7
@ -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
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
#include "passager.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Passager::Passager(string nom, string prenom)
|
||||
:nom{nom}, prenom{prenom}
|
||||
{}
|
||||
|
||||
Wagon Passager::getWagonActuel() const {
|
||||
return *wagonActuel;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
#ifndef PASSAGER_HPP
|
||||
#define PASSAGER_HPP
|
||||
|
||||
#include <string>
|
||||
#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
|
@ -0,0 +1,30 @@
|
||||
#include "wagon.hpp"
|
||||
#include "passager.hpp"
|
||||
#include "train.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
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;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#include "train.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
#ifndef TRAIN_HPP
|
||||
#define TRAIN_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "wagon.hpp"
|
||||
|
||||
class Train {
|
||||
private :
|
||||
|
||||
std::string nom;
|
||||
std::list<Wagon> *lesWagons;
|
||||
|
||||
public :
|
||||
|
||||
Train(std::string nom);
|
||||
|
||||
int ajouter(Wagon leWagon);
|
||||
int enlever(Wagon leWagon);
|
||||
|
||||
~Train();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // TRAIN_HPP
|
@ -0,0 +1,27 @@
|
||||
#include "wagon.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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) {
|
||||
|
||||
// }
|
@ -0,0 +1,30 @@
|
||||
#ifndef WAGON_HPP
|
||||
#define WAGON_HPP
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "passager.hpp"
|
||||
|
||||
class Wagon {
|
||||
|
||||
private :
|
||||
|
||||
int numero;
|
||||
|
||||
std::list<Passager> *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
|
Binary file not shown.
Loading…
Reference in new issue