ajout des tp de Cpp et du sujet de SAE2.02

master
Antoine PEREDERII 2 years ago
parent a97bbbbd70
commit f8a028e776

@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/SAE/SAE2.06-Travail_d_equipe" vcs="Git" />
</component> </component>
</project> </project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

@ -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,10 @@
#include "carte.hpp"
#include <iostream>
using namespace std;
Carte::Carte(Nom nom, Couleur couleur)
: nom{nom}, couleur{couleur}
{}

@ -0,0 +1,38 @@
#ifndef CARTE_HPP
#define CARTE_HPP
#include <iostream>
enum class Couleur {
BLEU,
ROUGE,
VERT,
ROSE,
JAUNE,
ORANGE,
NOIR
};
enum class Nom {
ROI,
RENNE,
CAVALIER,
DRAGON,
ENCHANTEUR,
MOINE,
PAYSAN,
SORCIER
};
class Carte {
Nom nom;
Couleur couleur;
public:
Carte(Nom nom, Couleur couleur);
};
#endif // CARTE_HPP

@ -0,0 +1,17 @@
// #include "jeu.hpp"
// #include <iostream>
// using namespace std;
// Jeu::Jeu()
// :
// {}
// ostream &operator<<(ostream &os, const Jeu &j) {
// return os;
// }

@ -0,0 +1,17 @@
// #ifndef JEU_HPP
// #define JEU_HPP
// #include <iostream>
// class Jeu {
// public:
// Jeu();
// friend std::ostream &operator<<(ostream &os, const Jeu &j);
// ~Jeu()=default;
// };
// #endif // JEU_HPP

@ -0,0 +1,17 @@
#include "joueur.hpp"
#include <iostream>
using namespace std;
Joueur::Joueur(string pseudo)
: pseudo{pseudo}
{}
ostream &operator<<(ostream &os, const Joueur &j) {
return os;
}

@ -0,0 +1,27 @@
#ifndef JOUEUR_HPP
#define JOUEUR_HPP
#include <iostream>
#include <list>
#include "carte.hpp"
class Joueur {
std::string pseudo;
list<Carte> lesCartes;
public:
Joueur(std::string pseudo);
std::string getPseudo();
Carte donnerCarte(int num);
bool recevoirCarte(Carte c);
void prendreCarte(Joueur j);
~Joueur()=default;
};
#endif // JOUEUR_HPP

@ -0,0 +1,7 @@
int main() {
return 0;
}

Binary file not shown.

@ -1,29 +1,67 @@
#include "livreRecettes.hpp" #include "livreRecettes.hpp"
#include "recetteAffichage.hpp"
#include "ingredient.hpp"
#include <map>
#include <algorithm>
using namespace std; using namespace std;
namespace appli { namespace appli {
// map<Recette, unordered_set<Ingredient>> LivreRecettes::rechercherRecette(const string &nomRecette) { map<Recette, unordered_set<Ingredient>> LivreRecettes::rechercherRecette(const string &nomRecette) {
// for(auto it = ) map<Recette, unordered_set<Ingredient>> rech;
// } for(auto it = livre.cbegin(); it != livre.cend(); ++it) {
if(it->first.getNom() == nomRecette) {
rech.insert({it->first, it->second});
}
}
return rech;
}
map<string, Quantite> LivreRecettes::faireListeCourses(list<Recette> l) { map<string, Quantite> LivreRecettes::faireListeCourses(list<Recette> l) {
string nomRecette;
int rep;
cout << "Quelle recette voulez vous ? " << endl;
cin >> nomRecette;
map<Recette, unordered_set<Ingredient>>::iterator it = livre.find(nomRecette);
// it = this->rechercherRecette(nomRecette);
for(const Ingredient &ing : it->second) {
cout << "avez vous du, des " << ing << " ? (0 : non/1 : oui)" << endl;
cin >> rep;
if(rep == 0) {
l.push_back(ing);
}
}
} }
void LivreRecettes::ajouter(const Recette &r, list<Ingredient> l) { void LivreRecettes::ajouter(const Recette &r, list<Ingredient> l) {
unordered_set<Ingredient> ing;
l.push_back(r) if(livre.find(r) != livre.end()) {
ajouter dans le livre la rec cout << "recette déjà présente" << endl;
return;
}
for(Ingredient i : l) {
unordered_set<Ingredient>::iterator it2 = ing.find(i);
if(it2 == ing.end()) {
ing.insert(i);
}
else {
Quantite q = i.getQuantite() + it2->getQuantite();
ing.erase(it2);
ing.insert(Ingredient{i.getAliment(), q});
}
}
livre.insert({r, ing});
} }
void LivreRecettes::afficherNomRecette() { void LivreRecettes::afficherNomRecette() {
afficherNoms(livre);
} }
void LivreRecettes::afficher() { void LivreRecettes::afficher() {
afficherTout(livre);
} }
} }

@ -11,7 +11,7 @@ namespace appli {
class LivreRecettes { class LivreRecettes {
std::list<Ingredient *> livre; std::map<Recette, std::unordered_set<Ingredient>> livre;
public: public:

@ -6,6 +6,7 @@
#include"ingredient.hpp" #include"ingredient.hpp"
#include"recette.hpp" #include"recette.hpp"
#include"recetteAffichage.hpp" #include"recetteAffichage.hpp"
#include "livreRecettes.hpp"
using namespace std; using namespace std;
@ -121,14 +122,37 @@ void testLivreRecettes(){
cout << " testLivreRecettes() " << endl; cout << " testLivreRecettes() " << endl;
cout << "------------------------------" << endl; cout << "------------------------------" << endl;
// appli::Recette r{"Soupe de poireaux", "Faire cuire les légumes puis mixer."};
// unordered_set<appli::Ingredient> 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}});
// 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<appli::Ingredient> 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<appli::Recette, unordered_set<appli::Ingredient>> livre;
// appli::LivreRecettes::ajouter(r, ing);
// appli::LivreRecettes::ajouter(r2, ing2);
// livre.appli::LivreRecette::afficherNomRecette()
//à compléter //à compléter
} }
int main(){ int main(){
// testUnite(); testUnite();
// testQuantite(); testQuantite();
// testIngredient(); testIngredient();
testRecette(); testRecette();
// testLivreRecettes(); // testLivreRecettes();

@ -19,7 +19,7 @@ namespace appli {
break; break;
case Unite::UNITE : os << ""; case Unite::UNITE : os << "";
break; break;
}; }
return os; return os;
} }

@ -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,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());
}
}

@ -0,0 +1,37 @@
#ifndef INGREDIENT_HPP
#define INGREDIENT_HPP
#include "quantite.hpp"
#include <iostream>
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<appli::Ingredient> {
size_t operator()(const appli::Ingredient &i) const {
return hash<string>()(i.getAliment());
}
};
}
#endif //INGREDIENT_HPP

@ -0,0 +1,98 @@
#include "livreRecettes.hpp"
#include "recetteAffichage.hpp"
#include "ingredient.hpp"
#include <map>
#include <algorithm>
using namespace std;
namespace appli {
map<Recette, unordered_set<Ingredient>> LivreRecettes::rechercherRecette(const string &nomRecette) {
map<Recette, unordered_set<Ingredient>> rech;
for(auto it = livre.cbegin(); it != livre.cend(); ++it) {
if(it->first.getNom() == nomRecette) {
rech.insert({it->first, it->second});
}
}
return rech;
}
/*
map<string, Quantite> LivreRecettes::faireListeCourses(list<Recette> l) {
string nomRecette;
int rep;
cout << "Quelle recette voulez vous ? " << endl;
cin >> nomRecette;
map<Recette, unordered_set<Ingredient>>::iterator it = livre.find(nomRecette);
// it = this->rechercherRecette(nomRecette);
for(const Ingredient &ing : it->second) {
cout << "avez vous du, des " << ing << " ? (0 : non/1 : oui)" << endl;
cin >> rep;
if(rep == 0) {
l.push_back(ing);
}
}
}
*/
// comme ça : on fait la liste de tous les ingrédients nécessaire pour faire les recettes choisies
// (sans prendre en compte si on possède déjà des aliments)
map<string, Quantite> LivreRecettes::faireListeCourses(list<Recette> l) {
map<string, Quantite> listeDeCourses;
// pour chaque recette de la liste de recettes que l'on souhaite réaliser :
for(const Recette & r : l){
map<Recette, unordered_set<Ingredient>>::iterator it = livre.find(r);
if(it == livre.end()) cout << "recette inconnue\n";
else{
for(const Ingredient &ing : it->second) {
// si l'ingrédient est déjà dans la liste de courses on met à jour sa quantité
map<string,Quantite>::iterator itIng = listeDeCourses.find(ing.getAliment());
if(itIng !=listeDeCourses.end()){
itIng->second = itIng->second + ing.getQuantite();
}
else{
// sinon on l'ajoute dans la liste de courses
listeDeCourses[ing.getAliment()] = ing.getQuantite();
}
}
}
}
return listeDeCourses;
}
void LivreRecettes::ajouter(const Recette &r, list<Ingredient> l) {
unordered_set<Ingredient> ing;
if(livre.find(r) != livre.end()) {
cout << "recette déjà présente" << endl;
return;
}
for(Ingredient i : l) {
unordered_set<Ingredient>::iterator it2 = ing.find(i);
if(it2 == ing.end()) {
ing.insert(i);
}
else {
Quantite q = i.getQuantite() + it2->getQuantite();
ing.erase(it2);
ing.insert(Ingredient{i.getAliment(), q});
}
}
livre.insert({r, ing});
}
void LivreRecettes::afficherNomRecette() {
afficherNoms(livre);
}
void LivreRecettes::afficher() {
afficherTout(livre);
}
}

