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.
367 lines
11 KiB
367 lines
11 KiB
/*!
|
|
\file deux.c
|
|
\author GOIGOUX Lucie & JEUDI--LEMOINE Alix
|
|
\date 23/12/22
|
|
\brief Partie 2 de la SAE 1.02
|
|
|
|
Application de gestion des candidature dans les IUT de France
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include "deux.h"
|
|
|
|
|
|
Candidat* creerCandidat(void) {
|
|
Candidat* candidat = (Candidat*) malloc(sizeof(Candidat));
|
|
|
|
if(candidat == NULL) {
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
|
|
//candidat->listeCandidatures = (ListeCandidatures) malloc(0);
|
|
|
|
return candidat;
|
|
}
|
|
|
|
Candidature* creerCandidature(void) {
|
|
Candidature* candid = (Candidature*) malloc(sizeof(Candidature));
|
|
|
|
if(candid == NULL) {
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
|
|
candid->decision = 0;
|
|
candid->validation = 0;
|
|
return candid;
|
|
}
|
|
|
|
void ajouterCandidat(ListeCandidats* listePointer, int* nbCandidats, Candidat* candidat) {
|
|
ListeCandidats listeNew = (ListeCandidats) realloc(*listePointer, (*nbCandidats+1)*sizeof(Candidat*));
|
|
|
|
if(listeNew == NULL) {
|
|
perror("realloc");
|
|
exit(errno);
|
|
}
|
|
|
|
*listePointer = listeNew;
|
|
|
|
*nbCandidats+=1;
|
|
candidat->id = *nbCandidats;
|
|
(*listePointer)[*nbCandidats-1] = candidat;
|
|
}
|
|
|
|
void ajouterCandidature(Candidat* candidat, Candidature* candidature) {
|
|
candidat->listeCandidatures = (ListeCandidatures) realloc(candidat->listeCandidatures, (candidat->nbCandidatures+1)*sizeof(Candidature*));
|
|
candidat->listeCandidatures[candidat->nbCandidatures] = candidature;
|
|
candidat->nbCandidatures+=1;
|
|
}
|
|
|
|
int checkCandidature(Candidat* candidat, Candidature candid) {
|
|
int nbCandidatures = candidat->nbCandidatures;
|
|
|
|
for(int i=0; i<nbCandidatures; i++)
|
|
if(strcmp(candidat->listeCandidatures[i]->ville, candid.ville) == 0)
|
|
if(strcmp(candidat->listeCandidatures[i]->departement, candid.departement) == 0)
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void afficherListeCandidats(ListeCandidats liste, int nbCandidats) {
|
|
ListeCandidats liste2 = (ListeCandidats) malloc(nbCandidats*sizeof(Candidat*));
|
|
|
|
if(liste2 == NULL) {
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
|
|
for (int i=0; i<nbCandidats; i++) {
|
|
memcpy(&liste2[i], &liste[i], sizeof(Candidat*));
|
|
}
|
|
|
|
qsort(liste2, nbCandidats, sizeof(Candidat*), compareCandidats);
|
|
|
|
for(int i=0; i<nbCandidats; i++) {
|
|
Candidat* candidat = liste2[i];
|
|
|
|
afficherCandidat(candidat);
|
|
}
|
|
}
|
|
|
|
void afficherCandidat(Candidat* candidat) {
|
|
printf("Candidat n°%d, '%s %s' :"
|
|
"\n - Moyenne en mathématiques : %f\n - Moyenne en français : %f"
|
|
"\n - Moyenne en anglais : %f\n - Moyenne en spécialité : %f"
|
|
"\n - Nombre de candidatures : %d\n\n",
|
|
candidat->id, candidat->prenom, candidat->nom,
|
|
candidat->moyenneMath, candidat->moyenneFrancais,
|
|
candidat->moyenneAnglais, candidat->moyenneSpecialite,
|
|
candidat->nbCandidatures);
|
|
}
|
|
|
|
void afficherCandidatures(ListeCandidatures candidatures, int nbCandidatures) {
|
|
if(nbCandidatures == 0) return;
|
|
|
|
char decision[LEN_MAX], validation[LEN_MAX];
|
|
Candidature* candidature = candidatures[nbCandidatures-1];
|
|
|
|
switch (candidature->decision) {
|
|
case 0:
|
|
strcpy(decision, "en cours de traitement");
|
|
break;
|
|
case 1:
|
|
strcpy(decision, "admis");
|
|
break;
|
|
case -1:
|
|
strcpy(decision, "refusé");
|
|
break;
|
|
case 2:
|
|
strcpy(decision, "sur liste d'attente");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
switch (candidature->validation) {
|
|
case 0:
|
|
strcpy(validation, "n'a pas encore décidé");
|
|
break;
|
|
case 1:
|
|
strcpy(validation, "refuse la proposition");
|
|
break;
|
|
case -1:
|
|
strcpy(validation, "accepte");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
printf("Candidature pour le département '%s' à l'IUT '%s' : \n"
|
|
" - Décision du département : %s,\n - Décision du candidat : %s\n\n",
|
|
candidature->departement, candidature->ville, decision, validation);
|
|
|
|
afficherCandidatures(candidatures, nbCandidatures-1);
|
|
}
|
|
|
|
/*
|
|
void afficherCandidatures_(Candidat* candidat) {
|
|
int nbCandidatures = candidat->nbCandidatures;
|
|
|
|
for(int i=0; i<nbCandidatures; i++) {
|
|
char decision[LEN_MAX], validation[LEN_MAX];
|
|
Candidature* candidature = candidat->listeCandidatures[i];
|
|
|
|
switch (candidature->decision) {
|
|
case 0:
|
|
strcpy(decision, "en cours de traitement");
|
|
break;
|
|
case 1:
|
|
strcpy(decision, "admis");
|
|
break;
|
|
case -1:
|
|
strcpy(decision, "refusé");
|
|
break;
|
|
case 2:
|
|
strcpy(decision, "sur liste d'attente");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
switch (candidature->validation) {
|
|
case 0:
|
|
strcpy(validation, "n'a pas encore décidé");
|
|
break;
|
|
case 1:
|
|
strcpy(validation, "refuse la proposition");
|
|
break;
|
|
case -1:
|
|
strcpy(validation, "accepte");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
printf("Candidature pour le département '%s' à l'IUT '%s' : \n"
|
|
" - Décision du département : %s,\n - Décision du candidat : %s\n\n",
|
|
candidature->departement, candidature->ville, decision, validation);
|
|
}
|
|
|
|
if(nbCandidatures == 0)
|
|
fprintf(stderr, "\e[0;91mErreur : vous n'avez aucune candidature en cours, merci de réessayer plus tard.\n\e[0m");
|
|
}*/
|
|
|
|
ListeCandidats readCandidats(int* nbCandidats) {
|
|
FILE *fe = fopen("donnees/candidats.don", "r");
|
|
|
|
if(fe == NULL) {
|
|
fprintf(stderr, "Erreur: impossible de lire le fichier candidats.don");
|
|
return NULL;
|
|
}
|
|
|
|
fscanf(fe, "%d", nbCandidats);
|
|
|
|
ListeCandidats liste = (ListeCandidats) malloc(*nbCandidats*sizeof(Candidat*));
|
|
|
|
if(liste == NULL) {
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
|
|
for(int i=0; i<*nbCandidats; i++) {
|
|
Candidat* candidat = creerCandidat();
|
|
fscanf(fe, "%d\n%[^\n]\n%[^\n]\n%f\n%f\n%f\n%f\n%d",
|
|
&candidat->id, candidat->nom, candidat->prenom,
|
|
&candidat->moyenneMath, &candidat->moyenneFrancais,
|
|
&candidat->moyenneAnglais, &candidat->moyenneSpecialite,
|
|
&candidat->nbCandidatures);
|
|
|
|
ListeCandidatures listeCandidatures = (ListeCandidatures) malloc(candidat->nbCandidatures*sizeof(Candidature*));
|
|
|
|
if(listeCandidatures == NULL) {
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
|
|
candidat->listeCandidatures = listeCandidatures;
|
|
|
|
for(int j=0; j<candidat->nbCandidatures; j++) {
|
|
Candidature* candidature = (Candidature*) malloc(sizeof(Candidature));
|
|
|
|
if(candidature == NULL) {
|
|
perror("malloc");
|
|
exit(errno);
|
|
}
|
|
|
|
fscanf(fe, "\n%[^\n]\n%[^\n]\n%d%d",
|
|
candidature->ville, candidature->departement,
|
|
&candidature->decision, &candidature->validation);
|
|
candidat->listeCandidatures[j] = candidature;
|
|
}
|
|
|
|
liste[i] = candidat;
|
|
}
|
|
|
|
return liste;
|
|
}
|
|
|
|
int compareCandidats(const void* p1, const void* p2) {
|
|
Candidat* c1 = *(ListeCandidats) p1;
|
|
Candidat* c2 = *(ListeCandidats) p2;
|
|
|
|
char nomComplet1[60];
|
|
strcpy(nomComplet1, c1->nom);
|
|
strcat(nomComplet1, c1->prenom);
|
|
|
|
char nomComplet2[60];
|
|
strcpy(nomComplet2, c2->nom);
|
|
strcat(nomComplet2, c2->prenom);
|
|
|
|
return strcmp(nomComplet1, nomComplet2);
|
|
}
|
|
|
|
int saveCandidats(ListeCandidats liste, int nbCandidats) {
|
|
FILE *fe = fopen("donnees/candidats.don", "w");
|
|
|
|
if(fe == NULL) {
|
|
fprintf(stderr, "Erreur: impossible de lire le fichier candidats.don");
|
|
return -1;
|
|
}
|
|
|
|
fprintf(fe, "%d", nbCandidats);
|
|
|
|
for(int i=0; i<nbCandidats; i++) {
|
|
Candidat* candidat = liste[i];
|
|
|
|
fprintf(fe, "\n%d\n%s\n%s\n%f\t%f\t%f\t%f\n%d",
|
|
candidat->id, candidat->nom, candidat->prenom,
|
|
candidat->moyenneMath, candidat->moyenneFrancais,
|
|
candidat->moyenneAnglais, candidat->moyenneSpecialite,
|
|
candidat->nbCandidatures);
|
|
|
|
ListeCandidatures listeCandidatures = candidat->listeCandidatures;
|
|
|
|
for(int j=0; j<candidat->nbCandidatures; j++) {
|
|
Candidature* candidature = listeCandidatures[j];
|
|
fprintf(fe, "\n%s\n%s\n%d\n%d",
|
|
candidature->ville, candidature->departement,
|
|
candidature->decision, candidature->validation);
|
|
}
|
|
}
|
|
|
|
fclose(fe);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void test2(void) {
|
|
int nbCandidats;
|
|
//printf("pa kc");
|
|
ListeCandidats liste = readCandidats(&nbCandidats);
|
|
|
|
/*
|
|
afficherCandidat(liste[0]);
|
|
afficherCandidat(liste[1]);
|
|
|
|
//triCandidats(liste, nbCandidats);
|
|
|
|
afficherListeCandidats(liste, nbCandidats);
|
|
|
|
// afficherCandidatures(liste[0]);
|
|
|
|
afficherCandidat(liste[0]);
|
|
afficherCandidat(liste[1]);*/
|
|
|
|
//sauvegarderCandidats(liste, nbCandidats);
|
|
|
|
Candidat* candidat = creerCandidat();
|
|
|
|
printf("Nom : ");
|
|
scanf("%[^\n]", candidat->nom);
|
|
printf("Prénom : ");
|
|
scanf("%*c%[^\n]", candidat->prenom);
|
|
printf("Moyenne en maths : ");
|
|
scanf("%f", &candidat->moyenneMath);
|
|
printf("Moyenne en français : ");
|
|
scanf("%f", &candidat->moyenneFrancais);
|
|
printf("Moyenne en anglais : ");
|
|
scanf("%f", &candidat->moyenneAnglais);
|
|
printf("Moyenne en spécialité : ");
|
|
scanf("%f", &candidat->moyenneSpecialite);
|
|
|
|
ajouterCandidat(&liste, &nbCandidats, candidat);
|
|
|
|
afficherListeCandidats(liste, nbCandidats);
|
|
|
|
Candidature* candid = creerCandidature();
|
|
|
|
char searchIUT[LEN_MAX], searchDept[LEN_MAX];
|
|
printf("Entrez la ville dans laquelle vous souhaitez candidater : ");
|
|
scanf("%s", searchIUT);
|
|
/*
|
|
VilleIUT* ville = NULL;
|
|
int i;
|
|
for(i=0; i<*nbVilles; i++)
|
|
if(strcmp(tiut[i]->ville, searchIUT) == 0)
|
|
ville = tiut[i];
|
|
|
|
if(ville == NULL)
|
|
fprintf(stderr, "\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT);
|
|
else {}*/
|
|
|
|
printf("Entrez le département dans lequel vous souhaitez candidater : ");
|
|
scanf("%s", searchDept);
|
|
|
|
strcpy(candid->ville, searchIUT);
|
|
strcpy(candid->departement, searchDept);
|
|
|
|
ajouterCandidature(liste[2], candid);
|
|
|
|
afficherListeCandidats(liste, nbCandidats);
|
|
//afficherCandidatures(liste[2]);
|
|
} |