123 lines
2.4 KiB
C++
123 lines
2.4 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
const int Nmax = 10;
|
|
|
|
struct PROF
|
|
{
|
|
int Id;
|
|
string nom;
|
|
string service;
|
|
};
|
|
|
|
void SaisieProf(PROF &prof);
|
|
void AfficherProf(const PROF prof);
|
|
|
|
template <typename T>
|
|
void DeplacerDroite(T tab[], int N, int i = 0)
|
|
{
|
|
while (N-- > i)
|
|
{
|
|
tab[N + 1 + i] = tab[N + i];
|
|
}
|
|
}
|
|
|
|
int ChercherProf(const PROF profs[], const int N, string name, string service);
|
|
|
|
int menu()
|
|
{
|
|
int choix;
|
|
|
|
cout
|
|
<< " 1. Saisir + Afficher\n"
|
|
<< " 2. Ajouter un PROF au début + Afficher\n"
|
|
<< " 3. Chercher si PROF1 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];
|
|
int choix = 0, N = 0;
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
while (choix != 4)
|
|
{
|
|
switch (choix = menu())
|
|
{
|
|
case 1:
|
|
SaisieProf(profs[N]);
|
|
AfficherProf(profs[N++]);
|
|
break;
|
|
case 2:
|
|
DeplacerDroite(profs, N);
|
|
N++;
|
|
SaisieProf(profs[0]);
|
|
AfficherProf(profs[0]);
|
|
break;
|
|
case 3:
|
|
if (ChercherProf(profs, N, "PROF1", "SERVICE1") != -1)
|
|
{
|
|
cout << "Le PROF1 est dans la liste" << "\n";
|
|
}
|
|
else
|
|
{
|
|
cout << "Le PROF1 n'est pas dans la liste" << "\n";
|
|
}
|
|
break;
|
|
case 4:
|
|
return;
|
|
case 5:
|
|
for (int i = 0; i < N; i++)
|
|
{
|
|
cout << "-- Prof " << i << " --" << endl;
|
|
AfficherProf(profs[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void SaisieProf(PROF &prof)
|
|
{
|
|
cout << "Identifiant: ";
|
|
cin >> prof.Id;
|
|
cin.ignore();
|
|
cout << "Nom : \n";
|
|
// cin.ignore();
|
|
|
|
// cin >> prof.nom;
|
|
getline(cin, prof.nom);
|
|
cout << "Service : \n";
|
|
// cin.ignore();
|
|
getline(cin, prof.service);
|
|
// cin >> prof.service;
|
|
}
|
|
|
|
void AfficherProf(const PROF prof)
|
|
{
|
|
cout << "Prof " << prof.Id << "\n"
|
|
<< "Nom : " << prof.nom << "\n"
|
|
<< "Service : " << prof.service << "\n";
|
|
}
|
|
|
|
int ChercherProf(const PROF profs[], int N, string name, string service)
|
|
{
|
|
for (int i = 0; i < N; i++)
|
|
{
|
|
if (profs[i].nom == name && profs[i].service == service)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
} |