@ -0,0 +1,29 @@
#ifndef LIVRERECETTES_HPP
#define LIVRERECETTES_HPP
#include "recette.hpp"
#include "ingredient.hpp"
#include <map>
#include <unordered_set>
#include <list>
namespace appli {
class LivreRecettes {
std::map<Recette, std::unordered_set<Ingredient>> livre;
public:
std::map<Recette, std::unordered_set<Ingredient>> rechercherRecette(const std::string &nomRecette);
std::map<std::string, Quantite> faireListeCourses(std::list<Recette> l);
void ajouter(const Recette &r, std::list<Ingredient> l);
void afficherNomRecette();
void afficher();
};
}
#endif // LIVRERECETTES_HPP

@ -0,0 +1,177 @@
#include <iostream>
#include <map>
#include <unordered_set>
#include <list>
#include "unite.hpp"
#include "quantite.hpp"
#include "ingredient.hpp"
#include "recette.hpp"
#include "recetteAffichage.hpp"
#include "livreRecettes.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<appli::Ingredient> 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<appli::Ingredient> 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<appli::Recette, unordered_set<appli::Ingredient>> 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;
appli::Recette r{"Soupe de poireaux", "Faire cuire les légumes puis mixer."};
list<appli::Ingredient> ing;
ing.push_back(appli::Ingredient{"poireaux", appli::Quantite{2, appli::Unite::UNITE}});
ing.push_back(appli::Ingredient{"pommes de terre", appli::Quantite{300, appli::Unite::G}});
ing.push_back(appli::Ingredient{"eau", appli::Quantite{50, appli::Unite::CL}});
appli::Recette r1{"Soupe de poireaux", "Faire cuire les légumes et lentilles puis mixer."};
list<appli::Ingredient> ing1;
ing1.push_back(appli::Ingredient{"poireaux", appli::Quantite{3, appli::Unite::UNITE}});
ing1.push_back(appli::Ingredient{"lentilles corail", appli::Quantite{200, appli::Unite::G}});
ing1.push_back(appli::Ingredient{"carottes", appli::Quantite{200, appli::Unite::G}});
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é."};
list<appli::Ingredient> ing2;
ing2.push_back(appli::Ingredient{"farine", appli::Quantite{250, appli::Unite::G}});
ing2.push_back(appli::Ingredient{"lait", appli::Quantite{0.5, appli::Unite::L}});
ing2.push_back(appli::Ingredient{"sucre", appli::Quantite{30, appli::Unite::G}});
ing2.push_back(appli::Ingredient{"oeufs", appli::Quantite{4, appli::Unite::UNITE}});
ing2.push_back(appli::Ingredient{"sel", appli::Quantite{3, appli::Unite::G}});
ing2.push_back(appli::Ingredient{"beurre", appli::Quantite{50, appli::Unite::G}});
appli::LivreRecettes livre;
livre.ajouter(r, ing);
livre.ajouter(r1, ing1);
livre.ajouter(r2, ing2);
livre.afficherNomRecette();
cout << "--------------------------------\n";
list<appli::Recette> listeRecettes;
listeRecettes.push_back(r);
listeRecettes.push_back(r1);
map<string,appli::Quantite> listeDeCourses = livre.faireListeCourses(listeRecettes);
cout << "liste de courses nécessaires : \n";
for(auto p : listeDeCourses){
cout <<"\t" << p.first << " : " << p.second << endl;
}
}
int main(){
// testUnite();
// testQuantite();
// testIngredient();
// testRecette();
testLivreRecettes();
return 0;
}

@ -0,0 +1,66 @@
#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;
}
Quantite Quantite::normaliser() const {
switch(unite) {
case Unite::KG :
return *this;
break;
case Unite::G :
return Quantite{nombre / 1000,Unite::KG};
break;
case Unite::L :
return *this;
break;
case Unite::DL :
return Quantite{nombre / 10, Unite::L};
break;
case Unite::CL :
return Quantite{nombre / 100, Unite::L};
break;
case Unite::ML :
return Quantite{nombre / 1000, Unite::L};
break;
case Unite::UNITE :
return Quantite{nombre / 1, Unite::UNITE};
break;
};
return *this;
}
ostream &operator<<(ostream &os, const Quantite &q) {
os << q.getNombre() << q.getUnite();
return os;
}
Quantite operator+(const Quantite &q1, const Quantite &q2) {
if(q1.getUnite() == q2.getUnite()) return Quantite(q1.getNombre() + q2.getNombre(), q1.getUnite());
else {
Quantite q1bis = q1.normaliser();
Quantite q2bis = q2.normaliser();
if(q1bis.getUnite() == q2bis.getUnite())
return Quantite{q1bis.getNombre() + q2bis.getNombre(), q1bis.getUnite()};
else {
cout << "Impossible d'ajouter des unités non compatibles" << endl;
return q1;
}
}
}
}

@ -0,0 +1,31 @@
#ifndef QUANTITE_HPP
#define QUANTITE_HPP
#include <iostream>
#include "unite.hpp"
namespace appli {
class Quantite {
double nombre;
Unite unite;
public:
Quantite(double nombre=1, const Unite &unite=Unite::UNITE);
Quantite normaliser() const;
double getNombre() const;
Unite getUnite() const;
};
std::ostream &operator<<(std::ostream &os, const Quantite &q);
Quantite operator+(const Quantite &q1, const Quantite &q2);
}
#endif // QUANTITE_HPP

@ -0,0 +1,28 @@
#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;
}
bool operator<(const Recette &r1, const Recette &r2) {
if(r1.getNom() < r2.getNom())
return true;
if(r1.getNom() > r2.getNom())
return false;
return r1.getDescription() < r2.getDescription();
}
}

@ -0,0 +1,29 @@
#ifndef RECETTE_HPP
#define RECETTE_HPP
#include <iostream>
#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;
};
bool operator<(const Recette &r1, const Recette &r2);
}
#endif //RECETTE_HPP

@ -0,0 +1,35 @@
#include "recetteAffichage.hpp"
using namespace std;
using namespace appli;
void afficherNomEtIngredients(const Recette &r, const unordered_set<Ingredient> &ingred) {
cout << r.getNom() << endl;
for(auto it = ingred.cbegin(); it != ingred.cend(); ++it) {
cout << "\t" << *it;
}
// for(Ingredient i : ingred) { //! OU CETTE FAÇON
// cout << i << endl;
// }
}
void afficherTout(const Recette &r, const unordered_set<Ingredient> &ingredient) {
cout << r.getNom() << endl;
for(auto it = ingredient.cbegin(); it != ingredient.cend(); ++it) {
cout << "\t" << *it;
}
cout << "description :\n" << r.getDescription() << endl;
}
void afficherTout(const map<Recette, unordered_set<Ingredient>> &recettes) {
for(auto it = recettes.cbegin(); it != recettes.cend(); ++it) {
afficherTout(it->first, it->second);
}
}
void afficherNoms(const map<Recette, unordered_set<Ingredient>> &recettes) {
for(map<Recette, unordered_set<Ingredient>>::const_iterator it = recettes.cbegin(); it != recettes.cend(); ++it){
cout << it->first.getNom() << endl;
}
}

@ -0,0 +1,15 @@
#ifndef RECETTEAFFICHAGE_HPP
#define RECETTEAFFICHAGE_HPP
#include "recette.hpp"
#include "ingredient.hpp"
#include <unordered_set>
#include <map>
void afficherNomEtIngredients(const appli::Recette &r, const std::unordered_set<appli::Ingredient> &ingred);
void afficherTout(const appli::Recette &r, const std::unordered_set<appli::Ingredient> &ingredients);
void afficherTout(const std::map<appli::Recette, std::unordered_set<appli::Ingredient>> &recettes);
void afficherNoms(const std::map<appli::Recette, std::unordered_set<appli::Ingredient>> &recettes);
#endif // RECETTEAFFICHAGE_HPP

