diff --git a/TP8/PAPILLONS/Côté_LES PAPILLONS_24.pdf b/TP8/PAPILLONS/Côté_LES PAPILLONS_24.pdf new file mode 100644 index 0000000..dc2ebe6 Binary files /dev/null and b/TP8/PAPILLONS/Côté_LES PAPILLONS_24.pdf differ diff --git a/TP8/PAPILLONS/PAPILLONS.sln b/TP8/PAPILLONS/PAPILLONS.sln new file mode 100644 index 0000000..b783721 --- /dev/null +++ b/TP8/PAPILLONS/PAPILLONS.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34221.43 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PAPILLONS", "PAPILLONS.vcxproj", "{EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Debug|x64.ActiveCfg = Debug|x64 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Debug|x64.Build.0 = Debug|x64 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Debug|x86.ActiveCfg = Debug|Win32 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Debug|x86.Build.0 = Debug|Win32 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Release|x64.ActiveCfg = Release|x64 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Release|x64.Build.0 = Release|x64 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Release|x86.ActiveCfg = Release|Win32 + {EA3BDFDD-EE87-4A19-BF13-B5B55F4FDE50}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {464C1159-1EE2-4873-AD3C-6E29E4DB6FB0} + EndGlobalSection +EndGlobal diff --git a/TP8/PAPILLONS/PAPILLONS.vcxproj b/TP8/PAPILLONS/PAPILLONS.vcxproj new file mode 100644 index 0000000..d7b3991 --- /dev/null +++ b/TP8/PAPILLONS/PAPILLONS.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {ea3bdfdd-ee87-4a19-bf13-b5b55f4fde50} + PAPILLONS + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/TP8/PAPILLONS/PAPILLONS.vcxproj.filters b/TP8/PAPILLONS/PAPILLONS.vcxproj.filters new file mode 100644 index 0000000..70d1087 --- /dev/null +++ b/TP8/PAPILLONS/PAPILLONS.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers de ressources + + + Fichiers de ressources + + + + + Fichiers sources + + + \ No newline at end of file diff --git a/TP8/PAPILLONS/PAPILLONS.vcxproj.user b/TP8/PAPILLONS/PAPILLONS.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/TP8/PAPILLONS/PAPILLONS.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TP8/PAPILLONS/PapB.txt b/TP8/PAPILLONS/PapB.txt new file mode 100644 index 0000000..2ed41f1 --- /dev/null +++ b/TP8/PAPILLONS/PapB.txt @@ -0,0 +1,4 @@ +3 +P5;B; +Chrys;B; +P6;B; \ No newline at end of file diff --git a/TP8/PAPILLONS/PapJ.txt b/TP8/PAPILLONS/PapJ.txt new file mode 100644 index 0000000..2dcfbd0 --- /dev/null +++ b/TP8/PAPILLONS/PapJ.txt @@ -0,0 +1,5 @@ +4 +P1;J; +Bap;J; +Buti;J; +P4;J; \ No newline at end of file diff --git a/TP8/PAPILLONS/main.cpp b/TP8/PAPILLONS/main.cpp new file mode 100644 index 0000000..22b13fd --- /dev/null +++ b/TP8/PAPILLONS/main.cpp @@ -0,0 +1,228 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class Papillon { + string Nom; + char couleur; +public: + Papillon() {}; + Papillon(char couleur) : couleur(couleur) {}; + + void saisie(ifstream& f); + void saisie(); + void afficher(); + + string nomcouleur() { + return couleur == 'J' ? "Jaune" : "Bleu"; + } + + char getcouleur() { + return couleur; + } + + string getnom() { + return Nom; + } + + bool operator<(Papillon b) { + return Nom > b.Nom; /* tri décroissant */ + } + + bool operator==(Papillon p) { + return Nom == p.Nom && couleur == p.couleur; + } +}; + +template +void lecture(T& cont, const string name) { + ifstream f(name); + + if (!f.is_open()) { + cout << "Erreur lors de l'ouverture du fichier" << endl; + exit(1); + } + + int n; + + f >> n; f.ignore(); + + while (!f.eof()) { + Papillon p; + + p.saisie(f); + f.ignore(); + cont.insert(cont.begin(), p); + } +} + +template +void afficher_el(T& el) { + el.afficher(); +} + +void afficher_el(string el) { + cout << el; +} + +template +void afficher(T cont) { + for (auto el : cont) { + // el.afficher(); + afficher_el(el); + cout << endl; + } + cout << endl; +} + +template +void tri_affichage(T& cont) { + sort(cont.begin(), cont.end()); + + afficher(cont); +} + +// spécialisation de template +template +void tri_affichage(list& cont) { + cont.sort(); afficher(cont); +} + +Papillon saisie_papillon() { + Papillon p; + p.saisie(); + return p; +} + +template +bool effacer_papillon(A& cont, Papillon rec) { + auto it = find(cont.begin(), cont.end(), rec); + + if (it == cont.end()) { + return false; + } + + cont.erase(it); + + return true; +} + +void effacer_papillon(list& cont1, vector& cont2) { + Papillon p = saisie_papillon(); + + if (!effacer_papillon(cont1, p)) { + cout << "Papillon non trouvé dans la liste jaune"< +void remplir_set(T cont, set& s) { + for (auto a : cont) { + s.insert(a.getnom()); + } +} + +int menu() { + int c; + + cout << "1) Lire PapJ.txt(Papillon Jaune) et stocker les données dans List" << endl + << "2) Lire PapB.txt(Papillon Bleu) et stocker les données dans Vector" << endl + << "3) Tri par ordre décroissant selon le nom + Affichage" << endl + << "4) Ajout d’1 Papillon dans List ou Vector selon sa couleur + Affichage" << endl + << "5) Cherche la position d’1 Papillon dans List et Vector et l’efface" << endl + << "6) Construit un SET avec les noms de tous les Papillons de List et Vector + Affichage" << endl; + + cout << "Choix : "; + cin >> c; cin.ignore(); + return c; +} + +int main() { + list j; + vector b; + + set noms; + + Papillon p; + + while (true) { + switch (menu()) { + case 1: + lecture(j, "PapJ.txt"); + afficher(j); + break; + case 2: + lecture(b, "PapB.txt"); + afficher(b); + break; + + case 3: + tri_affichage(j); + tri_affichage(b); + + break; + case 4: + p = saisie_papillon(); + if (p.getcouleur() == 'J') { + j.push_back(p); + afficher(j); + } + else { + b.push_back(p); + afficher(b); + } + + break; + + case 5: + effacer_papillon(j, b); + break; + + case 6: + noms.clear(); + remplir_set(j, noms); + remplir_set(b, noms); + afficher(noms); + + break; + default: + + return 0; + } + } +} + +void Papillon::saisie(ifstream& f) { + getline(f, Nom, ';'); + f >> couleur; f.ignore(); +} + +void Papillon::afficher() { + cout << left << setw(8) << Nom << " " << nomcouleur(); +} + +void Papillon::saisie() { + cout << "Nom : "; + getline(cin, Nom); + + couleur = '\0'; + while (couleur != 'J' && couleur != 'B') { + cout << "Couleur (J/B) : "; + cin >> couleur; cin.ignore(); + couleur = toupper(couleur); + } +} \ No newline at end of file