diff --git a/TP8/EtudProf/Côté_Etud_Prof_VF.pdf b/TP8/EtudProf/Côté_Etud_Prof_VF.pdf new file mode 100644 index 0000000..f2d8844 Binary files /dev/null and b/TP8/EtudProf/Côté_Etud_Prof_VF.pdf differ diff --git a/TP8/EtudProf/EtudProf.sln b/TP8/EtudProf/EtudProf.sln new file mode 100644 index 0000000..38d26a3 --- /dev/null +++ b/TP8/EtudProf/EtudProf.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}") = "EtudProf", "EtudProf.vcxproj", "{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}" +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 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x64.ActiveCfg = Debug|x64 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x64.Build.0 = Debug|x64 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x86.ActiveCfg = Debug|Win32 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x86.Build.0 = Debug|Win32 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x64.ActiveCfg = Release|x64 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x64.Build.0 = Release|x64 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x86.ActiveCfg = Release|Win32 + {D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2112B69A-D512-4F99-A3CE-CBDB944F07B8} + EndGlobalSection +EndGlobal diff --git a/TP8/EtudProf/EtudProf.vcxproj b/TP8/EtudProf/EtudProf.vcxproj new file mode 100644 index 0000000..09e8315 --- /dev/null +++ b/TP8/EtudProf/EtudProf.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {d6dec2bc-4a3c-4aa0-bd88-5fe3113cf810} + EtudProf + 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/EtudProf/EtudProf.vcxproj.filters b/TP8/EtudProf/EtudProf.vcxproj.filters new file mode 100644 index 0000000..ba6e7bf --- /dev/null +++ b/TP8/EtudProf/EtudProf.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 sources + + + + + Fichiers de ressources + + + Fichiers de ressources + + + \ No newline at end of file diff --git a/TP8/EtudProf/EtudProf.vcxproj.user b/TP8/EtudProf/EtudProf.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/TP8/EtudProf/EtudProf.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TP8/EtudProf/Etud_M.txt b/TP8/EtudProf/Etud_M.txt new file mode 100644 index 0000000..c9547c6 --- /dev/null +++ b/TP8/EtudProf/Etud_M.txt @@ -0,0 +1,4 @@ +15103A;Aladdin;3;5;15;13; +15095X;Jasmine;5;15;11;19;7;18; +14109C;Asterix;4;12;10;14;8; +19150B;Obelix;2;0;20; \ No newline at end of file diff --git a/TP8/EtudProf/Prof_M.txt b/TP8/EtudProf/Prof_M.txt new file mode 100644 index 0000000..d4b4a7e --- /dev/null +++ b/TP8/EtudProf/Prof_M.txt @@ -0,0 +1,5 @@ +Tournesol;3;Math;Philo;Chimie; +Einstein;2;Physique;Méca; +BruceLee;4;kungfu;Karaté;TaiChiChuan;Gung-Li; +StephenWilliamHawking;2;Cosmologie;Physique; +IsaacNewton;4;Math;Physique;Philo;Astronomie; \ No newline at end of file diff --git a/TP8/EtudProf/main.cpp b/TP8/EtudProf/main.cpp new file mode 100644 index 0000000..1617ebf --- /dev/null +++ b/TP8/EtudProf/main.cpp @@ -0,0 +1,220 @@ +#include +#include +#include +#include +#include +#include + + +using namespace std; + +const int ENTREE_MAX = 10; + +template +class Personne { + string nom; + int nbr_entrees; + T entrees[ENTREE_MAX]; +public: + void Lire(ifstream& f); + void afficher(); + T lire_entree(ifstream& f); + + string get_key() { return nom; } + string get_nom() { return nom; } +}; + +class Etud : public Personne { + string Id; +public: + void Lire(ifstream& f); + void afficher(); + + string get_key() { return Id; } +}; + +class Prof : public Personne {}; + +template +void lecture(M& mp, const string fname) { + ifstream f(fname); + + if (!f.is_open()) { + cout << "Erreur lors de la lecture du fichier"< +void afficher(const C& mp) { + for (auto pair : mp) { + pair.second.afficher(); + cout << endl; + } + cout << endl; +} + +template +void afficher(const set& s) { + for (auto e : s) { + cout << e; + cout << endl; + } + cout << endl; +} + +int menu() { + int c; + cout << "1 : Lire Etud_M.txt et stocker les données dans une Map1 d’Etudiants + affichage" << endl + << "2 : Lire Prof_M.txt et stocker les données dans une Map2 de PROFs + affichage" << endl + << "3 : Chercher selon le nom dans Map1 et dans Map2 si élément existe et l’Effacer + affichage" << endl + << "4 : Mettre les noms des étudiants et des PROFs dans un CnTri + affichage" << endl + << "5 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl; + cout << "Choix : "; + cin >> c; cin.ignore(); + return c; +} + +bool is_equal_ignorecase(string s1, string s2) { + if (s1.size() != s2.size()) return false; + for (int i = 0; i < s1.size(); i++) { + if (tolower(s1[i]) != tolower(s2[i])) + return false; + } + return true; +} + +template +auto find(T& t, const string nom) { + auto it = t.begin(); + for (; it != t.end(); it++) { + if (is_equal_ignorecase(it->second.get_nom(), nom)) + break; + } + return it; +} + + +void effacer_nom(map& etuds, map& profs) { + string nom; + + cout << "Nom : "; + getline(cin, nom); + + auto itE = find(etuds, nom); + + auto itP = find(profs, nom); + + if (itE == etuds.end() && itP == profs.end()) { + cout << "Ce nom n'existe pas" << endl; + return; + } + + if (itE != etuds.end()) { + etuds.erase(itE); + } + + if (itP != profs.end()) { + profs.erase(itP); + } + + afficher(etuds); + afficher(profs); +} + +template +void ajout_nom(set& noms, T& map) { + for (auto& p : map) { + noms.insert(p.second.get_nom()); + } +} + + +int main() { + map etuds; + map profs; + + set noms; + + while (true) { + switch (menu()) { + case 1: + lecture, Etud>(etuds, "Etud_M.txt"); + afficher(etuds); + + break; + + case 2: + lecture, Prof>(profs, "Prof_M.txt"); + afficher(profs); + + break; + + case 3: + effacer_nom(etuds, profs); + + break; + + case 4: + noms.clear(); + ajout_nom(noms, etuds); + ajout_nom(noms, profs); + + afficher(noms); + + break; + default: + return 0; + } + } +} + +template +void Personne::Lire(ifstream& f) { + getline(f, nom, ';'); + f >> nbr_entrees; f.ignore(); + for (int i = 0; i < nbr_entrees; i++) { + entrees[i] = lire_entree(f); + } +} + +string Personne::lire_entree(ifstream& f) { + string entree; + getline(f, entree, ';'); + return entree; +} + +float Personne::lire_entree(ifstream& f) { + float entree; + f >> entree; f.ignore(); + return entree; +} + + +void Etud::Lire(ifstream& f) { + getline(f, Id, ';'); + Personne::Lire(f); +} + +template +void Personne::afficher() { + cout << left << setw(22) << nom << " " << nbr_entrees << " "; + for (int i = 0; i < nbr_entrees; i++) { + cout << left << setw(8) << entrees[i] << " "; + } +} + +void Etud::afficher() { + cout << setw(6) << Id << " "; + Personne::afficher(); +} \ No newline at end of file