@ -0,0 +1,26 @@
#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;
}
}

@ -0,0 +1,14 @@
#ifndef UNITE_HPP
#define UNITE_HPP
#include <iostream>
namespace appli {
enum class Unite{KG, G, L, DL, CL, ML, UNITE};
std::ostream &operator<<(std::ostream &os, const Unite &u);
}
#endif // UNITE_HPP

Binary file not shown.

@ -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

Binary file not shown.

@ -0,0 +1,44 @@
#include "barmen.hpp"
using namespace std;
namespace personnage {
Barmen::Barmen(const string &nom, const string &nomBar)
: Humain(nom, "bière"), nomBar{nomBar}
{}
Barmen::Barmen(const string &nom)
: Humain(nom, "bière"), nomBar{"Coffee Place"}
{}
string Barmen::getNomBar() const {
return this->nomBar;
}
void Barmen::parler(const string &texte) const {
cout << "(" << this->getNom() << ") --- " << texte << " mon gars." << endl;
}
void Barmen::sePresenter() const {
Humain::sePresenter();
this->parler("De plus, je possede un bar qui se nomme le " + this->getNomBar());
}
void Barmen::servirVerre(const Cowboy &cowboy) const {
this->parler("Et voilà pour toi " + cowboy.getNom() +"ton verre favori")
}
void Barmen::servirVerre(const Dame &dame) const {
this->parler("Et voilà pour toi " + dame.getNom() +"ton verre favori")
}
void Barmen::servirVerre(const Sherif &sherif) const {
this->parler("Et voilà pour toi " + sherif.getNom() +"ton verre favori")
}
void Barmen::servirVerre(const Brigand &brigand) const {
this->parler("Et voilà pour toi " + brigand.getNom() +"ton verre favori")
}
}

@ -0,0 +1,41 @@
#ifndef BARMEN_HPP
#define BARMEN_HPP
#include <iostream>
#include "humain.hpp"
namespace personnage {
class Dame;
class Sherif;
class Brigand;
class Cowboy;
class Barmen : public Humain {
std::string nom;
std::string nomBar;
public :
Barmen(const std::string &nom);
Barmen(const std::string &nom, const std::string &nomBar);
std::string getNomBar() const;
void sePresenter() const override;
void parler(const std::string &texte) const override;
void servirVerre(const Cowboy &cowboy) const;
void servirVerre(const Dame &dame) const;
void servirVerre(const Sherif &sherif) const;
void servirVerre(const Brigand &brigand) const;
};
}
#endif // BARMEN_HPP

@ -0,0 +1,61 @@
#include "brigand.hpp"
#include <iostream>
using namespace std;
namespace personnage {
Brigand::Brigand(const string &nom, const string &boisson, const string &comportement, const float &recompense)
: Humain(nom, boisson), comportement{comportement}, recompense{recompense}
{}
Brigand::Brigand(const string &nom)
: Humain(nom, "tord-boyaux"), comportement{"méchant"}, recompense{100}
{}
string Brigand::getNom() const {
return Humain::getNom() + " le " + this->comportement;
}
float Brigand::getMiseAPrix() const {
return recompense;
}
void Brigand::kidnapper(const Dame &dame) {
this->parler("Ah ah !" + dame.getNom() + ", tu est mienne désormais !");
dame.seFaireKidnapper(this);
nbDamesEnlevees += 1;
}
bool Brigand::seFaireEmprisonnerPar(const Sherif &sherif) {
this->parler("Damned, je suis fait ! " + sherif.getNom() + ", tu m'as eu !");
enPrison = true;
}
void Brigand::sePresenter() const {
Humain::sePresenter();
if(this->nbDamesEnlevees > 0) {
if(this->enPrison == false) {
this->parler("Je suis " + this->comportement + ", j'ai capturé " + to_string(this->nbDamesEnlevees) + " femmes au total."); //? Comment arrondir au centieme ?
this->parler("La récompense pour ma capture est de " + to_string(this->recompense) + "$");
}
else {
this->parler("Je suis " + this->comportement + ", j'ai capturé " + to_string(this->nbDamesEnlevees) + " femmes au total, avant d'arriver en prison.");
}
}
else {
if(this->enPrison == false) {
this->parler("Je suis " + this->comportement + ", mais je n'ai toujours pas capturé de femme à ce jour ! "); //? Comment arrondir au centieme ?
this->parler("La récompense pour ma capture est de " + to_string(this->recompense) + "$");
}
else {
this->parler("Je suis " + this->comportement + ", mais je suis allé en prison sans avoir le temps de capturé une seule femme !");
}
}
}
}

@ -0,0 +1,38 @@
#ifndef BRIGAND_HPP
#define BRIGAND_HPP
#include <iostream>
#include "humain.hpp"
namespace personnage {
class Dame;
class Sherif;
class Brigand : public Humain{
std::string comportement;
int nbDamesEnlevees = 0;
float recompense;
bool enPrison = false;
public:
Brigand(const std::string &nom, const std::string &boisson, const std::string &comportement, const float &recompense);
Brigand(const std::string &nom);
std::string getNom() const override;
float getMiseAPrix() const;
void kidnapper(const Dame &dame);
bool seFaireEmprisonnerPar(const Sherif &sherif);
void sePresenter() const override;
};
}
#endif // BRIGAND_HPP

@ -0,0 +1,40 @@
#include "cowboy.hpp"
#include <ostream>
using namespace std;
namespace personnage {
Cowboy::Cowboy(const string &nom, const string &boisson, const string &attitude)
: Humain(nom, boisson), attitude{attitude}
{}
Cowboy::Cowboy(const string &nom)
: Humain(nom, "whisky"), attitude{"vaillant"}
{}
void Cowboy::liberer(const Dame &dame) {
dame.seFaireLiberer(this);
this->parler("Que vous avez une belle robe " + dame.getCouleurRobe() + ". Elle vous vas à ravir ! ;)");
}
void Cowboy::tirerSur(const Brigand &brigand) {
this->narrateur("Le " + this->attitude + " " + this->getNom() + " tire sur " + brigand.getNom() + ". PAN !");
cout << "(Le narrateur) --- Le " << this->attitude << " " << this->getNom() << " tire sur " << brigand.getNom() << ". PAN !" << endl;
this->parler("Prend ça, rascal !");
this->liberer(); //? Comment savoir qui on doit liberer ?
}
void Cowboy::sePresenter() const {
Humain::sePresenter();
if(this->popularite > 0) {
this->parler("Je suis un " + this->attitude + " cowboy. De plus, j'ai une popularité grimpante de " + to_string(this->popularite) + "."); //! Quand c'est des nb, ne pas oublier de les passer en to_string !
}
else {
this->parler("Je suis un " + this->attitude + " cowboy, mais ma popularité est encore nulle. Un jour viendras, je serais le plus grand des cowboy du comté !!");
}
}
}

@ -0,0 +1,31 @@
#ifndef COWBOY_HPP
#define COWBOY_HPP
#include <ostream>
#include "humain.hpp"
namespace personnage {
class Dame;
class Brigand;
class Cowboy : public Humain {
int popularite = 0;
std::string attitude;
public:
Cowboy(const std::string &nom, const std::string &boisson, const std::string &attitude);
Cowboy(const std::string &nom);
void liberer(const Dame &dame);
void tirerSur(const Brigand &brigand);
void sePresenter() const override;
};
}
#endif // COWBOY_HPP

@ -0,0 +1,54 @@
#include "dame.hpp"
#include <iostream>
using namespace std;
namespace personnage {
Dame::Dame(const string &nom, const string &boisson, const string &couleurRobe)
: Humain(nom, boisson), couleurRobe{couleurRobe}
{}
Dame::Dame(const string &nom)
: Humain(nom, "lait"), couleurRobe{"blanche"}
{}
string Dame::getNom() const {
return "Miss " + Humain::getNom();
}
string Dame::getCouleurRobe() const {
return couleurRobe;
}
bool Dame::isCaptive() const {
return captive;
}
void Dame::setCouleurRobe(const string &couleur) {
this->couleurRobe = couleur;
}
void Dame::seFaireKidnapper(const Brigand &brigand) {
cout << "Au secour, je me fait kidnapper par " << brigand.getNom() << ". Aidez moi !!!" << endl;
this->captive = true;
}
bool Dame::seFaireLiberer(const Cowboy &cowboy) {
if(captive == false) {
cout << "Ah, Ah, Ah ! Mais pour qui vous prenez vous ?! Je suis une femme libre enfin !" << endl;
return false;
}
else {
cout << "Merci " << cowboy.getNom() << ", mon valeureux cowboy, je t'en suis reconnaissante !" << endl;
}
}
void Dame::sePresenter() const {
Humain::sePresenter();
this->parler( "Et j'ai une robe de couleur " + this->couleurRobe + " qui est magnifique, en plus de me mettre en valeur !");
}
}

