From add166edcd3e5337c86a9da7f2e1a80f60414168 Mon Sep 17 00:00:00 2001 From: theking90000 Date: Tue, 26 Nov 2024 20:38:25 +0100 Subject: [PATCH] TP5 --- TP5/ETUDB.txt | 9 ++ TP5/PROF.txt | 6 ++ TP5/PROF.xsd | 9 ++ TP5/TP5.sln | 31 ++++++ TP5/TP5.vcxproj | 139 ++++++++++++++++++++++++++ TP5/TP5.vcxproj.filters | 30 ++++++ TP5/TP5.vcxproj.user | 4 + TP5/main.cpp | 215 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 443 insertions(+) create mode 100644 TP5/ETUDB.txt create mode 100644 TP5/PROF.txt create mode 100644 TP5/PROF.xsd create mode 100644 TP5/TP5.sln create mode 100644 TP5/TP5.vcxproj create mode 100644 TP5/TP5.vcxproj.filters create mode 100644 TP5/TP5.vcxproj.user create mode 100644 TP5/main.cpp diff --git a/TP5/ETUDB.txt b/TP5/ETUDB.txt new file mode 100644 index 0000000..5f4fe2c --- /dev/null +++ b/TP5/ETUDB.txt @@ -0,0 +1,9 @@ + +7 +Etud1 +Etud2 +Etud3 +Etud4 +Etud5 +Etud6 +Etud7 \ No newline at end of file diff --git a/TP5/PROF.txt b/TP5/PROF.txt new file mode 100644 index 0000000..f8229bf --- /dev/null +++ b/TP5/PROF.txt @@ -0,0 +1,6 @@ +5 +Prof1;Informatique; +Prof2;Informatique; +Prof3;Mathematique; +Prof4;Physique; +Prof5;Chimie; \ No newline at end of file diff --git a/TP5/PROF.xsd b/TP5/PROF.xsd new file mode 100644 index 0000000..39252b3 --- /dev/null +++ b/TP5/PROF.xsd @@ -0,0 +1,9 @@ + + + diff --git a/TP5/TP5.sln b/TP5/TP5.sln new file mode 100644 index 0000000..4091d91 --- /dev/null +++ b/TP5/TP5.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}") = "TP5", "TP5.vcxproj", "{5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}" +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 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Debug|x64.ActiveCfg = Debug|x64 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Debug|x64.Build.0 = Debug|x64 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Debug|x86.ActiveCfg = Debug|Win32 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Debug|x86.Build.0 = Debug|Win32 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Release|x64.ActiveCfg = Release|x64 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Release|x64.Build.0 = Release|x64 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Release|x86.ActiveCfg = Release|Win32 + {5ED86EF3-56FC-47BB-8158-B3DA0C5C17C9}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {751FCA9B-3D1B-4953-B0CB-D7CA089CBB38} + EndGlobalSection +EndGlobal diff --git a/TP5/TP5.vcxproj b/TP5/TP5.vcxproj new file mode 100644 index 0000000..09b2ae8 --- /dev/null +++ b/TP5/TP5.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {5ed86ef3-56fc-47bb-8158-b3da0c5c17c9} + TP5 + 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/TP5/TP5.vcxproj.filters b/TP5/TP5.vcxproj.filters new file mode 100644 index 0000000..c86a53a --- /dev/null +++ b/TP5/TP5.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/TP5/TP5.vcxproj.user b/TP5/TP5.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/TP5/TP5.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TP5/main.cpp b/TP5/main.cpp new file mode 100644 index 0000000..af38948 --- /dev/null +++ b/TP5/main.cpp @@ -0,0 +1,215 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class ETUD { + int Id; + string nom; + +public: + ETUD() { static int i = 0; Id = ++i; } + ~ETUD() { cout << "Disparition de l'étudiant ID=" << Id << endl; } + + void saisie(string ligne) { nom = ligne.substr(0, ligne.find(';')); }; + void affiche() { cout << setw(4) << Id << left << setw(2) << nom; } + void saisie() { cout << "Nom :"; cin.ignore(); getline(cin, nom); } + + string getNom() { return nom; } +}; + +class PROF { + int Id; + string nom, service; + +public: + PROF() { static int i = 0; Id = ++i; } + ~PROF() { cout << "Disparition du prof ID=" << Id << endl; } + + void saisie(string ligne) { int i = ligne.find(';'); nom = ligne.substr(0, i); service = ligne.substr(i + 1, ligne.find(';', i+1) - i - 1); }; + void affiche() { cout << left << setw(4) << Id << left << setw(8) << nom << " " << left << setw(8) << service; } + void saisie() { cout << "Nom :"; cin.ignore(); getline(cin, nom); cout << "Service :"; cin.ignore(); getline(cin, service); } + + string getNom() { return nom; } +}; + +int menu() { + int choix; + cout << "Entrez votre choix : \n" + << " 1. Lire fichier PROF et stocker les données dans un Vector + Affichage\n" + << " 2. Lire fichier ETUDB et stocker les données dans une List + Affichage\n" + << " 3. Ajouter un PROF au début du Vector + Afficher\n" + << " 4. Ajouter un ETUD au début de List + Afficher\n" + << " 5. Supprimer le PROF et ETUD au début de Vector et List + Affichage\n" + << " 6. Créer une List2 contenant uniquement les noms des ETUD et PROF \n" + << " 7. Quitter " << endl; + cin >> choix; + return choix; +} + +// template +template +void lire(C& c, string nomfichier) { + ifstream fichier(nomfichier); + int N; + string ligne; + + if (!fichier) { + cout << "Une erreur est survenue lors de la lecture du fichier" << endl; + return; + } + + fichier >> N; + fichier.ignore(); + while (N-- > 0) { + getline(fichier, ligne); + // O o; + // o.saisie(ligne); + // c.insert(c.end(), o); + + // https://cplusplus.com/reference/vector/vector/emplace/ + // https://cplusplus.com/reference/list/list/emplace/ + c.emplace(c.end())->saisie(ligne); + } +} + +template +void affiche(C& conteneur) { + cout << "Ce conteneur contient" << endl; + for (auto& o : conteneur) { + cout << endl; + o.affiche(); + } + cout << endl; +} + +template +void lire_puis_affiche(C& conteneur, string nomfichier) { + lire(conteneur, nomfichier); + affiche(conteneur); +} + +// template +template +void ajoutdebut_affiche(C& conteneur) { + conteneur.emplace(conteneur.begin())->saisie(); + affiche(conteneur); +} + +template +void supprimedebut_affiche(C& conteneur) { + conteneur.erase(conteneur.begin()); + affiche(conteneur); +} + +template +void remplirliste_nom(C& c, list& l) { + for (auto& o : c) { + l.push_back(o.getNom()); + } +} + +void affiche(list& l) { + cout << "Voici la liste des noms des etudiants et des PROFs" << endl; + for (auto& o : l) { + cout << endl << o; + } + cout << endl; +} + +int main() { + setlocale(LC_ALL, ""); + + list etuds; + vector profs; + + list list2; + + profs.reserve(10); + + int choix; + + while ((choix = menu()) != 7) { + switch (choix) { + case 1: + //lire, PROF>(profs, "PROF.txt"); + lire_puis_affiche(profs, "PROF.txt"); + break; + + case 2: + //lire, ETUD>(etuds, "ETUDB.txt"); + lire_puis_affiche(etuds, "ETUDB.txt"); + break; + + case 3: + ajoutdebut_affiche(profs); + break; + + case 4: + ajoutdebut_affiche(etuds); + break; + + case 5: + supprimedebut_affiche(etuds); + supprimedebut_affiche(profs); + break; + + case 6: + remplirliste_nom(etuds, list2); + remplirliste_nom(profs, list2); + affiche(list2); + break; + } + } + + + return 0; +} + +/* +template +void fonction_template(Conteneur& conteneur) { + T monobjet; + + conteneur.push_back(monobjet); +} + +void exemple_template() { + list profs; + profs.push_back + + int varI = 0; + + fonction_template, PROF>(profs); + + fonction_template, string>(profs); + + fonction_template(varI); +} +*/ +/* +// expand la fonction template comme ceci +void fonction_template(list& conteneur) { + PROF monobjet; + + conteneur.push_back(monobjet); +} + +// expand la fonction template comme ceci (avec le 2e) +void fonction_template(list& conteneur) { + string monobjet; + + conteneur.push_back(monobjet); +} + +// expand la fonction template comme ceci (avec le 3e) +void fonction_template(int& conteneur) { + string monobjet; + + conteneur.push_back(monobjet); +}*/ \ No newline at end of file