You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
7.2 KiB

#include "SAE.h"
/* Partie 2 */
/*
Afficher les infos d'un candidat
Afficher la liste des candidats par departement trié par ordre alphabetique
*/
int chargerCandidats(Etudiant *tetud[])
{
FILE *file;
file = fopen("resultats.txt", "r");
int nbCandidats, i = 0;
Choix choix;
if (file == NULL)
{
printf("Erreur d'ouverture du fichier !\n");
exit(1);
}
fscanf(file, "%d", &nbCandidats);
while (i < nbCandidats)
{
tetud[i] = (Etudiant *)malloc(sizeof(Etudiant));
if (tetud[i] == NULL)
{
printf("Erreur malloc\n");
exit(2);
}
fscanf(file, "%d%s%s", &tetud[i]->num, tetud[i]->nom, tetud[i]->prenom); // TODO : Faire un fgets pour le prénom
for (int note = 0; note < 4; note++)
{
fscanf(file, "%f", &tetud[i]->tabNotes[note]);
}
tetud[i]->tabNotes[4] = (tetud[i]->tabNotes[0] + tetud[i]->tabNotes[1] + tetud[i]->tabNotes[2] + tetud[i]->tabNotes[3]) / 4;
fscanf(file, "%d", &tetud[i]->nbChoix);
tetud[i]->lChoix = listenouvChoix();
for (int n = 0; n < tetud[i]->nbChoix; n++)
{
fscanf(file, "%s%s%d%d", choix.ville, choix.departement, &choix.decisionAdmission, &choix.decisionCandidat);
tetud[i]->lChoix = insererChoix(tetud[i]->lChoix, choix);
}
i++;
}
return i;
}
void sauvegarderCandidats(Etudiant *tetud[], int nbCandidats)
{
FILE *file;
file = fopen("dptInfos.txt", "w");
if (file == NULL)
{
printf("Erreur d'ouverture du fichier !\n");
exit(1);
}
fprintf(file, "%d\n", nbCandidats);
for (int i = 0; i < nbCandidats; i++)
{
fprintf(file, "%d\n%s\n%s\n", tetud[i]->num, tetud[i]->nom, tetud[i]->prenom);
for (int note = 0; note < 4; note++)
{
fprintf(file, "%.2f\t", tetud[i]->tabNotes[note]);
}
fprintf(file, "\n%d\n", tetud[i]->nbChoix);
sauvegarderChoix(tetud[i]->lChoix, file);
}
}
int rechercheCandidat(Etudiant *tetud[], int nbCandidats, int numRecherche, bool *trouve)
{
int i;
for (i = 0; i < nbCandidats; i++)
{
if (numRecherche == tetud[i]->num)
{
*trouve = true;
return i;
}
}
*trouve = false;
return i;
}
void afficherEtudiant(Etudiant mEtudiant)
{
printf("Numéro : %d\nNom : %s\nPrénom : %s\nNotes : %.2f\t%.2f\t%.2f\t%.2f\nNombre de choix : %d\n", mEtudiant.num, mEtudiant.nom, mEtudiant.prenom, mEtudiant.tabNotes[0], mEtudiant.tabNotes[1], mEtudiant.tabNotes[2], mEtudiant.tabNotes[3], mEtudiant.nbChoix);
afficherChoix(mEtudiant.lChoix);
printf("\n");
}
void afficherCandidat(Etudiant *tetud[], int nbCandidats)
{
int num, index;
bool trouve;
printf("Veuillez entrer le numéro de l'étudiant recherché :\n> ");
scanf("%d", &num);
index = rechercheCandidat(tetud, nbCandidats, num, &trouve);
if (trouve == false)
{
printf("Le numéro de l'étudiant recherché n'existe pas.\n");
return;
}
afficherEtudiant(*tetud[index]);
}
void afficherCandidats(Etudiant *tetud[], int nbCandidats)
{
for (int i = 0; i < nbCandidats; i++)
{
afficherEtudiant(*tetud[i]);
}
}
void sauvegarderChoix(ListeChoix lChoix, FILE *file)
{
if (lChoix != NULL)
{
fprintf(file, "%s\n%s\n%d\n%d\n", lChoix->choix.ville, lChoix->choix.departement, lChoix->choix.decisionAdmission, lChoix->choix.decisionCandidat);
sauvegarderChoix(lChoix->suiv, file);
}
}
void ajouterCandidature(Etudiant *tetud[], int nbCandidats, VilleIUT *tiut[], int nbVillesIUT)
{
int num, posCand, posVille;
char ville[30], dept[30];
bool trouve;
Choix c;
//! AUTHENTIFICATION
printf("Entrez votre numéro de candidat :\n> ");
scanf("%d", &num);
posCand = rechercheCandidat(tetud, nbCandidats, num, &trouve);
if (!trouve)
{
printf("Numéro de candidat non trouvé.\n");
return;
}
printf("Entrez la ville du département que vous souhaitez ajouter :\n> ");
scanf("%s", ville);
posVille = rechercheVille(tiut, nbVillesIUT, ville, &trouve);
if (!trouve)
{
printf("Ville non trouvée.\n");
return;
}
printf("Entrez le département que vous souhaitez ajouter :\n> ");
scanf("%s", dept);
rechercheDept(tiut[posVille]->ldept, dept, &trouve);
if (!trouve)
{
printf("Département non trouvé.\n");
return;
}
strcpy(c.ville, ville);
strcpy(c.departement, dept);
c.decisionAdmission = 0;
c.decisionCandidat = 0;
tetud[posCand]->lChoix = insererChoix(tetud[posCand]->lChoix, c);
tetud[posCand]->nbChoix++;
}
void supprimerCandidature(Etudiant *tetud[], int nbCandidats)
{
int num, posCand, posVille;
char ville[30], dept[30];
bool trouve;
Choix c;
//! AUTHENTIFICATION
printf("Entrez votre numéro de candidat :\n> ");
scanf("%d", &num);
posCand = rechercheCandidat(tetud, nbCandidats, num, &trouve);
if (!trouve)
{
printf("Numéro de candidat non trouvé.\n");
return;
}
printf("Entrez la ville du département que vous souhaitez supprimer :\n> ");
scanf("%s", c.ville);
printf("Entrez le département que vous souhaitez supprimer :\n> ");
scanf("%s", c.departement);
trouve = rechercheChoix(tetud[posCand]->lChoix, c);
if (!trouve)
{
printf("Choix non trouvé.\n");
return;
}
tetud[posCand]->lChoix = supprimerChoix(tetud[posCand]->lChoix, c);
tetud[posCand]->nbChoix--;
}
int inscription(Etudiant *tetud[], int nbCandidats, VilleIUT *tiut[], int nbVillesIUT)
{
Etudiant cand;
Choix c;
bool trouve;
int posVille;
printf("Quel est votre nom ?\n> ");
scanf("%s", cand.nom);
printf("Quel est votre prénom ?\n> ");
scanf("%s", cand.prenom);
printf("Entrez vos notes en : mathématiques, français, anglais et en spécialité :\n> ");
scanf("%f %f %f %f", &cand.tabNotes[0], &cand.tabNotes[1], &cand.tabNotes[2], &cand.tabNotes[3]);
printf("Entrez votre premier choix :\n");
printf("Ville :\n> ");
scanf("%s", c.ville);
posVille = rechercheVille(tiut, nbVillesIUT, c.ville, &trouve);
if (!trouve)
{
printf("Ville non trouvée.\n");
return nbCandidats;
}
printf("Département :\n> ");
scanf("%s", c.departement);
rechercheDept(tiut[posVille]->ldept, c.departement, &trouve);
if (!trouve)
{
printf("Département non trouvé.\n");
return nbCandidats;
}
c.decisionAdmission = 0;
c.decisionCandidat = 0;
cand.lChoix = listenouvChoix();
cand.lChoix = insererChoix(cand.lChoix, c);
cand.nbChoix = 1;
cand.num = nbCandidats + 1;
tetud[nbCandidats] = (Etudiant *)malloc(sizeof(Etudiant));
printf("Vous êtes le candidat numéro %d.\n", nbCandidats + 1);
*tetud[nbCandidats] = cand;
nbCandidats++;
return nbCandidats;
}
// ? Comment definir la note sur 20 mise lors de l'etude du dossier ?
// ? Ajouter une variable dans la structure Admission ?
// ? Ou mettre la liste et la note dans un tableau ?
// ? Après examen de chaque dossier de candidature,
// ? le jury doit regarder ou la note peut etre calculée automatiquement ?