@ -0,0 +1,38 @@
#ifndef DAME_HPP
#define DAME_HPP
#include <iostream>
#include "humain.hpp"
namespace personnage {
class Brigand;
class Cowboy;
class Dame : public Humain {
std::string couleurRobe;
bool captive = false;
public:
Dame(const std::string &nom, const std::string &boisson, const std::string &couleurRobe);
Dame(const std::string &nom);
std::string getNom() const override;
std::string getCouleurRobe() const;
bool isCaptive() const;
void setCouleurRobe(const std::string &couleur);
void seFaireKidnapper(const Brigand &brigand);
bool seFaireLiberer(const Cowboy &cowboy);
void sePresenter() const override;
};
}
#endif // DAME_HPP

@ -0,0 +1,47 @@
#include "humain.hpp"
#include <iostream>
using namespace std;
namespace personnage {
Humain::Humain(const string &nom, const string &boisson)
: nom{nom}, boisson{boisson}
{}
Humain::Humain(const string &nom)
: nom{nom}, boisson{"eau"}
{}
string Humain::getNom() const {
return nom;
}
string Humain::getBoisson() const {
return boisson;
}
void Humain::setBoisson(const string &boisson) {
this->boisson = boisson;
}
void Humain::parler(const string &texte) const {
cout << "(" << this->nom << ") --- " << texte << endl;
}
void Humain::sePresenter() const {
this->parler("Bonjour, je m'appelle " + this->nom + ", ma boisson favorite est le " + this->boisson);
}
void Humain::narrateur(const string &texte) const {
cout << "(narrateur) --- " << texte << endl;
}
void Humain::boire() const {
cout << "Ah ! Un bon verre de " << this->boisson << " ! GLOUPS !" << endl;
}
}

@ -0,0 +1,31 @@
#ifndef HUMAIN_HPP
#define HUMAIN_HPP
#include <iostream>
namespace personnage {
class Humain {
std::string nom;
std::string boisson;
public:
Humain(const std::string &nom, const std::string &boisson);
Humain(const std::string &nom);
virtual std::string getNom() const;
std::string getBoisson() const;
void setBoisson(const std::string &boisson);
virtual void parler(const std::string &texte) const;
virtual void sePresenter() const;
void narrateur(const std::string &texte) const;
void boire() const;
};
}
#endif // HUMAIN_HPP

@ -0,0 +1,140 @@
#include "humain.hpp"
#include "dame.hpp"
#include "brigand.hpp"
#include "cowboy.hpp"
#include "barmen.hpp"
#include "sherif.hpp"
using namespace std;
void testHumain() {
personnage::Humain jacques("Jacques", "biere");
personnage::Humain pierre("Pierre");
pierre.setBoisson("binouse");
jacques.sePresenter();
pierre.sePresenter();
jacques.boire();
pierre.boire();
pierre.parler("C'était bien sympa Jacques, rentrons à la maison maintenant !");
}
void testDame() {
personnage::Dame rose("Rose");
personnage::Dame ginette("Ginette", "ricard", "noir");
rose.sePresenter();
ginette.sePresenter();
rose.setCouleurRobe("verte");
rose.sePresenter();
rose.parler("J'aime les beaux cowboy !");
}
void testBrigand() {
personnage::Brigand robert("Robert");
personnage::Brigand bernard("Bernard", "aveze", "ronchon", 200);
robert.sePresenter();
bernard.sePresenter();
}
void testCowboy() {
personnage::Cowboy danny("Danny", "whisky", "magnifique");
personnage::Cowboy george("George");
danny.sePresenter();
george.sePresenter();
}
void testDBHumain() {
personnage::Dame rose("Rose");
personnage::Brigand marc("marc");
const personnage::Humain &vilainHumain = marc;
const personnage::Humain &gentilleHumain = rose;
cout << "Je suis " << vilainHumain.getNom() << endl;
cout << "Je suis " << gentilleHumain.getNom() << endl;
}
void testBarmen() {
personnage::Barmen jose("Jose");
personnage::Barmen franck("Franck", "The Franchy Bar");
jose.sePresenter();
franck.sePresenter();
jose.parler("J'aime les frites !!!");
}
void testSherif() {
personnage::Brigand robert("Robert");
personnage::Cowboy *clint = new personnage::Sherif{"Clint"};
clint->sePresenter();
clint->parler("Je suis magnifique aujourd'hui. Mais comme toujours c'est vraie !");
clint->coffrerBrigand(robert);
}
void testGeneral() {
personnage::Humain pierre("Pierre");
personnage::Dame rose("Rose");
personnage::Dame ginette("Ginette", "ricard", "noir");
personnage::Brigand robert("Robert");
personnage::Brigand bernard("Bernard", "aveze", "ronchon", 200);
personnage::Cowboy george("George");
personnage::Barmen franck("Franck", "The Franchy Bar");
personnage::Sherif clint("Clint");
personnage::Humain::narrateur("Il était une fois, une jeune et belle dame qui se promenait dans les bois avec une amie.");
rose.sePresenter();
ginette.sePresenter();
rose.parler("Qu'il fait beau aujourd'hui !!");
personnage::Humain::narrateur("Tout allait bien dans le meilleur des mondes, jusqu'à ce que deux brigands apparurent.");
robert.sePresenter();
bernard.sePresenter();
robert.parler("Nous allons vous kidnapper pauvres dames !!");
bernard.kidnapper(rose);
robert.kidnapper(ginette);
personnage::Humain::narrateur("Les pauvres Rose et Ginette se firent kidnapper par ses deux truans. Mais un vieux cowboy n'est pas loin");
george.sePresenter();
george.parler("Que faites vous bande de mal autrus !!!");
george.tirerSur(robert);
george.tirerSur(bernard);
bernard.parler("Tu nous a loupé veillard !!");
george.liberer(ginette);
robert.parler("À bientôt l'ancien !!");
personnage::Humain::narrateur("Et les deux brigands pure s'en aller paisiblement car la vieux cowboy ne tiré plus tout droit.");
personnage::Humain::narrateur("Surtout avec tout l'alcool qu'il s'était enpiffré. Mais il réussi quand même à liberer une des deux filles.");
personnage::Humain::narrateur("Et notre cowboy retourna au bar pour se remettre de ses émotions.");
george.parler("Hey Franck, un verre stp pour moi et cette dame !");
franck.servirVerre(george);
franck.servirVerre(ginette);
franck.parler("Alors ces brigands ??!!");
george.parler("Ils se sont enfuit, j'ai plus la forme comme avant ! Mais j'ai réussi à liberer cette dame.");
personnage::Humain::narrateur("Pendant ce temps là, les brigands s'échappe toujours. Notre cowboy décide donc d'en informer le Shérif.");
george.parler("Sherif !! J'ai deux brigands qui m'on échapés.");
clint.parler("Très bien george. Repose toi ! Je prends le relais");
clint.rechercherBrigand(bernard);
clint.rechercherBrigand(robert);
personnage::Humain::narrateur("Cela s'annonce compliqué pour notre Shérif !!");
clint.parler("Où on-t-il bien pu partir ???");
pierre.sePresenter();
pierre.parler("Sherif ! J'ai vu ces deux gangster avec une très jolie femme avec eux !");
clint.parler("Et où ça ?");
pierre.parler("Ils sont près de la gare !!!");
clint.parler("En avant mon fidèle destrier pilepoil !!");
personnage::Humain::narrateur("Notre Shérif entama donc son périple vers la gare avec son cheval pile-poil.");
personnage::Humain::narrateur("Une fois arrivé, il se cacha et s'approcha discrètement de ses deux brigands avant de les intercepter.");
clint.coffrerBrigand(robert);
clint.tirerSur(bernard);
clint.coffrerBrigand(bernard);
clint.liberer(rose);
rose.parler("Mais que vous êtes merveuilleux mon shérif !!");
clint.parler("Pour vous servir Miss rose.");
personnage::Humain::narrateur("Nos deux personnage partir tout deux heureux.");
}
int main() {
// testHumain();
// testDame();
// testBrigand();
// testCowboy();
// testDBHumain();
// testBarmen();
// testSherif();
// testGeneral();
return 0;
}

