#include #include #include #include using namespace std; class Personne { string nom; int mat1, mat2; public: void saisie(); void affiche(); string getnom() { return nom; } int getmat1() { return mat1; } int getmat2() { return mat2; } }; class Local { string nom; list mat; public: void saisie(); void affiche(); string getnom() { return nom; } void personnes(list etuds, vector profs); template bool affiche_local(T t, int m); }; template void saisie(C& cont, const string name) { int n; cout << "Nbr " << name << " : "; cin >> n; cin.ignore(); while (n-- > 0) { T obj; obj.saisie(); cont.insert(cont.end(), obj); //cont.push_back(saisie); } } template void affiche_el(T t) { t.affiche(); } void affiche_el(string t) { cout << t; } template void affiche(C cont) { for (auto v : cont) { affiche_el(v); cout << endl; } cout << endl; } template void copie_nom(list& cont, C c) { for (auto a : c) { cont.push_back(a.getnom()); } } void tri_doublon(list& c) { c.sort(); c.unique(); } void local_prof_etud(list locaux, list etuds, vector profs) { for (auto local : locaux) { local.personnes(etuds, profs); } } int menu() { int c; cout << "1) Saisie d’1 Vector de Prof (insertion à la Fin) + Affichage" << endl << "2) Saisie d’1 List de Etud(insertion à la Fin) + Affichage" << endl << "3) Copie des noms des Prof et Etud dans List2" << endl << "4) TRI et Supprime les doublons(noms) de la List2 + Affichage" << endl << "5) Saisie des \"Local\" + Affichage" << endl << "6) Pour tout mat_i appartenant au Local Afficher Prof + Etud" << endl; cout << "Choix : "; cin >> c; cin.ignore(); return c; } int main() { vector profs; list etuds; list list2; list locaux; setlocale(LC_ALL, ""); while (true) { switch (menu()) { case 1: saisie, Personne>(profs, "Prof"); affiche(profs); break; case 2: saisie, Personne>(etuds, "Etud"); affiche(etuds); break; case 3: copie_nom(list2, profs); copie_nom(list2, etuds); affiche(list2); break; case 4: tri_doublon(list2); affiche(list2); break; case 5: saisie, Local>(locaux, "Locaux"); affiche(locaux); break; case 6: local_prof_etud(locaux, etuds, profs); break; default: return 0; } } return 0; } void Personne::saisie() { cout << "Son nom ? : "; getline(cin, nom); cout << "Sa mat1 ? : "; cin >> mat1; cin.ignore(); cout << "Sa mat2 ? : "; cin >> mat2; cin.ignore(); } void Personne::affiche() { cout << "Nom : " << nom << endl; cout << "Mat1 : " << mat1 << endl; cout << "Mat2 : " << mat2 << endl; } void Local::saisie() { cout << "Son nom ? : "; getline(cin, nom); cout << "nbr mat ? :"; int m; cin >> m; for(int i = 0; i< m;i++) { int a; cout << "Mat"<> a; cin.ignore(); mat.insert(mat.begin(), a); } } void Local::affiche() { cout << "Nom : " << nom << endl; int i = 0; for (auto m : mat) { cout << "Mat"< etuds, vector profs) { cout << nom << " " << endl; for (auto m : mat) { cout << " " << "Mat" << m << " : "; bool f; f = affiche_local(etuds, m); f |= affiche_local(profs, m); if (!f) { cout << "NULL"; } cout << endl; } } template bool Local::affiche_local(T t, int m) { bool f = false; for (auto e : t) { if (e.getmat1() == m || e.getmat2() == m) { cout << e.getnom() << ", "; f = true; } } return f; }