From c622a253ca9a0728ff94e29c57b3007987a1451e Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:01:01 +0100 Subject: [PATCH 01/10] commit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ee66f5d..ce55f05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ singleFile.c main.exe -.vscode/ \ No newline at end of file +.vscode/ +.dataBackup/ \ No newline at end of file From 0bf03582a89dfc84c264d5615e2669d9285f9106 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:01:56 +0100 Subject: [PATCH 02/10] commit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ce55f05..94c44fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ singleFile.c main.exe .vscode/ -.dataBackup/ \ No newline at end of file +dataBackup/ \ No newline at end of file From 30653d1955d9752efdf8791566b8d4d8c2fb308a Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:03:13 +0100 Subject: [PATCH 03/10] commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9af32b0..8e0bb66 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Ce projet a pour but de créer un système de gestion de conférences en C. ## Requis -- gcc sur windows (MinGW)[https://sourceforge.net/projects/mingw/] +- gcc sur windows avec MinGW[https://sourceforge.net/projects/mingw/] ## Installation From e62a8153181c2d59f34bd960f44022a0646cddaa Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:04:12 +0100 Subject: [PATCH 04/10] commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e0bb66..00a83f3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Ce projet a pour but de créer un système de gestion de conférences en C. ## Requis -- gcc sur windows avec MinGW[https://sourceforge.net/projects/mingw/] +- gcc sur windows avec [MinGW](https://sourceforge.net/projects/mingw/) ## Installation From 1c361b97e8eb8b40bdfa50b4cd553a44ca64eb15 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:04:34 +0100 Subject: [PATCH 05/10] commit --- dataBackup/confs | 12 ------------ dataBackup/listeners | 19 ------------------- dataBackup/relations | 6 ------ 3 files changed, 37 deletions(-) delete mode 100644 dataBackup/confs delete mode 100644 dataBackup/listeners delete mode 100644 dataBackup/relations diff --git a/dataBackup/confs b/dataBackup/confs deleted file mode 100644 index fa10f60..0000000 --- a/dataBackup/confs +++ /dev/null @@ -1,12 +0,0 @@ -1,Rapport_du_GIEC,Jean_Jouzzel,15,11,2022 -2,L_esprit_critique,Thomas_Durand,6,2,2023 -3,La_resilience,Arthur_Keller,20,10,2022 -4,American_lobbying,Salah_Oueslati,30,11,2023 -5,Crysper_case9_et_ADN,Peggy_Baron,18,10,2023 -6,Materiaux_de_demain,Emmanuel_Chirache,15,11,2023 -7,Les_IA,Matthieu_Maurer,1,6,2023 -8,Therories_du_complots,Jean_Benoit,1,4,2021 -9,Le_lacet_irlandais,Mick_Oconnell,31,3,2022 -10,Litterature_et_SF,Terry_Pratchett,15,5,2021 -11,Les_chaises_en_bois,David,24,12,2023 -12,cybersecurite_des_coquillages,Bob,6,2,2024 diff --git a/dataBackup/listeners b/dataBackup/listeners deleted file mode 100644 index d2f1a19..0000000 --- a/dataBackup/listeners +++ /dev/null @@ -1,19 +0,0 @@ -1,Simon,21,3 -3,Thomas,20,3 -4,Victor,19,2 -5,Lukian,19,2 -6,Natacha,18,1 -7,Caroline,22,4 -8,Lucas,23,4 -9,Clodine,64,3 -10,Kevin,26,3 -11,Titouan,18,1 -12,Louise,20,3 -13,Chayma,22,5 -14,Elisa,23,5 -15,Erwan,19,2 -18,Marion,17,1 -19,Tom,17,1 -20,Sebastien,45,5 -21,Jean,50,5 -22,Patrick,15,5 diff --git a/dataBackup/relations b/dataBackup/relations deleted file mode 100644 index 17d29d8..0000000 --- a/dataBackup/relations +++ /dev/null @@ -1,6 +0,0 @@ -1:12;0,1;4 -2:12;0,1;4 -3:12;0,1;4 -4:12;0,1;4 -9:20;5 -10:21;5 From df2be62fe22cd4b0bb6a646817a7189331726ca5 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:06:06 +0100 Subject: [PATCH 06/10] commit --- data/confs | 12 ------------ data/listeners | 19 ------------------- data/relations | 6 ------ 3 files changed, 37 deletions(-) diff --git a/data/confs b/data/confs index fa10f60..e69de29 100644 --- a/data/confs +++ b/data/confs @@ -1,12 +0,0 @@ -1,Rapport_du_GIEC,Jean_Jouzzel,15,11,2022 -2,L_esprit_critique,Thomas_Durand,6,2,2023 -3,La_resilience,Arthur_Keller,20,10,2022 -4,American_lobbying,Salah_Oueslati,30,11,2023 -5,Crysper_case9_et_ADN,Peggy_Baron,18,10,2023 -6,Materiaux_de_demain,Emmanuel_Chirache,15,11,2023 -7,Les_IA,Matthieu_Maurer,1,6,2023 -8,Therories_du_complots,Jean_Benoit,1,4,2021 -9,Le_lacet_irlandais,Mick_Oconnell,31,3,2022 -10,Litterature_et_SF,Terry_Pratchett,15,5,2021 -11,Les_chaises_en_bois,David,24,12,2023 -12,cybersecurite_des_coquillages,Bob,6,2,2024 diff --git a/data/listeners b/data/listeners index d2f1a19..e69de29 100644 --- a/data/listeners +++ b/data/listeners @@ -1,19 +0,0 @@ -1,Simon,21,3 -3,Thomas,20,3 -4,Victor,19,2 -5,Lukian,19,2 -6,Natacha,18,1 -7,Caroline,22,4 -8,Lucas,23,4 -9,Clodine,64,3 -10,Kevin,26,3 -11,Titouan,18,1 -12,Louise,20,3 -13,Chayma,22,5 -14,Elisa,23,5 -15,Erwan,19,2 -18,Marion,17,1 -19,Tom,17,1 -20,Sebastien,45,5 -21,Jean,50,5 -22,Patrick,15,5 diff --git a/data/relations b/data/relations index 17d29d8..e69de29 100644 --- a/data/relations +++ b/data/relations @@ -1,6 +0,0 @@ -1:12;0,1;4 -2:12;0,1;4 -3:12;0,1;4 -4:12;0,1;4 -9:20;5 -10:21;5 From e015c4a017fdd0a879c897642b1fe816143d899b Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 30 Nov 2023 17:07:25 +0100 Subject: [PATCH 07/10] commit --- conf.c | 398 ++++++++++++++++++++++++++++---------------------- conf.h | 38 ++--- fileManager.c | 105 +++++++------ 3 files changed, 307 insertions(+), 234 deletions(-) diff --git a/conf.c b/conf.c index 9278f44..96baeed 100644 --- a/conf.c +++ b/conf.c @@ -3,283 +3,331 @@ #include #include "conf.h" -int findConfId(ptConf confChain) { +int findConfId(ptConf confChain) +{ ptConf px = confChain; int max = 0; - while (px -> next != NULL) { - if (px -> id > max) { - max = px -> id; + while (px->next != NULL) + { + if (px->id > max) + { + max = px->id; } - - px = px -> next; + + px = px->next; } return max + 1; } -ptConf newConfChain() { - ptConf confChain = (ptConf) malloc(sizeof(tConf)); +ptConf newConfChain() +{ + ptConf confChain = (ptConf)malloc(sizeof(tConf)); - confChain -> next = (ptConf) malloc(sizeof(tConf)); - confChain -> next -> next = NULL; - confChain -> id = -1; + confChain->next = (ptConf)malloc(sizeof(tConf)); + confChain->next->next = NULL; + confChain->id = -1; return confChain; } -void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year) { +void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year) +{ ptConf px = confChain; - while (px -> next != NULL) { - px = px -> next; + while (px->next != NULL) + { + px = px->next; } - px -> id = id; - px -> day = day; - px -> month = month; - px -> year = year; - strcpy(px -> title, title); - strcpy(px -> speaker, speaker); - px -> listeners = (ptListenerList) malloc(sizeof(tListenerList)); - px -> listeners -> next = (ptListenerList) malloc(sizeof(tListenerList)); - px -> listeners -> listener = NULL; - px -> listeners -> next -> next = NULL; - px -> next = (ptConf) malloc(sizeof(tConf)); - px -> next -> next = NULL; + px->id = id; + px->day = day; + px->month = month; + px->year = year; + strcpy(px->title, title); + strcpy(px->speaker, speaker); + px->listeners = (ptListenerList)malloc(sizeof(tListenerList)); + px->listeners->next = (ptListenerList)malloc(sizeof(tListenerList)); + px->listeners->listener = NULL; + px->listeners->next->next = NULL; + px->next = (ptConf)malloc(sizeof(tConf)); + px->next->next = NULL; } -void removeConf(ptConf confChain, int id) { +void removeConf(ptConf confChain, int id) +{ ptConf px = confChain; - while (px -> next != NULL && px -> next -> id != id) { - px = px -> next; + while (px->next != NULL && px->next->id != id) + { + px = px->next; } - if (px -> next != NULL && px -> next -> id == id) { - ptListenerList py = px -> next -> listeners -> next; + if (px->next != NULL && px->next->id == id) + { + ptListenerList py = px->next->listeners->next; - while (py -> next != NULL) { - removeConfFromConfList(py -> listener -> confs, px -> next); - py = py -> next; + while (py->next != NULL) + { + removeConfFromConfList(py->listener->confs, px->next); + py = py->next; } - ptConf tmp = px -> next -> next; - free(px -> next); - px -> next = tmp; + ptConf tmp = px->next->next; + free(px->next); + px->next = tmp; } } -int findListenerId(ptListener listenerChain) { +int findListenerId(ptListener listenerChain) +{ ptListener px = listenerChain; int max = 0; - while (px -> next != NULL) { - if (px -> id > max) { - max = px -> id; + while (px->next != NULL) + { + if (px->id > max) + { + max = px->id; } - - px = px -> next; + + px = px->next; } return max + 1; } -ptListener newListenerChain() { - ptListener listenerChain = (ptListener) malloc(sizeof(tListener)); +ptListener newListenerChain() +{ + ptListener listenerChain = (ptListener)malloc(sizeof(tListener)); - listenerChain -> prev = NULL; - listenerChain -> next = (ptListener) malloc(sizeof(tListener)); - listenerChain -> next -> prev = listenerChain; - listenerChain -> next -> next = NULL; - listenerChain -> id = -1; + listenerChain->prev = NULL; + listenerChain->next = (ptListener)malloc(sizeof(tListener)); + listenerChain->next->prev = listenerChain; + listenerChain->next->next = NULL; + listenerChain->id = -1; return listenerChain; } -int addListener(ptListener listenerChain, int id, char name[], int age, int level) { - if (level < 0 || level > 5) { +int addListener(ptListener listenerChain, int id, char name[], int age, int level) +{ + if (level < 0 || level > 5) + { return -1; } ptListener px = listenerChain; - while (px -> next != NULL) { - px = px -> next; + while (px->next != NULL) + { + px = px->next; } - px -> id = id; - strcpy(px -> name, name); - px -> age = age; - px -> level = level; - px -> confs = (ptConfList) malloc(sizeof(tConfList)); - px -> confs -> next = (ptConfList) malloc(sizeof(tConfList)); - px -> confs -> conf = NULL; - px -> confs -> next -> next = NULL; - px -> next = (ptListener) malloc(sizeof(tListener)); - px -> next -> next = NULL; - px -> next -> prev = px; + px->id = id; + strcpy(px->name, name); + px->age = age; + px->level = level; + px->confs = (ptConfList)malloc(sizeof(tConfList)); + px->confs->next = (ptConfList)malloc(sizeof(tConfList)); + px->confs->conf = NULL; + px->confs->next->next = NULL; + px->next = (ptListener)malloc(sizeof(tListener)); + px->next->next = NULL; + px->next->prev = px; return 0; } -void removeListener(ptListener listenerChain, int id) { +void removeListener(ptListener listenerChain, int id) +{ ptListener px = listenerChain; - while (px -> next != NULL && px -> next -> id != id) { - px = px -> next; + while (px->next != NULL && px->next->id != id) + { + px = px->next; } - if (px -> next != NULL && px -> next -> id == id) { - ptConfList py = px -> next -> confs -> next; + if (px->next != NULL && px->next->id == id) + { + ptConfList py = px->next->confs->next; - while (py -> next != NULL) { - removeListenerFromListenerList(py -> conf -> listeners, px -> next); - py = py -> next; + while (py->next != NULL) + { + removeListenerFromListenerList(py->conf->listeners, px->next); + py = py->next; } - ptListener tmp = px -> next -> next; - free(px -> next); - px -> next = tmp; - px -> next -> prev = px; + ptListener tmp = px->next->next; + free(px->next); + px->next = tmp; + px->next->prev = px; } } -void addConfToConfList(ptConfList confList, ptConf conf, int grade) { - ptConfList px = confList; - - while (px -> next != NULL) { - px = px -> next; - } - - px -> conf = conf; - px -> next = (ptConfList) malloc(sizeof(tConfList)); - px -> grade = grade; - px -> next -> next = NULL; -} - -void removeConfFromConfList(ptConfList confList, ptConf conf) { +void addConfToConfList(ptConfList confList, ptConf conf, int grade) +{ ptConfList px = confList; - while (px -> next != NULL && px -> next -> conf != conf) { - px = px -> next; + while (px->next != NULL) + { + px = px->next; } - if (px -> next != NULL && px -> next -> conf == conf) { - ptConfList tmp = px -> next -> next; - free(px -> next); - px -> next = tmp; + px->conf = conf; + px->next = (ptConfList)malloc(sizeof(tConfList)); + px->grade = grade; + px->next->next = NULL; +} + +void removeConfFromConfList(ptConfList confList, ptConf conf) +{ + ptConfList px = confList; + + while (px->next != NULL && px->next->conf != conf) + { + px = px->next; + } + + if (px->next != NULL && px->next->conf == conf) + { + ptConfList tmp = px->next->next; + free(px->next); + px->next = tmp; } } -void printConfList(ptConfList confList) { - ptConfList px = confList; - - printf("Participation aux conferences : "); - while (px -> next != NULL) { - printf("%s(%d) ", px -> conf -> title, px -> grade); - px = px -> next; - } - printf("\n"); +void printConfList(ptConfList confList) +{ + ptConfList px = confList; + + printf("Participation aux conferences : "); + while (px->next != NULL) + { + printf("%s(%d) ", px->conf->title, px->grade); + px = px->next; + } + printf("\n"); } -void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) { - ptListenerList px = listenerList; - - while (px -> next != NULL) { - px = px -> next; - } - - px -> listener = listener; - px -> next = (ptListenerList) malloc(sizeof(tListenerList)); - px -> grade = grade; - px -> next -> next = NULL; -} - -void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) { +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) +{ ptListenerList px = listenerList; - while (px -> next != NULL && px -> next -> listener != listener) { - px = px -> next; + while (px->next != NULL) + { + px = px->next; } - if (px -> next != NULL && px -> next -> listener == listener) { - ptListenerList tmp = px -> next -> next; - free(px -> next); - px -> next = tmp; + px->listener = listener; + px->next = (ptListenerList)malloc(sizeof(tListenerList)); + px->grade = grade; + px->next->next = NULL; +} + +void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) +{ + ptListenerList px = listenerList; + + while (px->next != NULL && px->next->listener != listener) + { + px = px->next; + } + + if (px->next != NULL && px->next->listener == listener) + { + ptListenerList tmp = px->next->next; + free(px->next); + px->next = tmp; } } -void printListenerList(ptListenerList listenerList) { - ptListenerList px = listenerList; - - printf("Participants : "); - while (px -> next != NULL) { - printf("%s(%d) ", px -> listener -> name, px -> grade); - px = px -> next; - } - printf("\n"); +void printListenerList(ptListenerList listenerList) +{ + ptListenerList px = listenerList; + + printf("Participants : "); + while (px->next != NULL) + { + printf("%s(%d) ", px->listener->name, px->grade); + px = px->next; + } + printf("\n"); } -int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) { - if (grade < 0 || grade > 5) { +int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) +{ + if (grade < 0 || grade > 5) + { return -1; } - ptConf px = confChain; - ptListener py = listenerChain; - ptListenerList pz; - - while (px -> next != NULL && px -> id != confId) { - px = px -> next; - } - - pz = px -> listeners -> next; - while (pz -> next != NULL) { - if (pz -> listener -> id == listenerId) { - return -2; - } - pz = pz -> next; - } - - while (py -> next != NULL && py -> id != listenerId) { - py = py -> next; - } - - if (px -> id != confId || py -> id != listenerId) { - return -2; - } - - addListenerToListenerList(px -> listeners, py, grade); - addConfToConfList(py -> confs, px, grade); + ptConf px = confChain; + ptListener py = listenerChain; + ptListenerList pz; + + while (px->next != NULL && px->id != confId) + { + px = px->next; + } + + pz = px->listeners->next; + while (pz->next != NULL) + { + if (pz->listener->id == listenerId) + { + return -2; + } + pz = pz->next; + } + + while (py->next != NULL && py->id != listenerId) + { + py = py->next; + } + + if (px->id != confId || py->id != listenerId) + { + return -2; + } + + addListenerToListenerList(px->listeners, py, grade); + addConfToConfList(py->confs, px, grade); return 0; } -int confGradeAvg(ptConf conf) { - ptListenerList px = conf -> listeners -> next; +int confGradeAvg(ptConf conf) +{ + ptListenerList px = conf->listeners->next; int total = 0, nb = 0; - while (px -> next != NULL) { - total += px -> grade; + while (px->next != NULL) + { + total += px->grade; nb++; - px = px -> next; + px = px->next; } - if (nb != 0) { + if (nb != 0) + { return total / nb; - } else { + } + else + { return -1; } - } -int confParticipations(ptConf conf) { - ptListenerList px = conf -> listeners -> next; +int confParticipations(ptConf conf) +{ + ptListenerList px = conf->listeners->next; int nb = 0; - while (px -> next != NULL) { + while (px->next != NULL) + { nb++; - px = px -> next; + px = px->next; } return nb; diff --git a/conf.h b/conf.h index 6898a2b..98a2765 100644 --- a/conf.h +++ b/conf.h @@ -3,43 +3,47 @@ struct listenerList; -typedef struct conf { +typedef struct conf +{ int id; char title[30]; char speaker[20]; int day; int month; int year; - struct listenerList* listeners; - struct conf* next; + struct listenerList *listeners; + struct conf *next; } tConf; -typedef struct confList { - struct conf* conf; +typedef struct confList +{ + struct conf *conf; int grade; - struct confList* next; + struct confList *next; } tConfList; -typedef struct listener { +typedef struct listener +{ int id; char name[20]; int age; int level; - struct confList* confs; - struct listener* prev; - struct listener* next; + struct confList *confs; + struct listener *prev; + struct listener *next; } tListener; -typedef struct listenerList { - struct listener* listener; +typedef struct listenerList +{ + struct listener *listener; int grade; - struct listenerList* next; + struct listenerList *next; } tListenerList; -typedef tConf* ptConf; -typedef tListener* ptListener; -typedef tConfList* ptConfList; -typedef tListenerList* ptListenerList; +typedef tConf *ptConf; +typedef tListener *ptListener; +typedef tConfList *ptConfList; +typedef tListenerList *ptListenerList; int findConfId(ptConf confChain); ptConf newConfChain(); diff --git a/fileManager.c b/fileManager.c index 6c81bec..c4a1449 100644 --- a/fileManager.c +++ b/fileManager.c @@ -3,17 +3,20 @@ #include #include "conf.h" -void readConfs(ptConf confChain) { +void readConfs(ptConf confChain) +{ FILE *file = fopen("./data/confs", "r"); char line[100]; char *token; - if (file == NULL) { + if (file == NULL) + { printf("ça marche pas."); return; } - while (fgets(line, sizeof(line), file)) { + while (fgets(line, sizeof(line), file)) + { int id = atoi(strtok(line, ",")); char *title = strtok(NULL, ","); char *speaker = strtok(NULL, ","); @@ -27,17 +30,20 @@ void readConfs(ptConf confChain) { fclose(file); } -void readListeners(ptListener listenerChain) { +void readListeners(ptListener listenerChain) +{ FILE *file = fopen("./data/listeners", "r"); char line[100]; char *token; - if (file == NULL) { + if (file == NULL) + { printf("ça marche pas."); return; } - while (fgets(line, sizeof(line), file)) { + while (fgets(line, sizeof(line), file)) + { int id = atoi(strtok(line, ",")); char *name = strtok(NULL, ","); int day = atoi(strtok(NULL, ",")); @@ -48,21 +54,25 @@ void readListeners(ptListener listenerChain) { fclose(file); } -void readRelations(ptConf confChain, ptListener listenerChain) { - FILE *file = fopen("./data/relations", "r"); - char line[100]; - char *token1; +void readRelations(ptConf confChain, ptListener listenerChain) +{ + FILE *file = fopen("./data/relations", "r"); + char line[100]; + char *token1; char *token2; - - if (file == NULL) { - printf("ça marche pas."); - return; - } - - while (fgets(line, sizeof(line), file)) { + + if (file == NULL) + { + printf("ça marche pas."); + return; + } + + while (fgets(line, sizeof(line), file)) + { int confId = atoi(strtok(line, ":")); - while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) { + while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) + { participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2)); } } @@ -70,50 +80,61 @@ void readRelations(ptConf confChain, ptListener listenerChain) { fclose(file); } -void saveConf(ptConf confChain) { +void saveConf(ptConf confChain) +{ FILE *file = fopen("./data/confs", "w"); ptConf px = confChain; - while(px -> next != NULL){ - fprintf(file,"%d,%s,%s,%d,%d,%d\n",px -> id,px -> title,px -> speaker,px -> day,px -> month,px -> year); - px = px -> next; + while (px->next != NULL) + { + fprintf(file, "%d,%s,%s,%d,%d,%d\n", px->id, px->title, px->speaker, px->day, px->month, px->year); + px = px->next; } fclose(file); } -void saveListeners(ptListener listenerChain) { +void saveListeners(ptListener listenerChain) +{ FILE *file = fopen("./data/listeners", "w"); ptListener px = listenerChain; - while(px -> next != NULL){ - fprintf(file,"%d,%s,%d,%d\n",px -> id,px -> name,px -> age,px -> level); - px = px -> next; + while (px->next != NULL) + { + fprintf(file, "%d,%s,%d,%d\n", px->id, px->name, px->age, px->level); + px = px->next; } fclose(file); } -void saveRelations(ptConf confChain) { +void saveRelations(ptConf confChain) +{ FILE *file = fopen("./data/relations", "w"); ptConf px = confChain; ptListenerList py; printf("test"); - while(px -> next != NULL){ + while (px->next != NULL) + { printf("test"); - py = px -> listeners -> next; + py = px->listeners->next; - if (py -> next != NULL) { - fprintf(file, "%d:", px -> id); - } - - while (py -> next != NULL) { - fprintf(file, "%d;%d", py -> listener -> id, py -> grade); - if (py -> next -> next != NULL) { - fprintf(file, ","); - } else { - fprintf(file, "\n"); - } - py = py -> next; + if (py->next != NULL) + { + fprintf(file, "%d:", px->id); } - px = px -> next; + while (py->next != NULL) + { + fprintf(file, "%d;%d", py->listener->id, py->grade); + if (py->next->next != NULL) + { + fprintf(file, ","); + } + else + { + fprintf(file, "\n"); + } + py = py->next; + } + + px = px->next; } fclose(file); } \ No newline at end of file From 6d363c7becf68b3076dd6da038119f9886db311a Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Wed, 6 Dec 2023 19:22:05 +0100 Subject: [PATCH 08/10] commit --- .gitignore | 1 - singleFile.c | 1192 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1192 insertions(+), 1 deletion(-) create mode 100644 singleFile.c diff --git a/.gitignore b/.gitignore index 94c44fe..d5417f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -singleFile.c main.exe .vscode/ dataBackup/ \ No newline at end of file diff --git a/singleFile.c b/singleFile.c new file mode 100644 index 0000000..e577f60 --- /dev/null +++ b/singleFile.c @@ -0,0 +1,1192 @@ +//+--------------------------------------------------------------------------------+ +//| | +//| Ce projet réalisé par Victor PASGRIMAUD et Lukian LEIZOUR avant le 01/12/2023. | +//| Il permet de stocker des conférences ainsi que des abonnés qui y participent. | +//| | +//+--------------------------------------------------------------------------------+ + +#include +#include +#include +#include + +//+----------------------------------------+ +//| Conf management | +//+----------------------------------------+ + +struct listenerList; + +//Structure permettant de stocker les conférences, le champs listeners correspond à une liste de pointeurs d'abonnés. + +typedef struct conf +{ + int id; + char title[30]; + char speaker[20]; + int day; + int month; + int year; + struct listenerList *listeners; + struct conf *next; +} tConf; + +typedef struct confList +{ + struct conf *conf; + int grade; + struct confList *next; +} tConfList; + +//Structure permettant de stocker les abonnés, le champs confs correspond à une liste de pointeurs de conférences. + +typedef struct listener +{ + int id; + char name[20]; + int age; + int level; + struct confList *confs; + struct listener *prev; + struct listener *next; +} tListener; + +typedef struct listenerList +{ + struct listener *listener; + int grade; + struct listenerList *next; +} tListenerList; + +typedef tConf *ptConf; +typedef tListener *ptListener; +typedef tConfList *ptConfList; +typedef tListenerList *ptListenerList; + +int findConfId(ptConf confChain); +ptConf newConfChain(); +void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year); +void removeConf(ptConf confChain, int id); +int findListenerId(ptListener listenerChain); +ptListener newListenerChain(); +int addListener(ptListener listenerChain, int id, char name[], int age, int level); +void removeListener(ptListener listenerChain, int id); +void addConfToConfList(ptConfList confList, ptConf conf, int grade); +void removeConfFromConfList(ptConfList confList, ptConf conf); +void printConfList(ptConfList confList); +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); +void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener); +void printListenerList(ptListenerList listenerList); +int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); +int confGradeAvg(ptConf conf); +int confParticipations(ptConf conf); + +//fonction permettant de trouver un id de conférence libre. + +int findConfId(ptConf confChain) +{ + ptConf px = confChain; + int max = 0; + + while (px->next != NULL) + { + if (px->id > max) + { + max = px->id; + } + + px = px->next; + } + + return max + 1; +} + +//fonction permettant de créer une liste de conférences vide. +//nous ajoutons un élément vide afin de grandement décomplexifier la suppression de conférences. + +ptConf newConfChain() +{ + ptConf confChain = (ptConf)malloc(sizeof(tConf)); + + confChain->next = (ptConf)malloc(sizeof(tConf)); + confChain->next->next = NULL; + confChain->id = -1; + + return confChain; +} + +//fonction permettant d'ajouter une conférence à une liste de conférences. + +void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year) +{ + ptConf px = confChain; + + while (px->next != NULL) + { + px = px->next; + } + + px->id = id; + px->day = day; + px->month = month; + px->year = year; + strcpy(px->title, title); + strcpy(px->speaker, speaker); + px->listeners = (ptListenerList)malloc(sizeof(tListenerList)); + px->listeners->next = (ptListenerList)malloc(sizeof(tListenerList)); + px->listeners->listener = NULL; + px->listeners->next->next = NULL; + px->next = (ptConf)malloc(sizeof(tConf)); + px->next->next = NULL; +} + +//fonction permettant de supprimer une conférence d'une liste de conférences. + +void removeConf(ptConf confChain, int id) +{ + //on recherche la conférence à supprimer. + + ptConf px = confChain; + + while (px->next != NULL && px->next->id != id) + { + px = px->next; + } + + if (px->next != NULL && px->next->id == id) + { + //on supprime la conférence de tous les abonnés qui y ont participé. + + ptListenerList py = px->next->listeners->next; + + while (py->next != NULL) + { + removeConfFromConfList(py->listener->confs, px->next); + py = py->next; + } + + //on supprime la conférence de la liste de conférences. + + ptConf tmp = px->next->next; + free(px->next); + px->next = tmp; + } +} + +//fonction permettant de trouver un id d'abonné libre. + +int findListenerId(ptListener listenerChain) +{ + ptListener px = listenerChain; + int max = 0; + + while (px->next != NULL) + { + if (px->id > max) + { + max = px->id; + } + + px = px->next; + } + + return max + 1; +} + +//fonction permettant de créer une liste d'abonnés vide. +//nous ajoutons un élément vide afin de grandement décomplexifier la suppression d'abonnés. + +ptListener newListenerChain() +{ + ptListener listenerChain = (ptListener)malloc(sizeof(tListener)); + + listenerChain->prev = NULL; + listenerChain->next = (ptListener)malloc(sizeof(tListener)); + listenerChain->next->prev = listenerChain; + listenerChain->next->next = NULL; + listenerChain->id = -1; + + return listenerChain; +} + +//fonction permettant d'ajouter un abonné à une liste d'abonnés. + +int addListener(ptListener listenerChain, int id, char name[], int age, int level) +{ + if (level < 0 || level > 5) + { + return -1; + } + + ptListener px = listenerChain; + + while (px->next != NULL) + { + px = px->next; + } + + px->id = id; + strcpy(px->name, name); + px->age = age; + px->level = level; + px->confs = (ptConfList)malloc(sizeof(tConfList)); + px->confs->next = (ptConfList)malloc(sizeof(tConfList)); + px->confs->conf = NULL; + px->confs->next->next = NULL; + px->next = (ptListener)malloc(sizeof(tListener)); + px->next->next = NULL; + px->next->prev = px; + return 0; +} + +//fonction permettant de supprimer un abonné d'une liste d'abonnés. + +void removeListener(ptListener listenerChain, int id) +{ + //on recherche l'abonné à supprimer. + + ptListener px = listenerChain; + + while (px->next != NULL && px->next->id != id) + { + px = px->next; + } + + if (px->next != NULL && px->next->id == id) + { + //on supprime l'abonné de toutes les conférences auxquelles il a participé. + + ptConfList py = px->next->confs->next; + + while (py->next != NULL) + { + removeListenerFromListenerList(py->conf->listeners, px->next); + py = py->next; + } + + //on supprime l'abonné de la liste d'abonnés. + + ptListener tmp = px->next->next; + free(px->next); + px->next = tmp; + px->next->prev = px; + } +} + +//fonction permettant d'ajouter une conférence à une liste de conférences. + +void addConfToConfList(ptConfList confList, ptConf conf, int grade) +{ + ptConfList px = confList; + + while (px->next != NULL) + { + px = px->next; + } + + px->conf = conf; + px->next = (ptConfList)malloc(sizeof(tConfList)); + px->grade = grade; + px->next->next = NULL; +} + +//fonction permettant de supprimer une conférence d'une liste de conférences. + +void removeConfFromConfList(ptConfList confList, ptConf conf) +{ + ptConfList px = confList; + + while (px->next != NULL && px->next->conf != conf) + { + px = px->next; + } + + if (px->next != NULL && px->next->conf == conf) + { + ptConfList tmp = px->next->next; + free(px->next); + px->next = tmp; + } +} + +//fonction permettant d'afficher une liste de conférences. + +void printConfList(ptConfList confList) +{ + ptConfList px = confList; + + printf("Participation aux conferences : "); + while (px->next != NULL) + { + printf("%s(%d) ", px->conf->title, px->grade); + px = px->next; + } + printf("\n"); +} + +//fonction permettant d'ajouter un abonné à une liste d'abonnés. + +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) +{ + ptListenerList px = listenerList; + + while (px->next != NULL) + { + px = px->next; + } + + px->listener = listener; + px->next = (ptListenerList)malloc(sizeof(tListenerList)); + px->grade = grade; + px->next->next = NULL; +} + +//fonction permettant de supprimer un abonné d'une liste d'abonnés. + +void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) +{ + ptListenerList px = listenerList; + + while (px->next != NULL && px->next->listener != listener) + { + px = px->next; + } + + if (px->next != NULL && px->next->listener == listener) + { + ptListenerList tmp = px->next->next; + free(px->next); + px->next = tmp; + } +} + +//fonction permettant d'afficher une liste d'abonnés. + +void printListenerList(ptListenerList listenerList) +{ + ptListenerList px = listenerList; + + printf("Participants : "); + while (px->next != NULL) + { + printf("%s(%d) ", px->listener->name, px->grade); + px = px->next; + } + printf("\n"); +} + +//fonction permettant à un abonné de participer à une conférence. + +int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) +{ + //on vérifie que la note est comprise entre 0 et 5 et que l'abonné n'a pas déjà participé à la conférence. + + if (grade < 0 || grade > 5) + { + return -1; + } + + ptConf px = confChain; + ptListener py = listenerChain; + ptListenerList pz; + + while (px->next != NULL && px->id != confId) + { + px = px->next; + } + + pz = px->listeners->next; + while (pz->next != NULL) + { + if (pz->listener->id == listenerId) + { + return -2; + } + pz = pz->next; + } + + while (py->next != NULL && py->id != listenerId) + { + py = py->next; + } + + if (px->id != confId || py->id != listenerId) + { + return -2; + } + + //on ajoute la conférence à la liste de conférences de l'abonné et l'abonné à la liste d'abonnés de la conférence. + + addListenerToListenerList(px->listeners, py, grade); + addConfToConfList(py->confs, px, grade); + + return 0; +} + +//fonction permettant de calculer la moyenne des notes d'une conférence. + +int confGradeAvg(ptConf conf) +{ + ptListenerList px = conf->listeners->next; + 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; + } +} + +//fonction permettant de calculer le nombre de participants à une conférence. + +int confParticipations(ptConf conf) +{ + ptListenerList px = conf->listeners->next; + int nb = 0; + + while (px->next != NULL) + { + nb++; + px = px->next; + } + + return nb; +} + +//+----------------------------------------+ +//| Files management | +//+----------------------------------------+ + +void readConfs(ptConf confChain); +void readListeners(ptListener listenerChain); +void readRelations(ptConf confChain, ptListener listenerChain); +void saveConf(ptConf confChain); +void saveListeners(ptListener listenerChain); +void saveRelations(ptConf confChain); + +//fonction permettant de lire les conférences dans le fichier ./data/confs. + +void readConfs(ptConf confChain) +{ + //on ouvre le fichier ./data/confs. + + FILE *file = fopen("./data/confs", "r"); + char line[100]; + char *token; + + //on vérifie que le fichier a bien été ouvert. + + if (file == NULL) + { + printf("ça marche pas."); + return; + } + + //on lit le fichier ligne par ligne et on ajoute les conférences à la liste de conférences. + + 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); + } + + //on ferme le fichier. + + fclose(file); +} + +//fonction permettant de lire les abonnés dans le fichier ./data/listeners. + +void readListeners(ptListener listenerChain) +{ + //on ouvre le fichier ./data/listeners. + + FILE *file = fopen("./data/listeners", "r"); + char line[100]; + char *token; + + //on vérifie que le fichier a bien été ouvert. + + if (file == NULL) + { + printf("ça marche pas."); + return; + } + + //on lit le fichier ligne par ligne et on ajoute les abonnés à la liste d'abonnés. + + 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); + } + + //on ferme le fichier. + + fclose(file); +} + +//fonction permettant de lire les relations entre conférences et abonnés dans le fichier ./data/relations. + +void readRelations(ptConf confChain, ptListener listenerChain) +{ + //on ouvre le fichier ./data/relations. + + FILE *file = fopen("./data/relations", "r"); + char line[100]; + char *token1; + char *token2; + + //on vérifie que le fichier a bien été ouvert. + + if (file == NULL) + { + printf("ça marche pas."); + return; + } + + //on lit le fichier ligne par ligne et on ajoute les relations entre conférences et abonnés. + + while (fgets(line, sizeof(line), file)) + { + int confId = atoi(strtok(line, ":")); + + while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) + { + participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2)); + } + } + + //on ferme le fichier. + + fclose(file); +} + +//fonction permettant d'écrire les conférences dans le fichier ./data/confs. + +void saveConf(ptConf confChain) +{ + //on ouvre le fichier ./data/confs. + + FILE *file = fopen("./data/confs", "w"); + ptConf px = confChain; + + //on écrit les conférences dans le fichier. + + while (px->next != NULL) + { + fprintf(file, "%d,%s,%s,%d,%d,%d\n", px->id, px->title, px->speaker, px->day, px->month, px->year); + px = px->next; + } + + //on ferme le fichier. + + fclose(file); +} + +//fonction permettant d'écrire les abonnés dans le fichier ./data/listeners. + +void saveListeners(ptListener listenerChain) +{ + //on ouvre le fichier ./data/listeners. + + FILE *file = fopen("./data/listeners", "w"); + ptListener px = listenerChain; + + //on écrit les abonnés dans le fichier. + + while (px->next != NULL) + { + fprintf(file, "%d,%s,%d,%d\n", px->id, px->name, px->age, px->level); + px = px->next; + } + + //on ferme le fichier. + + fclose(file); +} + +//fonction permettant d'écrire les relations entre conférences et abonnés dans le fichier ./data/relations. + +void saveRelations(ptConf confChain) +{ + //on ouvre le fichier ./data/relations. + + FILE *file = fopen("./data/relations", "w"); + ptConf px = confChain; + ptListenerList py; + printf("test"); + + //on écrit les relations entre conférences et abonnés dans le fichier. + + while (px->next != NULL) + { + printf("test"); + py = px->listeners->next; + + if (py->next != NULL) + { + fprintf(file, "%d:", px->id); + } + + while (py->next != NULL) + { + fprintf(file, "%d;%d", py->listener->id, py->grade); + if (py->next->next != NULL) + { + fprintf(file, ","); + } + else + { + fprintf(file, "\n"); + } + py = py->next; + } + + px = px->next; + } + + //on ferme le fichier. + + fclose(file); +} + +//+----------------------------------------+ +//| Screen manager | +//+----------------------------------------+ + +void goToCoords(int x, int y); +void drawHoryLine(char c, int lenght); +void drawVertiLine(char c, int lenght); +void drawRectangle(int x, int y, int lenght, int height); +void drawMenu(char *options[], int lenght); +void tasse(); +void menuConf(ptConf confChain, ptListener listenerChain); +void menuAbo(ptConf confChain, ptListener listenerChain); +void menu(ptConf confChain, ptListener listenerChain); + +//fonction permettant de déplacer le curseur à des coordonnées données. + +void goToCoords(int x, int y) +{ + COORD coords; + + coords.X = x; + coords.Y = y; + + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coords); +} + +//fonction permettant de dessiner une ligne horizontale dans la console. + +void drawHoryLine(char c, int lenght) +{ + int i = 0; + + while (i != lenght) + { + printf("%c", c); + i++; + } +} + +//fonction permettant de dessiner une ligne verticale dans la console. + +void drawVertiLine(char c, int lenght) +{ + CONSOLE_SCREEN_BUFFER_INFO info; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); + int x = info.dwCursorPosition.X; + int y = info.dwCursorPosition.Y; + + int i = 0; + + while (i != lenght) + { + goToCoords(x, y + i); + printf("%c", c); + i++; + } +} + +//fonction permettant de dessiner un rectangle à partir d'un point de départ, d'une longueur et d'une hauteur. + +void drawRectangle(int x, int y, int lenght, int height) +{ + goToCoords(x, y); + printf("%c", 201); + drawHoryLine(205, lenght - 2); + printf("%c", 187); + goToCoords(x, y + 1); + drawVertiLine(186, height - 2); + goToCoords(x + lenght - 1, y + 1); + drawVertiLine(186, height - 2); + goToCoords(x, y + height - 1); + printf("%c", 200); + drawHoryLine(205, lenght - 2); + printf("%c", 188); +} + +//fonction permettant de dessiner un menu à partir d'un tableau de chaînes de caractères. + +void drawMenu(char *options[], int lenght) +{ + //on calcule la longueur de la chaîne la plus longue. + + int max = strlen(options[0]); + int i; + + for (i = 0; i < lenght; i++) + { + if (strlen(options[i]) > max) + { + max = strlen(options[i]); + } + } + + //on récupère la taille de la console. + + CONSOLE_SCREEN_BUFFER_INFO info; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); + int columns = info.srWindow.Right - info.srWindow.Left + 1; + int rows = info.srWindow.Bottom - info.srWindow.Top + 1; + + //on dessine le rectangle. + + drawRectangle((columns - max - 4) / 2, 2, max + 4, lenght + 4); + + //on écrit les options. + + for (i = 0; i < lenght; i++) + { + goToCoords((columns - max - 4) / 2 + 2, 4 + i); + printf("%s", options[i]); + } +} + +//+---------------------------+ +//| | +//| ( ) ( ) ) | +//| ) ( ) ( ( | +//| ( ) ( ) ) | +//| _____________ | +//| <_____________> ___ | +//| | |/ _ \ | +//| | | | | | +//| | |_| | | +//| ___| |\___/ | +//| / \___________/ \ | +//| \_____________________/ | +//| | +//+---------------------------+ + +//fonction permettant d'afficher un tasse. + +void tasse() +{ + printf(" ( ) ( ) )\n ) ( ) ( (\n ( ) ( ) )\n _____________\n <_____________> ___\n | |/ _ \\\n | | | |\n | |_| |\n ___| |\\___/\n/ \\___________/ \\\n\\_____________________/\n"); +} + +//fonction permettant d'afficher le menu des conférences. + +void menuConf(ptConf confChain, ptListener listenerChain) +{ + //on affiche le menu. + + char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Supprimer une conference", "4/ Supprimer les conferences inferieures a une date", "5/ Retour"}; + system("cls"); + drawMenu(options, 5); + goToCoords(0, 13); + tasse(); + printf("\n"); + + //on récupère le choix de l'utilisateur. + + printf("Que voulez-vous faire ? : "); + int choice; + scanf("%d", &choice); + + //on effectue l'action correspondante. + + switch (choice) + { + case 1: //on affiche la liste des conférences. + { + ptConf px = confChain->next; + + while (px->next != NULL) + { + printf("Id : %d\nTitre : %s\nConferencier : %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->next != NULL) + { + printListenerList(px->listeners->next); + } + 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: //on ajoute une conférence. + { + int id, day, month, year; + char title[30]; + char speaker[20]; + + id = findConfId(confChain); + printf("Titre de la conference : "); + scanf("%29s", &title); + printf("Nom du conferencier : "); + scanf("%19s", &speaker); + printf("Jour : "); + scanf("%d", &day); + printf("Mois : "); + scanf("%d", &month); + printf("Annee : "); + scanf("%d", &year); + + addConf(confChain, id, title, speaker, day, month, year); + saveConf(confChain->next); + menuConf(confChain, listenerChain); + break; + } + + case 3: //on supprime une conférence. + { + ptConf px = confChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%d : %s\n", px->id, px->title); + px = px->next; + } + printf("\n"); + + int id; + + printf("Id de la conference a supprimer : "); + scanf("%d", &id); + + removeConf(confChain, id); + saveConf(confChain->next); + saveRelations(confChain->next); + menuConf(confChain, listenerChain); + break; + } + + case 4: //on supprime les conférences inférieures à une date. + { + ptConf px = confChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%s : %d/%d/%d\n", px->title, px->day, px->month, px->year); + px = px->next; + } + printf("\n"); + + 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; + + px = confChain; + + while (px->next != NULL) + { + if ((px->day + px->month * 31 + px->year * 365) < time && px != confChain) + { + ptConf py = px->next; + removeConf(confChain, px->id); + px = py; + } + else if ((px->day + px->month * 31 + px->year * 365) < time && px == confChain) + { + removeConf(confChain, px->id); + } + else + { + px = px->next; + } + } + + saveConf(confChain->next); + saveRelations(confChain->next); + menuConf(confChain, listenerChain); + } + + case 5: //on retourne au menu principal. + menu(confChain, listenerChain); + break; + + default: + break; + } +} + +//fonction permettant d'afficher le menu des abonnés. + +void menuAbo(ptConf confChain, ptListener listenerChain) +{ + //on affiche le menu. + + char *options[] = {"1/ Voir la liste des abonnes", "2/ Ajouter un abonne", "3/ Suprimer un abonne", "4/ Retour"}; + system("cls"); + drawMenu(options, 4); + goToCoords(0, 12); + tasse(); + printf("\n"); + + //on récupère le choix de l'utilisateur. + + printf("Que voulez-vous faire ? : "); + int choice; + scanf("%d", &choice); + + //on effectue l'action correspondante. + + switch (choice) + { + case 1: //on affiche la liste des abonnés. + { + ptListener py = listenerChain->next; + + while (py->next != NULL) + { + printf("Id : %d\nNom: %s\nAge: %d\nNiveau: %d\n", py->id, py->name, py->age, py->level); + if (py->confs->next->next != NULL) + { + printConfList(py->confs->next); + } + printf("\n"); + py = py->next; + } + system("pause"); + menuAbo(confChain, listenerChain); + break; + } + + case 2: //on ajoute un abonné. + { + int id, age, level; + char name[20]; + + id = findListenerId(listenerChain); + printf("Nom : "); + scanf("%19s", &name); + printf("Age : "); + scanf("%d", &age); + printf("Niveau : "); + scanf("%d", &level); + + if (addListener(listenerChain, id, name, age, level) != -1) + { + saveListeners(listenerChain->next); + } + else + { + printf("Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n"); + system("pause"); + } + menuAbo(confChain, listenerChain); + break; + } + + case 3: //on supprime un abonné. + { + ptListener px = listenerChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%d : %s\n", px->id, px->name); + px = px->next; + } + printf("\n"); + + int id; + + printf("Id de l'abonne a supprimer : "); + scanf("%d", &id); + + removeListener(listenerChain, id); + saveListeners(listenerChain->next); + saveRelations(confChain->next); + menuAbo(confChain, listenerChain); + break; + } + + case 4: //on retourne au menu principal. + menu(confChain, listenerChain); + break; + + default: + break; + } +} + +//fonction permettant d'afficher le menu principal. + +void menu(ptConf confChain, ptListener listenerChain) +{ + //on affiche le menu. + + 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, 5); + goToCoords(0, 13); + tasse(); + printf("\n"); + + //on récupère le choix de l'utilisateur. + + printf("Que voulez-vous faire ? : "); + int choice; + scanf("%d", &choice); + + //on effectue l'action correspondante. + + switch (choice) + { + case 1: //on affiche le menu des conférences. + menuConf(confChain, listenerChain); + break; + + case 2: //on affiche le menu des abonnés. + menuAbo(confChain, listenerChain); + break; + + case 3: //on permet à un abonné de participer à une conférence. + { + ptConf px = confChain->next; + ptListener py = listenerChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%d : %s\n", px->id, px->title); + px = px->next; + } + printf("\n"); + while (py->next != NULL) + { + printf("%d : %s\n", py->id, py->name); + py = py->next; + } + printf("\n"); + + 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 attribuee par le participant : "); + scanf("%d", &grade); + + if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) + { + saveRelations(confChain->next); + } + else + { + printf("La note doit etre comprise entre 0 et 5 et l'abonne ne doit pas avoir deja participe a la conference\n\n"); + system("pause"); + } + + menu(confChain, listenerChain); + break; + } + + case 4: //on affiche la meilleure conférence. + { + ptConf px = confChain -> next; + 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 conference la mieux notee est : %s\n\n", confMax->title); + + system("pause"); + menu(confChain, listenerChain); + + break; + } + + case 5: //on quitte le programme. + break; + + default: + break; + } +} + +//+----------------------------------------+ +//| Main function | +//+----------------------------------------+ + +//fonction main. + +int main() +{ + //on initialise les listes de conférences et d'abonnés. + + ptConf confChain = newConfChain(); + ptListener listenerChain = newListenerChain(); + + //on lit les fichiers de données. + + readConfs(confChain); + readListeners(listenerChain); + readRelations(confChain, listenerChain); + + //on affiche le menu principal. + + menu(confChain, listenerChain); + + return 0; +} \ No newline at end of file From a13db7946f90ba7ad923c2c10883b482bfd8f752 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Wed, 6 Dec 2023 20:33:15 +0100 Subject: [PATCH 09/10] commit --- singleFile.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/singleFile.c b/singleFile.c index e577f60..a3731ce 100644 --- a/singleFile.c +++ b/singleFile.c @@ -481,8 +481,6 @@ void readConfs(ptConf confChain) FILE *file = fopen("./data/confs", "r"); char line[100]; - char *token; - //on vérifie que le fichier a bien été ouvert. if (file == NULL) @@ -518,7 +516,6 @@ void readListeners(ptListener listenerChain) FILE *file = fopen("./data/listeners", "r"); char line[100]; - char *token; //on vérifie que le fichier a bien été ouvert. From 9268c43abc9a1facb8ad6a71ca7302022707662a Mon Sep 17 00:00:00 2001 From: Lukian Date: Sat, 30 Nov 2024 18:41:13 +0100 Subject: [PATCH 10/10] Saataa andagii ! --- singleFile.c | 1189 -------------------------------------------------- 1 file changed, 1189 deletions(-) delete mode 100644 singleFile.c diff --git a/singleFile.c b/singleFile.c deleted file mode 100644 index a3731ce..0000000 --- a/singleFile.c +++ /dev/null @@ -1,1189 +0,0 @@ -//+--------------------------------------------------------------------------------+ -//| | -//| Ce projet réalisé par Victor PASGRIMAUD et Lukian LEIZOUR avant le 01/12/2023. | -//| Il permet de stocker des conférences ainsi que des abonnés qui y participent. | -//| | -//+--------------------------------------------------------------------------------+ - -#include -#include -#include -#include - -//+----------------------------------------+ -//| Conf management | -//+----------------------------------------+ - -struct listenerList; - -//Structure permettant de stocker les conférences, le champs listeners correspond à une liste de pointeurs d'abonnés. - -typedef struct conf -{ - int id; - char title[30]; - char speaker[20]; - int day; - int month; - int year; - struct listenerList *listeners; - struct conf *next; -} tConf; - -typedef struct confList -{ - struct conf *conf; - int grade; - struct confList *next; -} tConfList; - -//Structure permettant de stocker les abonnés, le champs confs correspond à une liste de pointeurs de conférences. - -typedef struct listener -{ - int id; - char name[20]; - int age; - int level; - struct confList *confs; - struct listener *prev; - struct listener *next; -} tListener; - -typedef struct listenerList -{ - struct listener *listener; - int grade; - struct listenerList *next; -} tListenerList; - -typedef tConf *ptConf; -typedef tListener *ptListener; -typedef tConfList *ptConfList; -typedef tListenerList *ptListenerList; - -int findConfId(ptConf confChain); -ptConf newConfChain(); -void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year); -void removeConf(ptConf confChain, int id); -int findListenerId(ptListener listenerChain); -ptListener newListenerChain(); -int addListener(ptListener listenerChain, int id, char name[], int age, int level); -void removeListener(ptListener listenerChain, int id); -void addConfToConfList(ptConfList confList, ptConf conf, int grade); -void removeConfFromConfList(ptConfList confList, ptConf conf); -void printConfList(ptConfList confList); -void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); -void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener); -void printListenerList(ptListenerList listenerList); -int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); -int confGradeAvg(ptConf conf); -int confParticipations(ptConf conf); - -//fonction permettant de trouver un id de conférence libre. - -int findConfId(ptConf confChain) -{ - ptConf px = confChain; - int max = 0; - - while (px->next != NULL) - { - if (px->id > max) - { - max = px->id; - } - - px = px->next; - } - - return max + 1; -} - -//fonction permettant de créer une liste de conférences vide. -//nous ajoutons un élément vide afin de grandement décomplexifier la suppression de conférences. - -ptConf newConfChain() -{ - ptConf confChain = (ptConf)malloc(sizeof(tConf)); - - confChain->next = (ptConf)malloc(sizeof(tConf)); - confChain->next->next = NULL; - confChain->id = -1; - - return confChain; -} - -//fonction permettant d'ajouter une conférence à une liste de conférences. - -void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year) -{ - ptConf px = confChain; - - while (px->next != NULL) - { - px = px->next; - } - - px->id = id; - px->day = day; - px->month = month; - px->year = year; - strcpy(px->title, title); - strcpy(px->speaker, speaker); - px->listeners = (ptListenerList)malloc(sizeof(tListenerList)); - px->listeners->next = (ptListenerList)malloc(sizeof(tListenerList)); - px->listeners->listener = NULL; - px->listeners->next->next = NULL; - px->next = (ptConf)malloc(sizeof(tConf)); - px->next->next = NULL; -} - -//fonction permettant de supprimer une conférence d'une liste de conférences. - -void removeConf(ptConf confChain, int id) -{ - //on recherche la conférence à supprimer. - - ptConf px = confChain; - - while (px->next != NULL && px->next->id != id) - { - px = px->next; - } - - if (px->next != NULL && px->next->id == id) - { - //on supprime la conférence de tous les abonnés qui y ont participé. - - ptListenerList py = px->next->listeners->next; - - while (py->next != NULL) - { - removeConfFromConfList(py->listener->confs, px->next); - py = py->next; - } - - //on supprime la conférence de la liste de conférences. - - ptConf tmp = px->next->next; - free(px->next); - px->next = tmp; - } -} - -//fonction permettant de trouver un id d'abonné libre. - -int findListenerId(ptListener listenerChain) -{ - ptListener px = listenerChain; - int max = 0; - - while (px->next != NULL) - { - if (px->id > max) - { - max = px->id; - } - - px = px->next; - } - - return max + 1; -} - -//fonction permettant de créer une liste d'abonnés vide. -//nous ajoutons un élément vide afin de grandement décomplexifier la suppression d'abonnés. - -ptListener newListenerChain() -{ - ptListener listenerChain = (ptListener)malloc(sizeof(tListener)); - - listenerChain->prev = NULL; - listenerChain->next = (ptListener)malloc(sizeof(tListener)); - listenerChain->next->prev = listenerChain; - listenerChain->next->next = NULL; - listenerChain->id = -1; - - return listenerChain; -} - -//fonction permettant d'ajouter un abonné à une liste d'abonnés. - -int addListener(ptListener listenerChain, int id, char name[], int age, int level) -{ - if (level < 0 || level > 5) - { - return -1; - } - - ptListener px = listenerChain; - - while (px->next != NULL) - { - px = px->next; - } - - px->id = id; - strcpy(px->name, name); - px->age = age; - px->level = level; - px->confs = (ptConfList)malloc(sizeof(tConfList)); - px->confs->next = (ptConfList)malloc(sizeof(tConfList)); - px->confs->conf = NULL; - px->confs->next->next = NULL; - px->next = (ptListener)malloc(sizeof(tListener)); - px->next->next = NULL; - px->next->prev = px; - return 0; -} - -//fonction permettant de supprimer un abonné d'une liste d'abonnés. - -void removeListener(ptListener listenerChain, int id) -{ - //on recherche l'abonné à supprimer. - - ptListener px = listenerChain; - - while (px->next != NULL && px->next->id != id) - { - px = px->next; - } - - if (px->next != NULL && px->next->id == id) - { - //on supprime l'abonné de toutes les conférences auxquelles il a participé. - - ptConfList py = px->next->confs->next; - - while (py->next != NULL) - { - removeListenerFromListenerList(py->conf->listeners, px->next); - py = py->next; - } - - //on supprime l'abonné de la liste d'abonnés. - - ptListener tmp = px->next->next; - free(px->next); - px->next = tmp; - px->next->prev = px; - } -} - -//fonction permettant d'ajouter une conférence à une liste de conférences. - -void addConfToConfList(ptConfList confList, ptConf conf, int grade) -{ - ptConfList px = confList; - - while (px->next != NULL) - { - px = px->next; - } - - px->conf = conf; - px->next = (ptConfList)malloc(sizeof(tConfList)); - px->grade = grade; - px->next->next = NULL; -} - -//fonction permettant de supprimer une conférence d'une liste de conférences. - -void removeConfFromConfList(ptConfList confList, ptConf conf) -{ - ptConfList px = confList; - - while (px->next != NULL && px->next->conf != conf) - { - px = px->next; - } - - if (px->next != NULL && px->next->conf == conf) - { - ptConfList tmp = px->next->next; - free(px->next); - px->next = tmp; - } -} - -//fonction permettant d'afficher une liste de conférences. - -void printConfList(ptConfList confList) -{ - ptConfList px = confList; - - printf("Participation aux conferences : "); - while (px->next != NULL) - { - printf("%s(%d) ", px->conf->title, px->grade); - px = px->next; - } - printf("\n"); -} - -//fonction permettant d'ajouter un abonné à une liste d'abonnés. - -void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) -{ - ptListenerList px = listenerList; - - while (px->next != NULL) - { - px = px->next; - } - - px->listener = listener; - px->next = (ptListenerList)malloc(sizeof(tListenerList)); - px->grade = grade; - px->next->next = NULL; -} - -//fonction permettant de supprimer un abonné d'une liste d'abonnés. - -void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) -{ - ptListenerList px = listenerList; - - while (px->next != NULL && px->next->listener != listener) - { - px = px->next; - } - - if (px->next != NULL && px->next->listener == listener) - { - ptListenerList tmp = px->next->next; - free(px->next); - px->next = tmp; - } -} - -//fonction permettant d'afficher une liste d'abonnés. - -void printListenerList(ptListenerList listenerList) -{ - ptListenerList px = listenerList; - - printf("Participants : "); - while (px->next != NULL) - { - printf("%s(%d) ", px->listener->name, px->grade); - px = px->next; - } - printf("\n"); -} - -//fonction permettant à un abonné de participer à une conférence. - -int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) -{ - //on vérifie que la note est comprise entre 0 et 5 et que l'abonné n'a pas déjà participé à la conférence. - - if (grade < 0 || grade > 5) - { - return -1; - } - - ptConf px = confChain; - ptListener py = listenerChain; - ptListenerList pz; - - while (px->next != NULL && px->id != confId) - { - px = px->next; - } - - pz = px->listeners->next; - while (pz->next != NULL) - { - if (pz->listener->id == listenerId) - { - return -2; - } - pz = pz->next; - } - - while (py->next != NULL && py->id != listenerId) - { - py = py->next; - } - - if (px->id != confId || py->id != listenerId) - { - return -2; - } - - //on ajoute la conférence à la liste de conférences de l'abonné et l'abonné à la liste d'abonnés de la conférence. - - addListenerToListenerList(px->listeners, py, grade); - addConfToConfList(py->confs, px, grade); - - return 0; -} - -//fonction permettant de calculer la moyenne des notes d'une conférence. - -int confGradeAvg(ptConf conf) -{ - ptListenerList px = conf->listeners->next; - 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; - } -} - -//fonction permettant de calculer le nombre de participants à une conférence. - -int confParticipations(ptConf conf) -{ - ptListenerList px = conf->listeners->next; - int nb = 0; - - while (px->next != NULL) - { - nb++; - px = px->next; - } - - return nb; -} - -//+----------------------------------------+ -//| Files management | -//+----------------------------------------+ - -void readConfs(ptConf confChain); -void readListeners(ptListener listenerChain); -void readRelations(ptConf confChain, ptListener listenerChain); -void saveConf(ptConf confChain); -void saveListeners(ptListener listenerChain); -void saveRelations(ptConf confChain); - -//fonction permettant de lire les conférences dans le fichier ./data/confs. - -void readConfs(ptConf confChain) -{ - //on ouvre le fichier ./data/confs. - - FILE *file = fopen("./data/confs", "r"); - char line[100]; - //on vérifie que le fichier a bien été ouvert. - - if (file == NULL) - { - printf("ça marche pas."); - return; - } - - //on lit le fichier ligne par ligne et on ajoute les conférences à la liste de conférences. - - 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); - } - - //on ferme le fichier. - - fclose(file); -} - -//fonction permettant de lire les abonnés dans le fichier ./data/listeners. - -void readListeners(ptListener listenerChain) -{ - //on ouvre le fichier ./data/listeners. - - FILE *file = fopen("./data/listeners", "r"); - char line[100]; - - //on vérifie que le fichier a bien été ouvert. - - if (file == NULL) - { - printf("ça marche pas."); - return; - } - - //on lit le fichier ligne par ligne et on ajoute les abonnés à la liste d'abonnés. - - 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); - } - - //on ferme le fichier. - - fclose(file); -} - -//fonction permettant de lire les relations entre conférences et abonnés dans le fichier ./data/relations. - -void readRelations(ptConf confChain, ptListener listenerChain) -{ - //on ouvre le fichier ./data/relations. - - FILE *file = fopen("./data/relations", "r"); - char line[100]; - char *token1; - char *token2; - - //on vérifie que le fichier a bien été ouvert. - - if (file == NULL) - { - printf("ça marche pas."); - return; - } - - //on lit le fichier ligne par ligne et on ajoute les relations entre conférences et abonnés. - - while (fgets(line, sizeof(line), file)) - { - int confId = atoi(strtok(line, ":")); - - while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) - { - participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2)); - } - } - - //on ferme le fichier. - - fclose(file); -} - -//fonction permettant d'écrire les conférences dans le fichier ./data/confs. - -void saveConf(ptConf confChain) -{ - //on ouvre le fichier ./data/confs. - - FILE *file = fopen("./data/confs", "w"); - ptConf px = confChain; - - //on écrit les conférences dans le fichier. - - while (px->next != NULL) - { - fprintf(file, "%d,%s,%s,%d,%d,%d\n", px->id, px->title, px->speaker, px->day, px->month, px->year); - px = px->next; - } - - //on ferme le fichier. - - fclose(file); -} - -//fonction permettant d'écrire les abonnés dans le fichier ./data/listeners. - -void saveListeners(ptListener listenerChain) -{ - //on ouvre le fichier ./data/listeners. - - FILE *file = fopen("./data/listeners", "w"); - ptListener px = listenerChain; - - //on écrit les abonnés dans le fichier. - - while (px->next != NULL) - { - fprintf(file, "%d,%s,%d,%d\n", px->id, px->name, px->age, px->level); - px = px->next; - } - - //on ferme le fichier. - - fclose(file); -} - -//fonction permettant d'écrire les relations entre conférences et abonnés dans le fichier ./data/relations. - -void saveRelations(ptConf confChain) -{ - //on ouvre le fichier ./data/relations. - - FILE *file = fopen("./data/relations", "w"); - ptConf px = confChain; - ptListenerList py; - printf("test"); - - //on écrit les relations entre conférences et abonnés dans le fichier. - - while (px->next != NULL) - { - printf("test"); - py = px->listeners->next; - - if (py->next != NULL) - { - fprintf(file, "%d:", px->id); - } - - while (py->next != NULL) - { - fprintf(file, "%d;%d", py->listener->id, py->grade); - if (py->next->next != NULL) - { - fprintf(file, ","); - } - else - { - fprintf(file, "\n"); - } - py = py->next; - } - - px = px->next; - } - - //on ferme le fichier. - - fclose(file); -} - -//+----------------------------------------+ -//| Screen manager | -//+----------------------------------------+ - -void goToCoords(int x, int y); -void drawHoryLine(char c, int lenght); -void drawVertiLine(char c, int lenght); -void drawRectangle(int x, int y, int lenght, int height); -void drawMenu(char *options[], int lenght); -void tasse(); -void menuConf(ptConf confChain, ptListener listenerChain); -void menuAbo(ptConf confChain, ptListener listenerChain); -void menu(ptConf confChain, ptListener listenerChain); - -//fonction permettant de déplacer le curseur à des coordonnées données. - -void goToCoords(int x, int y) -{ - COORD coords; - - coords.X = x; - coords.Y = y; - - SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coords); -} - -//fonction permettant de dessiner une ligne horizontale dans la console. - -void drawHoryLine(char c, int lenght) -{ - int i = 0; - - while (i != lenght) - { - printf("%c", c); - i++; - } -} - -//fonction permettant de dessiner une ligne verticale dans la console. - -void drawVertiLine(char c, int lenght) -{ - CONSOLE_SCREEN_BUFFER_INFO info; - GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); - int x = info.dwCursorPosition.X; - int y = info.dwCursorPosition.Y; - - int i = 0; - - while (i != lenght) - { - goToCoords(x, y + i); - printf("%c", c); - i++; - } -} - -//fonction permettant de dessiner un rectangle à partir d'un point de départ, d'une longueur et d'une hauteur. - -void drawRectangle(int x, int y, int lenght, int height) -{ - goToCoords(x, y); - printf("%c", 201); - drawHoryLine(205, lenght - 2); - printf("%c", 187); - goToCoords(x, y + 1); - drawVertiLine(186, height - 2); - goToCoords(x + lenght - 1, y + 1); - drawVertiLine(186, height - 2); - goToCoords(x, y + height - 1); - printf("%c", 200); - drawHoryLine(205, lenght - 2); - printf("%c", 188); -} - -//fonction permettant de dessiner un menu à partir d'un tableau de chaînes de caractères. - -void drawMenu(char *options[], int lenght) -{ - //on calcule la longueur de la chaîne la plus longue. - - int max = strlen(options[0]); - int i; - - for (i = 0; i < lenght; i++) - { - if (strlen(options[i]) > max) - { - max = strlen(options[i]); - } - } - - //on récupère la taille de la console. - - CONSOLE_SCREEN_BUFFER_INFO info; - GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); - int columns = info.srWindow.Right - info.srWindow.Left + 1; - int rows = info.srWindow.Bottom - info.srWindow.Top + 1; - - //on dessine le rectangle. - - drawRectangle((columns - max - 4) / 2, 2, max + 4, lenght + 4); - - //on écrit les options. - - for (i = 0; i < lenght; i++) - { - goToCoords((columns - max - 4) / 2 + 2, 4 + i); - printf("%s", options[i]); - } -} - -//+---------------------------+ -//| | -//| ( ) ( ) ) | -//| ) ( ) ( ( | -//| ( ) ( ) ) | -//| _____________ | -//| <_____________> ___ | -//| | |/ _ \ | -//| | | | | | -//| | |_| | | -//| ___| |\___/ | -//| / \___________/ \ | -//| \_____________________/ | -//| | -//+---------------------------+ - -//fonction permettant d'afficher un tasse. - -void tasse() -{ - printf(" ( ) ( ) )\n ) ( ) ( (\n ( ) ( ) )\n _____________\n <_____________> ___\n | |/ _ \\\n | | | |\n | |_| |\n ___| |\\___/\n/ \\___________/ \\\n\\_____________________/\n"); -} - -//fonction permettant d'afficher le menu des conférences. - -void menuConf(ptConf confChain, ptListener listenerChain) -{ - //on affiche le menu. - - char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Supprimer une conference", "4/ Supprimer les conferences inferieures a une date", "5/ Retour"}; - system("cls"); - drawMenu(options, 5); - goToCoords(0, 13); - tasse(); - printf("\n"); - - //on récupère le choix de l'utilisateur. - - printf("Que voulez-vous faire ? : "); - int choice; - scanf("%d", &choice); - - //on effectue l'action correspondante. - - switch (choice) - { - case 1: //on affiche la liste des conférences. - { - ptConf px = confChain->next; - - while (px->next != NULL) - { - printf("Id : %d\nTitre : %s\nConferencier : %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->next != NULL) - { - printListenerList(px->listeners->next); - } - 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: //on ajoute une conférence. - { - int id, day, month, year; - char title[30]; - char speaker[20]; - - id = findConfId(confChain); - printf("Titre de la conference : "); - scanf("%29s", &title); - printf("Nom du conferencier : "); - scanf("%19s", &speaker); - printf("Jour : "); - scanf("%d", &day); - printf("Mois : "); - scanf("%d", &month); - printf("Annee : "); - scanf("%d", &year); - - addConf(confChain, id, title, speaker, day, month, year); - saveConf(confChain->next); - menuConf(confChain, listenerChain); - break; - } - - case 3: //on supprime une conférence. - { - ptConf px = confChain->next; - - printf("\n"); - while (px->next != NULL) - { - printf("%d : %s\n", px->id, px->title); - px = px->next; - } - printf("\n"); - - int id; - - printf("Id de la conference a supprimer : "); - scanf("%d", &id); - - removeConf(confChain, id); - saveConf(confChain->next); - saveRelations(confChain->next); - menuConf(confChain, listenerChain); - break; - } - - case 4: //on supprime les conférences inférieures à une date. - { - ptConf px = confChain->next; - - printf("\n"); - while (px->next != NULL) - { - printf("%s : %d/%d/%d\n", px->title, px->day, px->month, px->year); - px = px->next; - } - printf("\n"); - - 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; - - px = confChain; - - while (px->next != NULL) - { - if ((px->day + px->month * 31 + px->year * 365) < time && px != confChain) - { - ptConf py = px->next; - removeConf(confChain, px->id); - px = py; - } - else if ((px->day + px->month * 31 + px->year * 365) < time && px == confChain) - { - removeConf(confChain, px->id); - } - else - { - px = px->next; - } - } - - saveConf(confChain->next); - saveRelations(confChain->next); - menuConf(confChain, listenerChain); - } - - case 5: //on retourne au menu principal. - menu(confChain, listenerChain); - break; - - default: - break; - } -} - -//fonction permettant d'afficher le menu des abonnés. - -void menuAbo(ptConf confChain, ptListener listenerChain) -{ - //on affiche le menu. - - char *options[] = {"1/ Voir la liste des abonnes", "2/ Ajouter un abonne", "3/ Suprimer un abonne", "4/ Retour"}; - system("cls"); - drawMenu(options, 4); - goToCoords(0, 12); - tasse(); - printf("\n"); - - //on récupère le choix de l'utilisateur. - - printf("Que voulez-vous faire ? : "); - int choice; - scanf("%d", &choice); - - //on effectue l'action correspondante. - - switch (choice) - { - case 1: //on affiche la liste des abonnés. - { - ptListener py = listenerChain->next; - - while (py->next != NULL) - { - printf("Id : %d\nNom: %s\nAge: %d\nNiveau: %d\n", py->id, py->name, py->age, py->level); - if (py->confs->next->next != NULL) - { - printConfList(py->confs->next); - } - printf("\n"); - py = py->next; - } - system("pause"); - menuAbo(confChain, listenerChain); - break; - } - - case 2: //on ajoute un abonné. - { - int id, age, level; - char name[20]; - - id = findListenerId(listenerChain); - printf("Nom : "); - scanf("%19s", &name); - printf("Age : "); - scanf("%d", &age); - printf("Niveau : "); - scanf("%d", &level); - - if (addListener(listenerChain, id, name, age, level) != -1) - { - saveListeners(listenerChain->next); - } - else - { - printf("Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n"); - system("pause"); - } - menuAbo(confChain, listenerChain); - break; - } - - case 3: //on supprime un abonné. - { - ptListener px = listenerChain->next; - - printf("\n"); - while (px->next != NULL) - { - printf("%d : %s\n", px->id, px->name); - px = px->next; - } - printf("\n"); - - int id; - - printf("Id de l'abonne a supprimer : "); - scanf("%d", &id); - - removeListener(listenerChain, id); - saveListeners(listenerChain->next); - saveRelations(confChain->next); - menuAbo(confChain, listenerChain); - break; - } - - case 4: //on retourne au menu principal. - menu(confChain, listenerChain); - break; - - default: - break; - } -} - -//fonction permettant d'afficher le menu principal. - -void menu(ptConf confChain, ptListener listenerChain) -{ - //on affiche le menu. - - 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, 5); - goToCoords(0, 13); - tasse(); - printf("\n"); - - //on récupère le choix de l'utilisateur. - - printf("Que voulez-vous faire ? : "); - int choice; - scanf("%d", &choice); - - //on effectue l'action correspondante. - - switch (choice) - { - case 1: //on affiche le menu des conférences. - menuConf(confChain, listenerChain); - break; - - case 2: //on affiche le menu des abonnés. - menuAbo(confChain, listenerChain); - break; - - case 3: //on permet à un abonné de participer à une conférence. - { - ptConf px = confChain->next; - ptListener py = listenerChain->next; - - printf("\n"); - while (px->next != NULL) - { - printf("%d : %s\n", px->id, px->title); - px = px->next; - } - printf("\n"); - while (py->next != NULL) - { - printf("%d : %s\n", py->id, py->name); - py = py->next; - } - printf("\n"); - - 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 attribuee par le participant : "); - scanf("%d", &grade); - - if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) - { - saveRelations(confChain->next); - } - else - { - printf("La note doit etre comprise entre 0 et 5 et l'abonne ne doit pas avoir deja participe a la conference\n\n"); - system("pause"); - } - - menu(confChain, listenerChain); - break; - } - - case 4: //on affiche la meilleure conférence. - { - ptConf px = confChain -> next; - 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 conference la mieux notee est : %s\n\n", confMax->title); - - system("pause"); - menu(confChain, listenerChain); - - break; - } - - case 5: //on quitte le programme. - break; - - default: - break; - } -} - -//+----------------------------------------+ -//| Main function | -//+----------------------------------------+ - -//fonction main. - -int main() -{ - //on initialise les listes de conférences et d'abonnés. - - ptConf confChain = newConfChain(); - ptListener listenerChain = newListenerChain(); - - //on lit les fichiers de données. - - readConfs(confChain); - readListeners(listenerChain); - readRelations(confChain, listenerChain); - - //on affiche le menu principal. - - menu(confChain, listenerChain); - - return 0; -} \ No newline at end of file