@ -0,0 +1,27 @@
#include "sherif.hpp"
using namespace std;
namespace personnage {
Sherif::Sherif(const string &nom)
: Cowboy(nom, "Tekila", "honnête")
{}
string Sherif::getNom() const {
return "Shérif " + Cowboy::getNom();
}
void Sherif::coffrerBrigand(const Brigand &brigand) {
if() { //? Comment verifier s'il est en prison ?
this->parler(brigand.getNom() + " au nom de la loi, je vous arrête !!")
brigand.seFaireEmprisonerPar(this);
}
}
void Sherif::rechercherBrigand(const Brigand &brigand) {
//? Comment l'écrire sans utiliser de find a chaque fois ?
Humain::narrateur("OYEZ OYEZ BRAVE GENS !! " + brigand.getMiseAPrix() + " $ à qui arrêtera " + brigand.getNom() + "mort ou vif !!");
}
}

@ -0,0 +1,30 @@
#ifndef SHERIF_HPP
#define SHERIF_HPP
#include <iostream>
#include "cowboy.hpp"
namespace personnage {
class Brigand;
class Sherif : public Cowboy {
std::string nom;
int nbBrigands = 0;
public :
Sherif(const std::string &nom);
std::string getNom() const override;
void coffrerBrigand(const Brigand &brigand);
void rechercherBrigand(const Brigand &brigand);
};
}
#endif // SHERIF_HPP

Binary file not shown.

@ -0,0 +1,46 @@
Bonjour Antoine,
concernant le TP sur le western :
de manière générale, les const, virtual et override sont bien mis.
dans la classe Humain :
dans la méthode sePresenter : on doit faire appel à getNom() et non à l'attribut nom directement, car sinon on aura pas l'affichage voulu quand on l'appellera à partir d'un objet de classe fille.
il n'y a pas de méthode narrateur. QUand on dit dans le sujet que le narrateur dit c'est que l'on fera simplement un cout pour afficher une ligne de texte sans que ce soit un personnage qui parle.
dans boire, ce n'est pas un cout qu'il faut faire car ici c'est le personnage qui dit/parle donc on fait appel à parler pour dire la phrase voulue.
dans la classe Dame :
dans dame.cpp ne pas oublier d'inclure cowboy.hpp et brigand.hpp car on a besoin de connaître les méthodes de ces classes pour y faire appel
habituellement, quand dans un constructeur on fait appel au constructeur de la classe mère, la notation utilisée de nos jours est celle avec les {} et plus (). On écrira plutôt :
Dame::Dame(const string &nom, const string &boisson, const string &couleurRobe)
: Humain{nom, boisson}, couleurRobe{couleurRobe}
quand elle change de robe elle dit un truc d'après le sujet => donc dans setCouleurRobe ne pas oublier cette ligne
dans seFaireLiberer ne pas oublier de la libérer la dame et de retourner le bouléen qui indique que ça a été fait
dans la classe Brigand :
dans brigand.cpp ne pas oublier d'inclure dame.hpp et sherif.hpp car on a besoin de connaître les méthodes de ces classes pour y faire appel
pour la méthode kidnapper,
la dame prise en paramètre n'est pas const car en fin de compte elle va être modifiée par l'appel à seFaireKidnapper (elle deviendra captive).
et puisque seFaireKidnapper a une ref sur Brigand en paramètre on doit lui passer lors de l'appel le brigand qui est pointé par this et non ce que contient this(l'adresse du brigand)
dans seFaireEmprisonnerPar : ne pas oublier le booléen à retourner qui indique si le brigand a vraiment été fait prisonnier par cette action (peut être qu'il n'a pas été emprisonner ici car il l'était déjà). Et donc ne pas oublier toutes les lignes de codes de cette fonction permettant de gérer cela
dans la classe Cowboy :
dans cowboy.cpp ne pas oublier d'inclure dame.hpp et brigand.hpp car on a besoin de connaître les méthodes de ces classes pour y faire appel
pour la méthode liberer :
normalement un cowboy gagne en popularité à chaque fois qu'il libère une dame (seulement si il l'a bien libérée bien sûr)
et auparavant il la flatte
et seFaireLiberer attend un cowboy en param et pas son adresse alors on lui donne *this et pas this
et comme lors de tout cela la dame va être modifiée : elle va devenir libre par l'appel à seFaireLiberer, donc elle ne doit pas être const dans la déclaration du prototype.
quand le Cowboy tire sur un brigand, il ne fait que parler, personne n'est libéré ou modifié => méthode const et pas d'appel à liberer
dans la classe Barmen :
pas besoin de dire que les classes dame, cowboy, brigand..... existent
la methode servirVerre sert un vert à un humain de manière général. Pour savoir quel verre servir, c'est facile l'appel à la méthode getBoisson le dira.
dans le constructeur de Barmen, si pas de nom de bar fourni, il est dit dans le sujet que le nom du bar est "chez"+nom, et pas autre chose.
quand un barmen parle, il le fait comme un humain avec juste mon gars à la fin du texte
dans la classe Shérif :
dans sherif.cpp ne pas oublier d'inclure brigand.hpp car on a besoin de connaître les méthodes de cette classe pour y faire appel
méthode coffrerBrigand :
le brigand ne peut être const, il sera probablement modifié par l'appel à seFaireEmprisonner
et voir le code, je l'ai modifié
rechercherBrigand, ne fait rien d'autre que de l'affichage, ni le brigand, ni le shérif ne sont modifiés => const et const. et j'ai modifié le code.
dans le main j'ai remplacé tous les appels au narrateur par des cout .

@ -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

Binary file not shown.

@ -0,0 +1,57 @@
#include "barmen.hpp"
using namespace std;
namespace personnage {
Barmen::Barmen(const string &nom, const string &nomBar)
: Humain(nom, "bière"), nomBar{nomBar}
{}
Barmen::Barmen(const string &nom)
// : Humain(nom, "bière"), nomBar{"Coffee Place"}
: Humain(nom, "bière"), nomBar{"Chez "+nom} ///// comme ça d'après le sujet
{}
string Barmen::getNomBar() const {
return this->nomBar;
}
void Barmen::parler(const string &texte) const {
///cout << "(" << this->getNom() << ") --- " << texte << " mon gars." << endl;
//
Humain::parler(texte + " mon gars."); // comme ça
}
void Barmen::sePresenter() const {
Humain::sePresenter();
this->parler("De plus, je possede un bar qui se nomme le " + this->getNomBar());
}
/*
void Barmen::servirVerre(const Cowboy &cowboy) const {
this->parler("Et voilà pour toi " + cowboy.getNom() +"ton verre favori")
}
void Barmen::servirVerre(const Dame &dame) const {
this->parler("Et voilà pour toi " + dame.getNom() +"ton verre favori")
}
void Barmen::servirVerre(const Sherif &sherif) const {
this->parler("Et voilà pour toi " + sherif.getNom() +"ton verre favori")
}
void Barmen::servirVerre(const Brigand &brigand) const {
this->parler("Et voilà pour toi " + brigand.getNom() +"ton verre favori")
}
*/
//////// voici comment il fallait faire :
void Barmen::servirVerre(const Humain & humain) const {
this->parler("Et voilà pour toi " + humain.getNom() +"un verre de "
+ humain.getBoisson());
}
}

@ -0,0 +1,40 @@
#ifndef BARMEN_HPP
#define BARMEN_HPP
#include <iostream>
#include "humain.hpp"
namespace personnage {
// class Dame;
// class Sherif;
// class Brigand;
// class Cowboy;
class Barmen : public Humain {
std::string nom;
std::string nomBar;
public :
Barmen(const std::string &nom);
Barmen(const std::string &nom, const std::string &nomBar);
std::string getNomBar() const;
void sePresenter() const override;
void parler(const std::string &texte) const override;
/*
void servirVerre(const Cowboy &cowboy) const;
void servirVerre(const Dame &dame) const;
void servirVerre(const Sherif &sherif) const;
void servirVerre(const Brigand &brigand) const;
*/
void servirVerre(const Humain & humain) const; /// comme ça
};
}
#endif // BARMEN_HPP

