diff --git a/conf.c b/conf.c index 0255477..9913d62 100644 --- a/conf.c +++ b/conf.c @@ -147,7 +147,7 @@ void removeListener(ptListener listenerChain, int id) { } } -void addConfToConfList(ptConfList confList, ptConf conf) { +void addConfToConfList(ptConfList confList, ptConf conf, int grade) { ptConfList px = confList; while (px -> next != NULL) { @@ -156,6 +156,7 @@ void addConfToConfList(ptConfList confList, ptConf conf) { px -> conf = conf; px -> next = (ptConfList) malloc(sizeof(tConfList)); + px -> grade = grade; px -> next -> next = NULL; } @@ -164,13 +165,13 @@ void printConfList(ptConfList confList) { printf("Participation aux conferences : "); while (px -> next != NULL) { - printf("%s ", px -> conf -> title); + printf("%s(%d) ", px -> conf -> title, px -> grade); px = px -> next; } printf("\n"); } -void addListenerToListenerList(ptListenerList listenerList, ptListener listener) { +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) { ptListenerList px = listenerList; while (px -> next != NULL) { @@ -179,6 +180,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener) px -> listener = listener; px -> next = (ptListenerList) malloc(sizeof(tListenerList)); + px -> grade = grade; px -> next -> next = NULL; } @@ -187,13 +189,13 @@ void printListenerList(ptListenerList listenerList) { printf("Participants : "); while (px -> next != NULL) { - printf("%s ", px -> listener -> name); + printf("%s(%d) ", px -> listener -> name, px -> grade); px = px -> next; } printf("\n"); } -void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId) { +void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) { ptConf px = confChain; ptListener py = listenerChain; ptListenerList pz; @@ -218,6 +220,36 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i return; } - addListenerToListenerList(px -> listeners, py); - addConfToConfList(py -> confs, px); + addListenerToListenerList(px -> listeners, py, grade); + addConfToConfList(py -> confs, px, grade); +} + +int confGradeAvg(ptConf conf) { + ptListenerList px = conf -> listeners; + int total = 0, nb = 0; + + while (px -> next != NULL) { + total += px -> grade; + nb++; + px = px -> next; + } + + if (nb != 0) { + return total / nb; + } else { + return -1; + } + +} + +int confParticipations(ptConf conf) { + ptListenerList px = conf -> listeners; + int nb = 0; + + while (px -> next != NULL) { + nb++; + px = px -> next; + } + + return nb; } \ No newline at end of file diff --git a/conf.h b/conf.h index 7924973..194d026 100644 --- a/conf.h +++ b/conf.h @@ -16,6 +16,7 @@ typedef struct conf { typedef struct confList { struct conf* conf; + int grade; struct confList* next; } tConfList; @@ -31,6 +32,7 @@ typedef struct listener { typedef struct listenerList { struct listener* listener; + int grade; struct listenerList* next; } tListenerList; @@ -47,10 +49,12 @@ int findListenerId(ptListener listenerChain); ptListener newListenerChain(); void addListener(ptListener listenerChain, int id, char name[], int age, int level); void removeListener(ptListener listenerChain, int id); -void addConfToConfList(ptConfList confList, ptConf conf); +void addConfToConfList(ptConfList confList, ptConf conf, int grade); void printConfList(ptConfList confList); -void addListenerToListenerList(ptListenerList listenerList, ptListener listener); +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); void printListenerList(ptListenerList listenerList); -void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId); +void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); +int confGradeAvg(ptConf conf); +int confParticipations(ptConf conf); #endif // CONF_H diff --git a/data/relations b/data/relations index f53a0b2..ced4fda 100644 --- a/data/relations +++ b/data/relations @@ -1 +1 @@ -1:3,2,1,6,11,12,13,14,15,16 +1:1;12,2;12,12;0 diff --git a/fileManager.c b/fileManager.c index 58c5296..e6d6088 100644 --- a/fileManager.c +++ b/fileManager.c @@ -4,56 +4,45 @@ #include "conf.h" void readConfs(ptConf confChain) { - FILE *file = fopen("./data/confs", "r"); - char line[100]; - char *tokens[6]; - char *token; - - if (file == NULL) { - printf("ça marche pas."); - return; - } - - while (fgets(line, sizeof(line), file)) { - token = strtok(line, ","); - - int i = 0; + FILE *file = fopen("./data/confs", "r"); + char line[100]; + char *token; - while (token != NULL && i < 6) { - tokens[i] = token; - i ++; - token = strtok(NULL, ","); - } - - addConf(confChain, atoi(tokens[0]), tokens[1], tokens[2], atoi(tokens[3]), atoi(tokens[4]), atoi(tokens[5])); + if (file == NULL) { + printf("ça marche pas."); + return; + } + + while (fgets(line, sizeof(line), file)) { + int id = atoi(strtok(line, ",")); + char *title = strtok(NULL, ","); + char *speaker = strtok(NULL, ","); + int day = atoi(strtok(NULL, ",")); + int month = atoi(strtok(NULL, ",")); + int year = atoi(strtok(NULL, ",")); + + addConf(confChain, id, title, speaker, day, month, year); } fclose(file); } void readListeners(ptListener listenerChain) { - FILE *file = fopen("./data/listeners", "r"); - char line[100]; - char *tokens[4]; - char *token; - - if (file == NULL) { - printf("ça marche pas."); - return; - } - - while (fgets(line, sizeof(line), file)) { - token = strtok(line, ","); - - int i = 0; + FILE *file = fopen("./data/listeners", "r"); + char line[100]; + char *token; - while (token != NULL && i < 4) { - tokens[i] = token; - i ++; - token = strtok(NULL, ","); - } - - addListener(listenerChain, atoi(tokens[0]), tokens[1], atoi(tokens[2]), atoi(tokens[3])); + if (file == NULL) { + printf("ça marche pas."); + return; + } + + while (fgets(line, sizeof(line), file)) { + int id = atoi(strtok(line, ",")); + char *name = strtok(NULL, ","); + int day = atoi(strtok(NULL, ",")); + int month = atoi(strtok(NULL, ",")); + addListener(listenerChain, id, name, day, month); } fclose(file); @@ -62,10 +51,8 @@ void readListeners(ptListener listenerChain) { void readRelations(ptConf confChain, ptListener listenerChain) { FILE *file = fopen("./data/relations", "r"); char line[100]; - char *tokens[50]; - char *token; - int i; - int j; + char *token1; + char *token2; if (file == NULL) { printf("ça marche pas."); @@ -73,22 +60,13 @@ void readRelations(ptConf confChain, ptListener listenerChain) { } while (fgets(line, sizeof(line), file)) { - token = strtok(line, ":"); - printf("%d\n", atoi(token)); + int confId = atoi(strtok(line, ":")); - i = 0; - - while (token != NULL) { - tokens[i] = token; - i ++; - token = strtok(NULL, ","); + while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) { + participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2)); } } - for (j = 1; j < i; j++) { - participateToConf(confChain, listenerChain, atoi(tokens[0]), atoi(tokens[j])); - } - fclose(file); } @@ -124,7 +102,7 @@ void saveRelations(ptConf confChain) { } while (py -> next != NULL) { - fprintf(file, "%d", py -> listener -> id); + fprintf(file, "%d;%d", py -> listener -> id, py -> grade); if (py -> next -> next != NULL) { fprintf(file, ","); } else { diff --git a/main.exe b/main.exe index 3fff024..396e74c 100644 Binary files a/main.exe and b/main.exe differ diff --git a/screenManager.c b/screenManager.c index 8d30915..9f45edd 100644 --- a/screenManager.c +++ b/screenManager.c @@ -83,10 +83,10 @@ void drawMenu(char *options[], int lenght) { } void menuConf(ptConf confChain, ptListener listenerChain) { - char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Suprimer une conference", "4/ Retour"}; + char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Suprimer une conference", "4/ Supprimer les conferences inferieures a une date", "5/ Retour"}; system("cls"); - drawMenu(options, 4); - goToCoords(0, 12); + drawMenu(options, 5); + goToCoords(0, 13); printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -94,21 +94,27 @@ void menuConf(ptConf confChain, ptListener listenerChain) { switch (choice) { case 1: - system ("cls"); + { ptConf px = confChain; while (px -> next != NULL) { - printf("id : %d\ntitle : %s\nspeaker : %s\n", px -> id, px -> title, px -> speaker); - printf("%d/%d/%d\n",px -> day, px -> month, px -> year); + printf("Id : %d\nTitre : %s\nConférencier : %s\n", px -> id, px -> title, px -> speaker); + printf("Date : %d/%d/%d\n",px -> day, px -> month, px -> year); + printf("Nombre de participants : %d\n", confParticipations(px)); if (px -> listeners -> next != NULL ) { printListenerList(px -> listeners); } + int avg; + if ((avg = confGradeAvg(px) != -1)) { + printf("Moyenne des notes : %d\n", confGradeAvg(px)); + } printf("\n"); px = px -> next; } system("pause"); menuConf(confChain, listenerChain); break; + } case 2: { @@ -148,6 +154,33 @@ void menuConf(ptConf confChain, ptListener listenerChain) { } case 4: + { + int day, month, year, time; + printf("Jour : "); + scanf("%d", &day); + printf("Mois : "); + scanf("%d", &month); + printf("Annee : "); + scanf("%d", &year); + + time = day + 31 * month * 365 * year; + + ptConf px = confChain; + + while(px -> next != NULL) { + if ((px -> day + px -> month * 31 + px -> year * 365) < time) { + ptConf py = px -> next; + removeConf(confChain, px -> id); + px = py; + } else { + px = px -> next; + } + } + + menuConf(confChain, listenerChain); + } + + case 5: menu(confChain, listenerChain); break; @@ -168,7 +201,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { switch (choice) { case 1: - system ("cls"); + { ptListener py = listenerChain; while (py -> next != NULL) { @@ -182,6 +215,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { system("pause"); menuAbo(confChain, listenerChain); break; + } case 2: { @@ -226,10 +260,10 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { void menu(ptConf confChain, ptListener listenerChain) { - char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Voir la participation a une conference", "6/ Quitter"}; + char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Quitter"}; system("cls"); - drawMenu(options, 6); - goToCoords(0, 14); + drawMenu(options, 5); + goToCoords(0, 13); printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -246,26 +280,46 @@ void menu(ptConf confChain, ptListener listenerChain) case 3: { - int confId, listenerId; + int confId, listenerId, grade; printf("Entrez l'ID de la conference : "); scanf("%d", &confId); printf("Entrez l'ID du participant : "); scanf("%d", &listenerId); + printf("Entrez la note attribuée par le participant : "); + scanf("%d", &grade); - participateToConf(confChain, listenerChain, confId, listenerId); + participateToConf(confChain, listenerChain, confId, listenerId, grade); saveRelations(confChain); menu(confChain, listenerChain); break; } case 4: + { + ptConf px = confChain; + int max = confGradeAvg(px); + ptConf confMax = px; + + while (px -> next != NULL) { + int tmp = confGradeAvg(px); + if (tmp > max) { + confMax = px; + max = tmp; + } + + px = px -> next; + } + + printf("La conférence la mieux notée est : %s\n\n", confMax -> title); + + system("pause"); + menu(confChain, listenerChain); + break; + } case 5: break; - - case 6: - break; default: break;