Vous êtes sur la page 1sur 7

partement = departement;

this->moyenne = moyenne;
this->mention = mention;
}

void Etudiant::save()
{
ofstream flux (Etudiant::file, ios::out | ios::app);
if(flux)
{
flux << matricule << ";" << nom << ";" << prenom << ";" << departement <<
";" << moyenne << ";" << mention << endl;
cout << "Enregistrement réussie !!!" << endl;
}
else
cout << "Ce fichier n'a pas pû être ouvert" << endl;

void Etudiant::display()
{
cout << "==========================================" << endl;
cout << "Matricule ---> " << matricule << endl;
cout << "Nom ---> " << nom << endl;
cout << "Prénom ---> " << prenom << endl;
cout << "Département ---> " << departement << endl;
cout << "Moyenne ---> " << moyenne << endl;
cout << "Mention ---> " << mention << endl;
cout << "=========================================" << endl;
}

void Etudiant::getAll()
{
Etudiant e;
bool trouve = false;
string line;
ifstream flux (Etudiant::file, ios::in);
if(flux)
{
cout <<
"+---------------------------------------------------------------------------------
--+" << endl;
cout << "+ Matricule | Nom | Prénom | Département |
Moyenne | Mention |" << endl;
cout <<
"+---------------------------------------------------------------------------------
--+" << endl;
while(getline(flux,line))
{
e.split(line);
e.line();
trouve = true;
}
flux.close();
if(!trouve)
cout << "Liste Vide" << endl;
}
else
cout << "Ce fichier n'a pas pû être ouvert" << endl;
}

void Etudiant::search()
{
Etudiant e;
bool trouve = false;
string line;
ifstream flux (Etudiant::file, ios::in);
if(flux)
{
while (getline(flux,line))
{
if(matricule == line.substr(0,7))
{
trouve = true;
break;
}
}
flux.close();
if(trouve)
{
e.split(line);
e.display();
}
else
{
cout << "Cet étudiant n'existe pas" << endl;
}

}
else
cout << "Ce fichier n'a pas pû être ouvert" << endl;
}

void Etudiant::update()
{
bool trouve = false;
string line, data = "", nom, prenom, departement, mentions;
float moy, note[6], som = 0;
ifstream flux (Etudiant::file, ios::in);
if(flux)
{
while(getline(flux,line))
{
if(matricule != line.substr(0,7))
{
data += line + "\n";
}
else
{
cout << "Veuillez saisir les nouvelles informations" << endl;
cout << "Nom ---> "; cin.ignore(255,'\n');
getline(cin,nom);
cout << "Prénom ---> "; getline(cin,prenom);
cout << "Département ---> "; getline(cin,departement);
cout << "Les 6 notes " << endl;
for(int i = 0; i < 6; i++)
{
cout << "Note " << i+1 << " : ";
while(!(cin >> note[i])){
cout << "Erreur de saisie, reprendre la note " << i+1 << " --->
";
cin.clear();
cin.ignore(255,'\n');
}
som += note[i];
}
moy = Etudiant::Moyenne(som);
mentions = Etudiant::Mention(moy);
data += line.substr(0,7) + ";";
data += nom + ";";
data += prenom + ";";
data += departement + ";";
data += to_string(moy) + ";";
data += mentions + "\n";
trouve = true;
}
}
flux.close();
ofstream fluxSortie;
if(trouve)
{
fluxSortie.open(Etudiant::file, ios::out | ios::trunc);
fluxSortie << data;
fluxSortie.close();
cout << "Modification reussi" << endl;
}
else
{
cout << "Cet étudiant n'existe pas" << endl;
}
}
else
cout << "Ce fichier n'a pas pû être ouvert" << endl;
}

void Etudiant::drop()
{
bool trouve = false;
string line, data = "";
ifstream flux (Etudiant::file, ios::in);
if(flux)
{
while (getline(flux,line))
{
if(matricule != line.substr(0,7))
{
data += line + "\n";
}
else
{
trouve = true;
}
}
flux.close();
ofstream fluxSortie;
if(trouve)
{
fluxSortie.open(Etudiant::file, ios::out | ios::trunc);
fluxSortie << data;
fluxSortie.close();
cout << "Suppression réussie" << endl;
}
else
{
cout << "Cet étudiant n'existe pas" << endl;
}

}
else
{
cout << "Ce fichier n'a pas pû être ouvert" << endl;
}
}

void Etudiant::split(string line)


{
int pos = 7, nextPos;
matricule = line.substr(0,pos);
nextPos = line.find(";",pos+1);
nom = line.substr(pos+1,nextPos-pos-1);
pos = nextPos;
nextPos = line.find(";",pos+1);
prenom = line.substr(pos+1,nextPos-pos-1);
pos = nextPos;
nextPos = line.find(";",pos+1);
departement = line.substr(pos+1,nextPos-pos-1);
pos = nextPos;
nextPos = line.find(";",pos+1);
moyenne = stof(line.substr(pos+1,nextPos-pos-1));
pos = nextPos;
nextPos = line.find(";",pos+1);
mention = line.substr(pos+1,nextPos-pos-1);
}

void Etudiant::line()
{

cout << "| " << setw(11) << matricule << " | " << setw(7) << nom << " | " <<
setw(19) << prenom << " | " << setw(12) << departement << " | " << setw(6) <<
moyenne << " | " << setw(9) << mention << " | " << endl;
cout <<
"+---------------------------------------------------------------------------------
--+" << endl;

float Etudiant::Moyenne(float som)


{
return som / 6;
}

string Etudiant::Mention(float moy)


{
if (moy >= 9)
return "EXCELLENT";
else if (moy >= 8)
return "TBIEN";
else if (moy >= 7)
return "BIEN";
else if (moy >= 6)
return "ABIEN";
else if (moy >= 5)
return "PASSABLE";
else if (moy >= 4)
return "INSUFFISANT";
else
return "ECHEC";
}
int Etudiant::getMatricule()
{
ifstream flux (Etudiant::file, ios::in);
string line, lineCopy = "ET23000";
while(getline(flux,line)) lineCopy = line;
int matriculeline = stoi(lineCopy.substr(4,3));

return matriculeline;

}
class App{
private:
static void save();
static void readAll();
static void search();
static void update();
static void drop();
static void pause();
public:
static void run();
};

void App::run()
{
int choix;
do
{
system("clear");
cout << "+---------------------------------|" << endl;
cout << "| 1. AJOUTER UN ÉTUDIANTS |" << endl;
cout << "+---------------------------------|" << endl;
cout << "| 2. LISTE DE TOUS LES ETUDIANTS |" << endl;
cout << "+---------------------------------|" << endl;
cout << "| 3. RECHERCHER UN ÉTUDIANT |" << endl;
cout << "+---------------------------------|" << endl;
cout << "| 4. MODIFICATION D'ÉTUDIANTS |" << endl;
cout << "+---------------------------------|" << endl;
cout << "| 5. SUPPRESSION D'ÉTUDIANTS |" << endl;
cout << "+---------------------------------|" << endl;
cout << "| 6. QUITTER |" << endl;
cout << "+---------------------------------+" << endl;
cout << "Votre choix >> ";
while(!(cin >> choix))
{
cout << "Erreur de saisie reprendre ---> ";
cin.clear();
cin.ignore(255,'\n');
}
switch (choix)
{
case 1 : App::save(); App::pause(); break;
case 2 : App::readAll(); App::pause(); break;
case 3 : App::search(); App::pause(); break;
case 4 : App::update(); App::pause(); break;
case 5 : App::drop(); App::pause(); break;
case 6 : cout << "Vous venez de quittez l'application" << endl;
break;
default:
cout << "Choix Incorrect " << endl; App::pause();
break;
}
} while (choix != 6);

void App::save()
{
system("clear");
string nom, prenom, departement, mentions;
float note[6], som = 0, moy;
cout << "==== ENREGISTREMENT D'UN ÉTUDIANT ====" << endl;
cout << "Nom ---> ";
cin.ignore(255,'\n'); getline(cin, nom);
cout << "Prénom ---> "; getline(cin,prenom);
cout << "Département ---> "; getline(cin,departement);
cout << "Sasir les 6 notes " << endl;
for(int i = 0; i < 6; i++)
{
cout << "Note " << i+1 << " : ";
while(!(cin >> note[i])){
cout << "Erreur de saisie, reprendre la note " << i+1 << " ---> ";
cin.clear();
cin.ignore(255,'\n');
}
som += note[i];
}
moy = Etudiant::Moyenne(som);
mentions = Etudiant::Mention(moy);
Etudiant(nom,prenom,departement,moy,mentions).save();
}

void App::readAll()
{
system("clear");
cout << "==== LISTES DES ÉTUDIANTS ====" << endl;
Etudiant::getAll();
}

void App::search()
{
system("clear");
string matricule;
cout << "=== RECHERCHE D'UN ÉTUDIANT ===" << endl;
cout << "Veuillez saisir son matricule >> "; cin >> matricule;
Etudiant(matricule).search();
}
void App::update()
{
system("clear");
string matricule;
cout << "=== MODIFICATION D'UN ÉTUDIANT ===" << endl;
cout << "Veuillez saisir son matricule >> "; cin >> matricule;
Etudiant(matricule).update();
}

void App::drop()
{
system("clear");
string matricule;
cout << "=== SUPPRESSION D'UN ÉTUDIANT ===" << endl;
cout << "Veuillez saisir son matricule >> "; cin >> matricule;
Etudiant(matricule).drop();
}

void App::pause()
{
char systempause;
cin.ignore(255,'\n');
cout << "Appuyez sur une touche pour continuer...";
cin.get(systempause);
}

int main(){
system("clear");
App::run();
return 0;
}

Vous aimerez peut-être aussi