@ -0,0 +1,80 @@
#include "brigand.hpp"
#include "dame.hpp" ///// pour connaître les méthodes de cette classe
#include "sherif.hpp" ///// necessaire pour connaître les méthodes de shérif
#include <iostream>
using namespace std;
namespace personnage {
Brigand::Brigand(const string &nom, const string &boisson, const string &comportement, const float &recompense)
: Humain(nom, boisson), comportement{comportement}, recompense{recompense}
{}
Brigand::Brigand(const string &nom)
: Humain(nom, "tord-boyaux"), comportement{"méchant"}, recompense{100}
{}
string Brigand::getNom() const {
return Humain::getNom() + " le " + this->comportement;
}
float Brigand::getMiseAPrix() const {
return recompense;
}
/////// void Brigand::kidnapper(const Dame &dame) {
void Brigand::kidnapper(Dame &dame) { // comme ça
this->parler("Ah ah !" + dame.getNom() + ", tu est mienne désormais !");
/////// dame.seFaireKidnapper(this);
dame.seFaireKidnapper(*this); // comme ça
nbDamesEnlevees += 1;
}
bool Brigand::seFaireEmprisonnerPar(const Sherif &sherif) {
if(enPrison){ ////// ne pas oublier ce cas !!
parler ("Tu arrives trop tard, je suis déjà en prison !"); //
return false; //////
}
else if(sherif.getNom() == this->getNom()) {
this->parler("Je ne peux pas m'enprisonner moi-même enfin !");
return false;
}
else{
this->parler("Damned, je suis fait ! " + sherif.getNom() + ", tu m'as eu !");
enPrison = true;
return true; //// ne pas oublier cette ligne
}
}
void Brigand::seFaireScalper(const Indien &indien) {
this->parler("Aïe, ma tête... Je meurs !!");
}
void Brigand::sePresenter() const {
Humain::sePresenter();
if(this->nbDamesEnlevees > 0) {
if(this->enPrison == false) {
this->parler("Je suis " + this->comportement + ", j'ai capturé " + to_string(this->nbDamesEnlevees) + " femmes au total."); //? Comment arrondir au centieme ?
this->parler("La récompense pour ma capture est de " + to_string(this->recompense) + "$");
}
else {
this->parler("Je suis " + this->comportement + ", j'ai capturé " + to_string(this->nbDamesEnlevees) + " femmes au total, avant d'arriver en prison.");
}
}
else {
if(this->enPrison == false) {
this->parler("Je suis " + this->comportement + ", mais je n'ai toujours pas capturé de femme à ce jour ! "); //? Comment arrondir au centieme ?
this->parler("La récompense pour ma capture est de " + to_string(this->recompense) + "$");
}
else {
this->parler("Je suis " + this->comportement + ", mais je suis allé en prison sans avoir le temps de capturé une seule femme !");
}
}
}
}

@ -0,0 +1,44 @@
#ifndef BRIGAND_HPP
#define BRIGAND_HPP
#include <iostream>
#include "humain.hpp"
#include "scalpable.hpp"
namespace personnage {
class Dame;
class Sherif;
class Brigand : virtual public Humain, public Scalpable {
protected :
std::string comportement;
int nbDamesEnlevees = 0;
float recompense;
bool enPrison = false;
public:
Brigand(const std::string &nom, const std::string &boisson, const std::string &comportement, const float &recompense);
Brigand(const std::string &nom);
std::string getNom() const override;
float getMiseAPrix() const;
///////// void kidnapper(const Dame &dame);
virtual void kidnapper(Dame &dame); // comme ça
virtual bool seFaireEmprisonnerPar(const Sherif &sherif);
void seFaireScalper(const Indien &indien) override;
void sePresenter() const override;
};
}
#endif // BRIGAND_HPP

@ -0,0 +1,51 @@
#include "cowboy.hpp"
#include "dame.hpp" // pour connaître les méthodes de cette classe
#include "brigand.hpp" // pour connaître les méthodes de cette classe
#include <ostream>
using namespace std;
namespace personnage {
Cowboy::Cowboy(const string &nom, const string &boisson, const string &attitude)
: Humain(nom, boisson), attitude{attitude}
{}
Cowboy::Cowboy(const string &nom)
: Humain(nom, "whisky"), attitude{"vaillant"}
{}
// void Cowboy::liberer(const Dame &dame) {
void Cowboy::liberer(Dame &dame) { // comme ça
///// dame.seFaireLiberer(this);
this->parler("Que vous avez une belle robe " + dame.getCouleurRobe() + ". Elle vous vas à ravir ! ;)");
bool rep = dame.seFaireLiberer(*this); ////// comme ça
if(rep == true) popularite++; //////
}
// void Cowboy::tirerSur(const Brigand &brigand) {
void Cowboy::tirerSur(const Brigand &brigand)const { //// comme ça
//this->narrateur("Le " + this->attitude + " " + this->getNom() + " tire sur " + brigand.getNom() + ". PAN !");
cout << "Le " << this->attitude << " " << this->getNom() << " tire sur " << brigand.getNom() << ". PAN !" << endl;
this->parler("Prend ça, rascal !");
// this->liberer(); //? Comment savoir qui on doit liberer ?
//// R2ponse : on ne libère persone
}
void Cowboy::seFaireScalper(const Indien &indien) {
this->parler("Aïe, ma tête... Je meurs !!");
}
void Cowboy::sePresenter() const {
Humain::sePresenter();
if(this->popularite > 0) {
this->parler("Je suis un " + this->attitude + " cowboy. De plus, j'ai une popularité grimpante de " + to_string(this->popularite) + "."); //! Quand c'est des nb, ne pas oublier de les passer en to_string !
}
else {
this->parler("Je suis un " + this->attitude + " cowboy, mais ma popularité est encore nulle. Un jour viendras, je serais le plus grand des cowboy du comté !!");
}
}
}

@ -0,0 +1,38 @@
#ifndef COWBOY_HPP
#define COWBOY_HPP
#include <ostream>
#include "humain.hpp"
#include "scalpable.hpp"
namespace personnage {
class Dame;
class Brigand;
class Cowboy : virtual public Humain, public Scalpable {
protected :
int popularite = 0;
std::string attitude;
public:
Cowboy(const std::string &nom, const std::string &boisson, const std::string &attitude);
Cowboy(const std::string &nom);
////// void liberer(const Dame &dame);
void liberer(Dame &dame); ///// comme ça
///// void tirerSur(const Brigand &brigand);
void tirerSur(const Brigand &brigand)const;
void seFaireScalper(const Indien &indien) override;
void sePresenter() const override;
};
}
#endif // COWBOY_HPP

@ -0,0 +1,68 @@
#include "dame.hpp"
#include "brigand.hpp" // pour connaitre les méthodes de cette classe
#include "cowboy.hpp" // pour connaitre les méthodes de cette classe
#include "indien.hpp" // pour avoir accer au infos de l'indien
#include <iostream>
using namespace std;
namespace personnage {
Dame::Dame(const string &nom, const string &boisson, const string &couleurRobe)
: Humain(nom, boisson), couleurRobe{couleurRobe}
{}
Dame::Dame(const string &nom)
: Humain(nom, "lait"), couleurRobe{"blanche"}
{}
string Dame::getNom() const {
return "Miss " + Humain::getNom();
}
string Dame::getCouleurRobe() const {
return couleurRobe;
}
bool Dame::isCaptive() const {
return captive;
}
void Dame::setCouleurRobe(const string &couleur) {
this->couleurRobe = couleur;
parler("Regardez ma nouvelle robe "+ couleurRobe); /////// ne pas oublier cette ligne pour respecter le sujet
}
void Dame::seFaireKidnapper(const Brigand &brigand) {
if(brigand.getNom() == this->getNom()) {
this->parler("Mais enfin ! Je ne peux pas me kidnapper toute seule !!!");
return;
}
this->parler("Au secour, je me fait kidnapper par " + brigand.getNom() + ". Aidez moi !!!");
this->captive = true;
}
bool Dame::seFaireLiberer(const Cowboy &cowboy) {
if(captive == false) {
cout << "Ah, Ah, Ah ! Mais pour qui vous prenez vous ?! Je suis une femme libre enfin !" << endl;
return false;
}
else {
cout << "Merci " << cowboy.getNom() << ", mon valeureux cowboy, je t'en suis reconnaissante !" << endl;
captive = false; ////// ne pas oublier cette ligne
return true; ////// ni celle-ci
}
}
void Dame::seFaireScalper(const Indien &indien) {
this->parler("Oh non " + indien.getNom() + ", vous avez tâché ma belle robe " + this->getCouleurRobe() + " ... Je me meurs !!");
}
void Dame::sePresenter() const {
Humain::sePresenter();
this->parler( "Et j'ai une robe de couleur " + this->couleurRobe + " qui est magnifique, en plus de me mettre en valeur !");
}
}

@ -0,0 +1,43 @@
#ifndef DAME_HPP
#define DAME_HPP
#include <iostream>
#include "humain.hpp"
#include "scalpable.hpp"
namespace personnage {
class Brigand;
class Cowboy;
class Dame : virtual public Humain, public Scalpable {
protected :
std::string couleurRobe;
bool captive = false;
public:
Dame(const std::string &nom, const std::string &boisson, const std::string &couleurRobe);
Dame(const std::string &nom);
std::string getNom() const override;
std::string getCouleurRobe() const;
bool isCaptive() const;
void setCouleurRobe(const std::string &couleur);
void seFaireKidnapper(const Brigand &brigand);
bool seFaireLiberer(const Cowboy &cowboy);
void seFaireScalper(const Indien &indien) override;
void sePresenter() const override;
};
}
#endif // DAME_HPP

