TP3
This commit is contained in:
122
TP3/3.2.cpp
Normal file
122
TP3/3.2.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int Nmax = 10;
|
||||
|
||||
struct PROF
|
||||
{
|
||||
int Id;
|
||||
string nom;
|
||||
string service;
|
||||
|
||||
void saisie();
|
||||
void afficher();
|
||||
};
|
||||
|
||||
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:
|
||||
profs[N].saisie();
|
||||
profs[N++].afficher();
|
||||
break;
|
||||
case 2:
|
||||
DeplacerDroite(profs, N);
|
||||
N++;
|
||||
profs[0].saisie();
|
||||
profs[0].afficher();
|
||||
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;
|
||||
profs[i].afficher();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PROF::saisie()
|
||||
{
|
||||
cout << "Identifiant: ";
|
||||
cin >> Id;
|
||||
cin.ignore();
|
||||
cout << "Nom : \n";
|
||||
|
||||
// cin >> prof.nom;
|
||||
getline(cin, nom);
|
||||
cout << "Service : \n";
|
||||
// cin.ignore();
|
||||
getline(cin, service);
|
||||
// cin >> prof.service;
|
||||
}
|
||||
|
||||
void PROF::afficher()
|
||||
{
|
||||
cout << "Prof " << Id << "\n"
|
||||
<< "Nom : " << nom << "\n"
|
||||
<< "Service : " << 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;
|
||||
}
|
||||
Reference in New Issue
Block a user