#include #include using namespace std; const int Nmax = 10; struct PROF { int Id; string nom; string service; PROF(); void saisie(); void afficher(); static int counter; bool operator==(PROF P) { return P.nom == nom && P.service == service; } }; int PROF::counter = 0; template void DeplacerDroite(T tab[], int N, int i = 0) { PROF tmp = tab[Nmax - 1]; while (N-- > i) { tab[N + 1 + i] = tab[N + i]; } tab[0] = tmp; } int ChercherProf(PROF profs[], const int N, PROF p); int menu() { int choix; cout << " 1. Saisir + Afficher\n" << " 2. Ajouter un PROF au début + Afficher\n" << " 3. Chercher si un prof existe ou pas dans le tableau\n" << " 4. Quitter " << "\n" << " 5. Afficher la liste de profs\n" << "Entrez votre choix : "; cin >> choix; return choix; } void main() { PROF profs[Nmax]; PROF p; int choix = 0, N = 0; setlocale(LC_ALL, ""); while (choix != 4) { switch (choix = menu()) { case 1: if (N >= 10) { break; } profs[N].saisie(); profs[N++].afficher(); break; case 2: if (N >= 10) { break; } DeplacerDroite(profs, Nmax); N++; profs[0].saisie(); profs[0].afficher(); break; case 3: cout << "Entrez le nom du prof à rechercher : \n"; cin.ignore(); getline(cin, p.nom); cout << "Entrez le nom du service du prof à rechercher : \n"; // cin.ignore(); getline(cin, p.service); // cout << "Service:" << p.service << "\n"; if (ChercherProf(profs, N, p) != -1) { cout << "Le " << p.nom << " est dans la liste" << "\n"; } else { cout << "Le " << p.nom << " n'est pas dans la liste" << "\n"; } break; case 4: return; case 5: for (int i = 0; i < N; i++) { cout << "-- Prof " << i << " --" << endl; profs[i].afficher(); } } } } PROF::PROF() { Id = ++counter; } void PROF::saisie() { cout << "Nom : "; cin.ignore(); // cin >> prof.nom; getline(cin, nom); cout << "Service : "; // cin.ignore(); getline(cin, service); // cin >> prof.service; } void PROF::afficher() { cout << "Prof " << Id << "\n" << "Nom : " << nom << "\n" << "Service : " << service << "\n"; } int ChercherProf(PROF profs[], int N, PROF P) { for (int i = 0; i < N; i++) { if (profs[i] == P) { return i; } } return -1; }