@ -0,0 +1,45 @@
#include "femmeBrigand.hpp"
#include "sherif.hpp"
#include "dame.hpp"
using namespace std;
namespace personnage {
FemmeBrigand::FemmeBrigand(const string &nom, const string &boisson, const string &couleurRobe, const string &comportement, const float &recompense)
: Humain(nom, boisson), Dame(nom, boisson, couleurRobe), Brigand(nom, boisson, comportement, recompense)
{}
string FemmeBrigand::getNom() const {
return Dame::getNom();
}
void FemmeBrigand::sePresenter() const {
Dame::sePresenter();
this->parler("La récompense pour ma capture est de " + to_string(this->recompense) + " car je suis " + this->comportement + " !!");
}
void FemmeBrigand::kidnapper(Dame &dame) { // comme ça
if(this->getNom() == dame.getNom()) {
this->parler("Mais enfin, je ne peut pas me kidnapper toute seule !!!");
return;
}
this->parler("Hi hi ! Désolé " + dame.getNom() + "... encore UNE de moins qui me feras de l'ombre.");
/////// dame.seFaireKidnapper(this);
dame.seFaireKidnapper(*this); // comme ça
nbDamesEnlevees += 1;
}
bool FemmeBrigand::seFaireEmprisonnerPar(const Sherif &sherif) {
if(enPrison){ ////// ne pas oublier ce cas !!
parler ("Tu arrives trop tard, je suis déjà en prison !"); //
return false; //////
}
else{
this->parler(sherif.getNom() + " ?!! Une lady comme moi ... je vous promet que je suis inocente !");
enPrison = true;
return true; //// ne pas oublier cette ligne
}
}
}

@ -0,0 +1,26 @@
#ifndef FEMMEBRIGAND_HPP
#define FEMMEBRIGAND_HPP
#include "dame.hpp"
#include "brigand.hpp"
namespace personnage {
class Sherif;
class FemmeBrigand : public Dame, public Brigand{
public :
FemmeBrigand(const std::string &nom, const std::string &boisson = "lait", const std::string &couleurRobe = "blanche", const std::string &comportement = "discrète", const float &recompense = 50000);
std::string getNom() const override;
void kidnapper(Dame &dame) override;
bool seFaireEmprisonnerPar(const Sherif &sherif) override;
void sePresenter() const override;
};
}
#endif // FEMMEBRIGAND_HPP

@ -0,0 +1,48 @@
#include "humain.hpp"
#include <iostream>
using namespace std;
namespace personnage {
Humain::Humain(const string &nom, const string &boisson)
: nom{nom}, boisson{boisson}
{}
Humain::Humain(const string &nom)
: nom{nom}, boisson{"eau"}
{}
string Humain::getNom() const {
return nom;
}
string Humain::getBoisson() const {
return boisson;
}
void Humain::setBoisson(const string &boisson) {
this->boisson = boisson;
}
void Humain::parler(const string &texte) const {
cout << "(" << this->nom << ") --- " << texte << endl;
}
void Humain::sePresenter() const {
this->parler("Bonjour, je m'appelle " + this->nom + ", ma boisson favorite est le " + this->boisson);
}
/*
void Humain::narrateur(const string &texte) const {
cout << "(narrateur) --- " << texte << endl;
}
*/
void Humain::boire() const {
// cout << "Ah ! Un bon verre de " << this->boisson << " ! GLOUPS !" << endl;
parler("Ah ! Un bon verre de " + boisson + " ! GLOUPS !" ); // comme ça
}
}

@ -0,0 +1,31 @@
#ifndef HUMAIN_HPP
#define HUMAIN_HPP
#include <iostream>
namespace personnage {
class Humain {
std::string nom;
std::string boisson;
public:
Humain(const std::string &nom, const std::string &boisson);
Humain(const std::string &nom);
virtual std::string getNom() const;
std::string getBoisson() const;
void setBoisson(const std::string &boisson);
virtual void parler(const std::string &texte) const;
virtual void sePresenter() const;
// void narrateur(const std::string &texte) const;
void boire() const;
};
}
#endif // HUMAIN_HPP

@ -0,0 +1,24 @@
#include "indien.hpp"
using namespace std;
namespace personnage {
Indien::Indien(const string &nom, const string &boisson, const int nbPlumes, const string &totem)
:Humain(nom, boisson), nbPlumes{nbPlumes}, totem{totem}
{}
string Indien::getNom() const {
return Humain::getNom();
}
void Indien::parler(const string &texte) const {
Humain::parler(texte + " Ugh !");
}
void Indien::sePresenter() const {
this->parler("Oyh, moi être " + this->getNom() + " et aimer " + this->getBoisson() + ".");
this->parler("Moi vénérer totem " + this->totem + ". Moi guerrier. Moi avoir " + to_string(this->nbPlumes) + " plumes.");
}
}

@ -0,0 +1,27 @@
#ifndef INDIEN_HPP
#define INDIEN_HPP
#include <iostream>
#include "humain.hpp"
namespace personnage {
class Indien : public Humain {
int nbPlumes;
std::string totem;
public :
Indien(const std::string &nom, const std::string &boisson = "jus de racines", const int nbPlumes = 0, const std::string &totem = "Coyote");
std::string getNom() const override;
void parler(const std::string &texte) const override;
void sePresenter() const override;
};
}
#endif // INDIEN_HPP

