diff --git a/saeN.c b/saeN.c index 306159d..aa9496f 100644 --- a/saeN.c +++ b/saeN.c @@ -1,6 +1,7 @@ #include #include -#include "sae.h" +#include "saeN.h" +#define TAILLE 50 int creeadherent(int *tNC,char *tN,char *tPR,int *tA,int *tCA,int *tPO, int Tmax) { @@ -85,4 +86,168 @@ void globale() n=creeadherent(tNC,tN,tPR,tA,tCA,tPO,250); affichageA(tNC,tN,tPR,tA,tCA,tPO, n); valtrouve=recherche(tNC,n,100,&trouve); -} \ No newline at end of file +} + +void gestionAvecMenu (void) +{ + int idSports[TAILLE], nbPtSpo[TAILLE], n, choix; + n = chargementSport(idSports,nbPtSpo,TAILLE); + printf("------------------------------------------------\n"); //tableau qui s'affiche en premier pour choisir + printf("| Gestion des activités |\n"); + printf("| |\n"); + printf("| 1. Affichage |\n"); + printf("| 2. Ajout d'une Activité |\n"); + printf("| 3. Suppression d'une Activité |\n"); + printf("| 4. Changer le prix d'une activité |\n"); + printf("| 9. Quitter |\n"); + printf("| |\n"); + printf("------------------------------------------------\n"); //tableau qui s'affiche en premier pour choisir + printf("Rentrez un chiffre : \n"); //choix de l'option + scanf("%d%*c",&choix); + if (choix == 1) + {printf("\n"),affichage(idSports,nbPtSpo,n); printf("\n");} + if (choix == 2) + {printf("\n"),ajoutSport(idSports,nbPtSpo,&n,TAILLE); printf("\n");} + if (choix == 3) + {printf("\n"),enlèveSport(idSports,nbPtSpo,&n);printf("\n");} + if (choix == 4) + {printf("\n"),changprix(idSports,nbPtSpo,n);printf("\n");} + if (choix == 9) //quitte le logiciel si l'utilisateur a rentré 9 + {printf("\n"); printf("Arrêt du logiciel"); printf("\n"); printf("\n");} + sauvegardeSports(idSports,nbPtSpo,n); + return; +} + +void sauvegardeSports (int *idSports, int *pt, int n) +{ + int i; + FILE *fw; + fw = fopen("sport.txt","w"); + for (i = 0; i < n; i++) + fprintf(fw,"%d\t%d\n",idSports[i],pt[i]); + fclose(fw); +} + +int chargementSport (int *idSports, int *nbPtSpo, int tmax) +{ + int idSportTemp, ptTemp, i = 0; + FILE *fr; + fr = fopen("sport.txt","r"); + if (fr == NULL) + { + printf("Problème à l'ouverture du fichier"); + fclose(fr); + return -1; + } + fscanf(fr,"%d%d",&idSportTemp,&ptTemp); + while (!feof(fr)) + { + if (i == tmax) + { + printf("Problème, tableau plein"); + return i; + } + idSports[i] = idSportTemp; + nbPtSpo[i] = ptTemp; + i++; + fscanf(fr,"%d%d",&idSportTemp,&ptTemp); + } + fclose(fr); + return i; +} + +void affichage (int *idSports, int *pt, int n) +{ + int i; + printf("Sport:\tPoints:\n"); + for (i = 0; i < n; i++) + { + printf("%d\t%d\n",idSports[i],pt[i]); + } +} + +int rechercheSport (int *tablchoisi ,int tailletabl, int valacherch, char *trouvoupas) +{ + int i; + for (i=1; i valacherch) //il est plus loin que la valeur a recherché donc a pas trouvé + { + *trouvoupas = 'N'; + return i; + } + } +} + +void ajoutSport (int *idSports, int *pt, int *n, int taillePhys) +{ + int nvSpo, nvNbPt, place, i; + char trouvoupas; + if (*n == taillePhys) //vérifie qu'il y a encore de la place dans le tableau + { + printf("Erreur: la table est pleine"); + return; + } + printf("Numéro du nouveau sport: \n"); + scanf("%d%*c",&nvSpo); + printf("Nombre de points du nouveau sport: \n"); + scanf("%d%*c",&nvNbPt); + place = rechercheSport(idSports,*n,nvSpo,&trouvoupas); //donne où il doit ajouter le sport ou si il existe pas déjà + if (trouvoupas == 'O') //si le sport existe déjà + { + printf("Erreur, le sport existe déjà\n"); + return; + } + for (i = *n - 1 ; i >= place; i--) //décale les sports après celui à ajouter + { + idSports[i+1] = idSports[i]; + pt[i+1] = pt[i]; + } + idSports[place] = nvSpo; //ajoute le sport a sa place + pt[place] = nvNbPt; //ajoute le nb de points a sa place + *n = *n + 1; //augmente la taille logique + return; +} + +void changprix (int *idSport, int *pt, int n) +{ + int nvPrix , SpoChoix, place; + char trouve; + printf("Changer le prix de quel sport ?\n"); + scanf("%d%*c",&SpoChoix); + place = rechercheSport(idSport,n,SpoChoix,&trouve); + if (trouve == 'N') + { + printf("Erreur, le sport n'existe pas\n"); + return; + } + printf("Veuillez rentrer le nouveau prix: \n"); + scanf("%d%*c",&nvPrix); + pt[place] = nvPrix ; +} + +void enlèveSport (int *idSport, int *pt, int *n) +{ + int place, i, supSpo; + char trouvoupas; + printf("Numéro du sport à supprimer: \n"); + scanf("%d%*c",&supSpo); + place = rechercheSport(idSport,*n,supSpo,&trouvoupas); //donne la place du sport et si il l'a trouvé + if (trouvoupas == 'N') //il ne l'a pas trouvé + { + printf("Erreur, le sport existe pas\n"); + return; + } + for (i = place ; i < *n - 1; i++) //décalle pour pouvoir supprimer le sport + { + idSport[i] = idSport[i+1]; + pt[i] = pt[i+1]; + } + *n = *n - 1; //réduit la taille logique + return; +} diff --git a/saeN.h b/saeN.h index f7f8ae1..fa757ca 100644 --- a/saeN.h +++ b/saeN.h @@ -32,4 +32,20 @@ int recherche(int*tNC,int n, int val, int*trouve); /* \brief: globale */ -void globale(); \ No newline at end of file +void globale(); + +int chargementSport (int *idSports, int *nbPtSpo, int tmax); + +void affichage (int *idSports, int *pt, int n); + +void enlèveSport (int *idSport, int *pt, int *n); + +void gestionAvecMenu (void); + +int rechercheSport (int *tablchoisi ,int tailletabl, int valacherch, char *trouvoupas); + +void sauvegardeSports (int *idSports, int *pt, int n); + +void ajoutSport (int *idSports, int *pt, int *n, int taillePhys); + +void changprix (int *idSport, int *pt, int n); diff --git a/saetest b/saetest new file mode 100755 index 0000000..b4d23f3 Binary files /dev/null and b/saetest differ diff --git a/saetestN.c b/saetestN.c index 02afa4c..fdcbcf1 100644 --- a/saetestN.c +++ b/saetestN.c @@ -1,8 +1,8 @@ -#include "sae.h" +#include "saeN.h" #include int main(void) { globale(); return 0; -} \ No newline at end of file +}