diff --git a/TP8/ParcoursVita/Parcours Vita_VF.pdf b/TP8/ParcoursVita/Parcours Vita_VF.pdf new file mode 100644 index 0000000..b0a99ee Binary files /dev/null and b/TP8/ParcoursVita/Parcours Vita_VF.pdf differ diff --git a/TP8/ParcoursVita/ParcoursVita.sln b/TP8/ParcoursVita/ParcoursVita.sln new file mode 100644 index 0000000..e0fcb64 --- /dev/null +++ b/TP8/ParcoursVita/ParcoursVita.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}") = "ParcoursVita", "ParcoursVita.vcxproj", "{E000E911-87DE-426A-A425-A796F5A8CC97}" +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 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x64.ActiveCfg = Debug|x64 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x64.Build.0 = Debug|x64 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x86.ActiveCfg = Debug|Win32 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x86.Build.0 = Debug|Win32 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x64.ActiveCfg = Release|x64 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x64.Build.0 = Release|x64 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x86.ActiveCfg = Release|Win32 + {E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6848ED2D-79A2-415E-B230-BEFE036DDB2C} + EndGlobalSection +EndGlobal diff --git a/TP8/ParcoursVita/ParcoursVita.vcxproj b/TP8/ParcoursVita/ParcoursVita.vcxproj new file mode 100644 index 0000000..ef2e8ef --- /dev/null +++ b/TP8/ParcoursVita/ParcoursVita.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {e000e911-87de-426a-a425-a796f5a8cc97} + ParcoursVita + 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/ParcoursVita/ParcoursVita.vcxproj.filters b/TP8/ParcoursVita/ParcoursVita.vcxproj.filters new file mode 100644 index 0000000..5d997ac --- /dev/null +++ b/TP8/ParcoursVita/ParcoursVita.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {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 sources + + + \ No newline at end of file diff --git a/TP8/ParcoursVita/ParcoursVita.vcxproj.user b/TP8/ParcoursVita/ParcoursVita.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/TP8/ParcoursVita/ParcoursVita.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TP8/ParcoursVita/main.cpp b/TP8/ParcoursVita/main.cpp new file mode 100644 index 0000000..7fc2f3c --- /dev/null +++ b/TP8/ParcoursVita/main.cpp @@ -0,0 +1,197 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + + +class Participant { + string Nom; + int age; +public: + void Affichage(); + void Saisie(); + + int getAge() { return age; } + string getNom() { return Nom; } + + // Tri par l'age + bool operator<(Participant p) { + return Nom < p.Nom; + } +}; + +template +void saisie(C& c) { + int n; + + cout << "Nombre de participants à saisir : "; + cin >> n; cin.ignore(); + + while ((n--) > 0) { + T participant; + participant.Saisie(); + c.insert(c.begin(), participant); + } +} + +template +void affichage(C c) { + for (auto p : c) { + p.Affichage(); cout << endl; + } + cout << endl; +} + +void affichage(set c) { + for (auto a : c) { + cout << a << endl; + } + cout << endl; +} + +template +void affichage(C c, const string name) { + cout << "Affichage de " << name << endl; + + affichage(c); +} + + + +// template +bool tri_age(Participant a, Participant b) { + return a.getAge() < b.getAge(); +} + +// template +bool tri_age_dec(Participant a, Participant b) { + return !tri_age(a, b); +} + +template +void erase_max(A& a, B& b, F cmp, string txt) { + auto ita = max_element(a.begin(), a.end(), cmp); + auto itb = max_element(b.begin(), b.end(), cmp); + + cout << txt; + if (ita != a.end() + && (itb == b.end() || cmp(*itb, *ita))) { + ita->Affichage(); + a.erase(ita); + } + else if (itb != b.end() + && (ita == a.end() || cmp(*ita, *itb))) { + itb->Affichage(); + b.erase(itb); + } + else { + cout << "NULL"; + } + cout << endl; +} + +template +void erase_jeune_age(A& a, B& b) { + erase_max(a, b, tri_age, "Le plus vieux = "); + erase_max(a, b, tri_age_dec, "Le plus jeune = "); +} + +template +void add_allnom(A source, B& b) { + for(auto a : source) { + b.insert(a.getNom()); + } +} + + +int menu() { + int c; + + cout << "1. Saisie liste L1 + affichage" << endl + << "2. Saisie vector V1 + affichage" << endl + << "3. Efface le + jeune et le + agé (L1/V1)" << endl + << "4. Tri croissant selon age (L1/V1) + affichage" << endl + << "5. Conteneur de noms de L1/V1 trié+sans doublons" << endl + << "6. Afficher L1 et V1" << endl; + + cout << "Choix : " << endl; + + cin >> c; cin.ignore(); + return c; +} + +int main() { + list L1; + vector V1; + + set noms; + + setlocale(LC_ALL, ""); + + while (true) { + switch (menu()) { + case 1: + saisie, Participant>(L1); + affichage(L1, "L1"); + + break; + case 2: + saisie, Participant>(V1); + affichage(V1, "V1"); + + break; + case 3: + erase_jeune_age(L1, V1); + affichage(L1, "L1"); + affichage(V1, "V1"); + + break; + + case 4: + L1.sort(tri_age); + sort(V1.begin(), V1.end(), tri_age); + affichage(L1, "L1"); + affichage(V1, "V1"); + + break; + case 5: + add_allnom(L1, noms); + add_allnom(V1, noms); + affichage(noms, "Affichage du conteneur :"); + + break; + case 6: + affichage(L1, "L1"); + affichage(V1, "V1"); + + break; + default: + return 0; + } + } +} + +template +void affiche(T t, int w) { + cout << left << setw(w) << t << " "; +} + +void Participant::Affichage() { + affiche(Nom, 10); + affiche(age, 4); +} + +void Participant::Saisie() { + // Saisie de du nom : via getline(); + cout << "Son nom ? : "; + getline(cin, Nom); + + // Saisie de l'age + cout << "Son age ? : "; + cin >> age; cin.ignore(); +} \ No newline at end of file