@ -0,0 +1,178 @@
#include "humain.hpp"
#include "dame.hpp"
#include "brigand.hpp"
#include "cowboy.hpp"
#include "barmen.hpp"
#include "sherif.hpp"
#include "ripou.hpp"
#include "femmeBrigand.hpp"
#include "indien.hpp"
using namespace std;
void testHumain() {
personnage::Humain jacques("Jacques", "biere");
personnage::Humain pierre("Pierre");
pierre.setBoisson("binouse");
jacques.sePresenter();
pierre.sePresenter();
jacques.boire();
pierre.boire();
pierre.parler("C'était bien sympa Jacques, rentrons à la maison maintenant !");
}
void testDame() {
personnage::Dame rose("Rose");
personnage::Dame ginette("Ginette", "ricard", "noir");
rose.sePresenter();
ginette.sePresenter();
rose.setCouleurRobe("verte");
rose.sePresenter();
rose.parler("J'aime les beaux cowboy !");
}
void testBrigand() {
personnage::Brigand robert("Robert");
personnage::Brigand bernard("Bernard", "aveze", "ronchon", 200);
robert.sePresenter();
bernard.sePresenter();
}
void testCowboy() {
personnage::Cowboy danny("Danny", "whisky", "magnifique");
personnage::Cowboy george("George");
danny.sePresenter();
george.sePresenter();
}
void testDBHumain() {
personnage::Dame rose("Rose");
personnage::Brigand marc("marc");
const personnage::Humain &vilainHumain = marc;
const personnage::Humain &gentilleHumain = rose;
cout << "Je suis " << vilainHumain.getNom() << endl;
cout << "Je suis " << gentilleHumain.getNom() << endl;
}
void testBarmen() {
personnage::Barmen jose("Jose");
personnage::Barmen franck("Franck", "The Franchy Bar");
jose.sePresenter();
franck.sePresenter();
jose.parler("J'aime les frites !!!");
}
void testSherif() {
personnage::Brigand robert("Robert");
personnage::Cowboy *clint = new personnage::Sherif{"Clint"};
clint->sePresenter();
clint->parler("Je suis magnifique aujourd'hui. Mais comme toujours c'est vraie !");
// clint->coffrerBrigand(robert); ///// pas possible. Lors de la compilation on aura erreur car la méthode coffrerBrigand n'existe pas pour Cowboy (type du pointeur)
}
void testRipou() {
personnage::Ripou michel("Michel");
personnage::Ripou morice("Morice", "Jet", "Malicieux", "Cruel", 2000);
michel.sePresenter();
morice.sePresenter();
michel.parler("Hello boy !!!");
michel.tirerSur(morice);
michel.coffrerBrigand(michel);
}
void testFemmeBrigand() {
personnage::FemmeBrigand monique{"Monique"};
personnage::FemmeBrigand yvonne{"Yvonne", "Thé", "noir", "grogneuse", 75000};
monique.sePresenter();
yvonne.sePresenter();
monique.parler("Mais que tu est belle, Yvonne !");
monique.kidnapper(yvonne);
monique.kidnapper(monique);
}
void testIndien() {
personnage::Indien ventDoux{"VentDoux"};
personnage::Indien ventFort{"VentFort", "jus de pieds", 4, "Fouine"};
ventDoux.sePresenter();
ventFort.sePresenter();
ventFort.parler("Oeh ventDoux !");
}
void testGeneral1() {
personnage::Humain pierre("Pierre");
personnage::Dame rose("Rose");
personnage::Dame ginette("Ginette", "ricard", "noir");
personnage::Brigand robert("Robert");
personnage::Brigand bernard("Bernard", "aveze", "ronchon", 200);
personnage::Cowboy george("George");
personnage::Barmen franck("Franck", "The Franchy Bar");
personnage::Sherif clint("Clint");
cout << "Il était une fois, une jeune et belle dame qui se promenait dans les bois avec une amie.\n";
rose.sePresenter();
ginette.sePresenter();
rose.parler("Qu'il fait beau aujourd'hui !!");
cout << "Tout allait bien dans le meilleur des mondes, jusqu'à ce que deux brigands apparurent.\n";
robert.sePresenter();
bernard.sePresenter();
robert.parler("Nous allons vous kidnapper pauvres dames !!");
bernard.kidnapper(rose);
robert.kidnapper(ginette);
cout <<"Les pauvres Rose et Ginette se firent kidnapper par ses deux truans. Mais un vieux cowboy n'est pas loin\n";
george.sePresenter();
george.parler("Que faites vous bande de mal autrus !!!");
george.tirerSur(robert);
george.tirerSur(bernard);
bernard.parler("Tu nous a loupé veillard !!");
george.liberer(ginette);
robert.parler("À bientôt l'ancien !!");
cout <<"Et les deux brigands pure s'en aller paisiblement car la vieux cowboy ne tiré plus tout droit.\n";
cout <<"Surtout avec tout l'alcool qu'il s'était enpiffré. Mais il réussi quand même à liberer une des deux filles.\n";
cout <<"Et notre cowboy retourna au bar pour se remettre de ses émotions.\n";
george.parler("Hey Franck, un verre stp pour moi et cette dame !");
franck.servirVerre(george);
franck.servirVerre(ginette);
franck.parler("Alors ces brigands ?!");
george.parler("Ils se sont enfuit, j'ai plus la forme comme avant ! Mais j'ai réussi à liberer cette dame.");
cout <<"Pendant ce temps là, les brigands s'échappe toujours. Notre cowboy décide donc d'en informer le Shérif.\n";
george.parler("Sherif !! J'ai deux brigands qui m'on échapés.");
clint.parler("Très bien george. Repose toi ! Je prends le relais");
clint.rechercherBrigand(bernard);
clint.rechercherBrigand(robert);
cout <<"Cela s'annonce compliqué pour notre Shérif !!\n";
clint.parler("Où on-t-il bien pu partir ???");
pierre.sePresenter();
pierre.parler("Sherif ! J'ai vu ces deux gangster avec une très jolie femme avec eux !");
clint.parler("Et où ça ?");
pierre.parler("Ils sont près de la gare !!!");
clint.parler("En avant mon fidèle destrier pilepoil !!");
cout <<"Notre Shérif entama donc son périple vers la gare avec son cheval pile-poil.\n";
cout <<"Une fois arrivé, il se cacha et s'approcha discrètement de ses deux brigands avant de les intercepter.\n";
clint.coffrerBrigand(robert);
clint.tirerSur(bernard);
clint.coffrerBrigand(bernard);
clint.liberer(rose);
rose.parler("Mais que vous êtes merveuilleux mon shérif !!");
clint.parler("Pour vous servir Miss rose.");
cout <<"Nos deux personnage partir tout deux heureux.\n";
}
void testGeneral2() {
// vector<Humain *>
}
int main() {
// testHumain();
// testDame();
// testBrigand();
// testCowboy();
// testDBHumain();
// testBarmen();
// testSherif();
// testRipou();
// testFemmeBrigand();
// testIndien();
// testGeneral1();
return 0;
}

@ -0,0 +1,21 @@
#include "ripou.hpp"
using namespace std;
namespace personnage {
Ripou::Ripou(const string &nom, const string &boisson, const string &attitude, const string &comportement, const float &recompense)
: Humain(nom, boisson), Sherif(nom, boisson, attitude), Brigand(nom, boisson, comportement, recompense)
{}
string Ripou::getNom() const {
return Sherif::getNom() + "(aka " + Brigand::getNom() + ")";
}
void Ripou::sePresenter() const {
Sherif::sePresenter();
this->parler("Personne ne doit le savoir, mais j'ai kidnappé " + to_string(this->nbDamesEnlevees) + " dames, je suis un vrai " + this->comportement + " !");
this->parler("Celui qui me démasque pourra gagner " + to_string(this->getMiseAPrix()) + "$.");
}
}

@ -0,0 +1,29 @@
#ifndef RIPOU_HPP
#define RIPOU_HPP
#include <iostream>
#include "sherif.hpp"
#include "brigand.hpp"
namespace personnage {
class Ripou : public Sherif, public Brigand {
std::string nom;
public :
Ripou(const std::string &nom, const std::string &boisson = "gin", const std::string &attitude = "silencieux", const std::string &comportement = "sournois", const float &recompense = 1000);
std::string getNom() const override;
void sePresenter() const override;
};
}
#endif // RIPOU_HPP

@ -0,0 +1,20 @@
#ifndef SCALPABLE_HPP
#define SCALPABLE_HPP
#include <iostream>
namespace personnage {
class Indien;
class Scalpable {
public :
virtual void seFaireScalper(const Indien &indien) = 0;
};
}
#endif // SCALPABLE_HPP

@ -0,0 +1,69 @@
#include "sherif.hpp"
#include "brigand.hpp" // pour connaître les méthodes de cette classe
using namespace std;
namespace personnage {
Sherif::Sherif(const string &nom)
: Humain(nom, "Tekila"), Cowboy(nom, "Tekila", "honnête")
{}
Sherif::Sherif(const string &nom, const string &boisson,
const string &attitude)
: Humain(nom, boisson), Cowboy(nom, boisson, attitude)
{}
string Sherif::getNom() const {
return "Shérif " + Cowboy::getNom();
}
/*
void Sherif::coffrerBrigand(const Brigand &brigand) {
if() { //? Comment verifier s'il est en prison ?
this->parler(brigand.getNom() + " au nom de la loi,
je vous arrête !!")
brigand.seFaireEmprisonerPar(this);
}
}
*/
void Sherif::coffrerBrigand(Brigand &brigand) { // comme ça
if(brigand.getNom() == this->getNom()) {
this->parler("Je ne peux pas m'emprisonner moi-même enfin !!");
return;
}
else {
this->parler(brigand.getNom() + " au nom de la loi, je vous arrête !!");
bool rep = brigand.seFaireEmprisonnerPar(*this); // comme ça
if(rep == true) nbBrigands++; ///// comme ça
}
}
/*
void Sherif::rechercherBrigand(const Brigand &brigand) {
//? Comment l'écrire sans utiliser de find a chaque fois ?
Humain::narrateur("OYEZ OYEZ BRAVE GENS !! " +
brigand.getMiseAPrix() + " $ à qui arrêtera " + brigand.getNom()
+ "mort ou vif !!");
}
*/
/// c'est comme ça :
void Sherif::rechercherBrigand(const Brigand &brigand)const {
if(brigand.getNom() == this->getNom()) {
this->parler("Je ne peut pas me revchercher moi-même enfin !!!");
return;
}
parler("OYEZ OYEZ BRAVE GENS !! " + to_string(brigand.getMiseAPrix()) + " $ à qui arrêtera " + brigand.getNom() + "mort ou vif !!");
}
void Sherif::sePresenter() const {
Cowboy::sePresenter();
this->parler("Et j'ai à mon actif " + to_string(this->nbBrigands) + " capturé.");
}
}

@ -0,0 +1,34 @@
#ifndef SHERIF_HPP
#define SHERIF_HPP
#include <iostream>
#include "cowboy.hpp"
namespace personnage {
class Brigand;
class Sherif : public Cowboy {
std::string nom;
int nbBrigands = 0;
public :
Sherif(const std::string &nom);
Sherif(const std::string &nom, const std::string &boisson, const std::string &attitude);
std::string getNom() const override;
/// void coffrerBrigand(const Brigand &brigand);
void coffrerBrigand(Brigand &brigand); ///// comme ça
/// void rechercherBrigand(const Brigand &brigand);
void rechercherBrigand(const Brigand &brigand)const; // comme ça
void sePresenter() const override;
};
}
#endif // SHERIF_HPP

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

@ -0,0 +1 @@
Subproject commit ebe5187bbfe48165a8fab6efcec0f69ba17187ee

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 KiB

Loading…
Cancel
Save