From bd738652a55abecca972e04973f7c3e72cd283da Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Wed, 29 Nov 2023 19:51:46 +0100 Subject: [PATCH] commit --- .vscode/settings.json | 5 + chaise.bat | 23 + conf.c | 35 +- conf.h | 4 +- data/confs | 1 + data/listeners | 1 + data/relations | 3 +- dataBackup/confs | 11 + dataBackup/listeners | 21 + dataBackup/relations | 2 + main.exe | Bin 52993 -> 52833 bytes screenManager.c | 95 +++-- singleFile.c | 953 ++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 1115 insertions(+), 39 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 chaise.bat create mode 100644 dataBackup/confs create mode 100644 dataBackup/listeners create mode 100644 dataBackup/relations create mode 100644 singleFile.c diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9deab0a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdlib.h": "c" + } +} \ No newline at end of file diff --git a/chaise.bat b/chaise.bat new file mode 100644 index 0000000..7e776fe --- /dev/null +++ b/chaise.bat @@ -0,0 +1,23 @@ +@echo off +setlocal + +:: Vérifier si Dev-Cpp est installé +reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Dev-Cpp" >nul 2>&1 +if %errorlevel% equ 0 ( + for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Dev-Cpp" /v Location ^| find "Location"') do ( + set "mingwBin=%%b\MinGW64\bin" + ) + + :: Ajouter le chemin vers le bin de MinGW à la variable d'environnement PATH + echo %PATH% | find "%mingwBin%" >nul + if not errorlevel 1 ( + echo Le chemin d'accès aux bin de MinGW est déjà présent dans la variable d'environnement PATH. + ) else ( + setx PATH "%PATH%;%mingwBin%" -m + echo Le chemin d'accès aux bin de MinGW a été ajouté à la variable d'environnement PATH. + ) +) else ( + echo Dev-Cpp n'est pas installé sur cet ordinateur. +) + +endlocal \ No newline at end of file diff --git a/conf.c b/conf.c index 9913d62..6b7db6d 100644 --- a/conf.c +++ b/conf.c @@ -49,6 +49,20 @@ void removeConf(ptConf confChain, int id) { ptConf px = confChain; if (px -> next -> next == NULL) { + ptListenerList py = px -> listeners; + + while (py -> next != NULL) { + ptConfList pz = py -> listener -> confs; + + while (pz -> next != NULL) { + if (pz -> next -> next ) + + pz = pz -> next; + } + + py = py -> next; + } + free(px -> next); px -> next = NULL; } else if (px -> id == id) { @@ -99,7 +113,11 @@ ptListener newListenerChain() { return listenerChain; } -void addListener(ptListener listenerChain, int id, char name[], int age, int level) { +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) { @@ -115,6 +133,7 @@ void addListener(ptListener listenerChain, int id, char name[], int age, int lev px -> next = (ptListener) malloc(sizeof(tListener)); px -> next -> next = NULL; px -> next -> prev = px; + return 0; } void removeListener(ptListener listenerChain, int id) { @@ -187,7 +206,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener, void printListenerList(ptListenerList listenerList) { ptListenerList px = listenerList; - printf("Participants : "); + printf(" Participants : "); while (px -> next != NULL) { printf("%s(%d) ", px -> listener -> name, px -> grade); px = px -> next; @@ -195,7 +214,11 @@ void printListenerList(ptListenerList listenerList) { printf("\n"); } -void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) { +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; @@ -207,7 +230,7 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i pz = px -> listeners; while (pz -> next != NULL) { if (pz -> listener -> id == listenerId) { - return; + return -2; } pz = pz -> next; } @@ -217,11 +240,13 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i } if (px -> id != confId || py -> id != listenerId) { - return; + return -2; } addListenerToListenerList(px -> listeners, py, grade); addConfToConfList(py -> confs, px, grade); + + return 0; } int confGradeAvg(ptConf conf) { diff --git a/conf.h b/conf.h index 194d026..ac9c7f9 100644 --- a/conf.h +++ b/conf.h @@ -47,13 +47,13 @@ void addConf(ptConf confChain, int id, char title[], char speaker[], int day, in void removeConf(ptConf confChain, int id); int findListenerId(ptListener listenerChain); ptListener newListenerChain(); -void addListener(ptListener listenerChain, int id, char name[], int age, int level); +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 printConfList(ptConfList confList); void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); void printListenerList(ptListenerList listenerList); -void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); +int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); int confGradeAvg(ptConf conf); int confParticipations(ptConf conf); diff --git a/data/confs b/data/confs index 1c295f8..345e76f 100644 --- a/data/confs +++ b/data/confs @@ -8,3 +8,4 @@ 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 diff --git a/data/listeners b/data/listeners index 8659b89..fabd967 100644 --- a/data/listeners +++ b/data/listeners @@ -18,3 +18,4 @@ 18,Marion,17,1 19,Tom,17,1 20,Sebastien,45,5 +21,Jean,50,5 diff --git a/data/relations b/data/relations index ced4fda..a8edff2 100644 --- a/data/relations +++ b/data/relations @@ -1 +1,2 @@ -1:1;12,2;12,12;0 +1:12;0,1;4 +9:20;5 diff --git a/dataBackup/confs b/dataBackup/confs new file mode 100644 index 0000000..345e76f --- /dev/null +++ b/dataBackup/confs @@ -0,0 +1,11 @@ +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 diff --git a/dataBackup/listeners b/dataBackup/listeners new file mode 100644 index 0000000..fabd967 --- /dev/null +++ b/dataBackup/listeners @@ -0,0 +1,21 @@ +1,Simon,21,3 +2,Bertrand,42,8 +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 +16,Juliette,32,8 +17,Malick,25,7 +18,Marion,17,1 +19,Tom,17,1 +20,Sebastien,45,5 +21,Jean,50,5 diff --git a/dataBackup/relations b/dataBackup/relations new file mode 100644 index 0000000..a8edff2 --- /dev/null +++ b/dataBackup/relations @@ -0,0 +1,2 @@ +1:12;0,1;4 +9:20;5 diff --git a/main.exe b/main.exe index 396e74c9664318f256d20cb3d09bbe9dd096d608..5eca2ded87d2793eab5ae35b65fc6962a302e2ea 100644 GIT binary patch delta 13187 zcmch7dq7lW`u{nH;Uaeu6cJ(MqJWAZ7ZEQF$PkqmDlzj02%}&K2%}P2qYIQcV%Vdt zzr?#4m70o~mAmpy6YFOiySbacwQX@_Z3x!IGP81>-{(1JZYTHe@6qRd-}8B{@AF>H zd(N`Rv_Ki~4#1S!sw*1Khr zP7HM~-75&e6tr{bmLv^Tw|YsJ^z<8XmiK@cRH{MV^j9&$zrhd9bs&GxT=I~z{o_2* z+yi3CQkpA`rq`vx)FOq5m2^-VEmqSXP}b0GaP)4$l2_YaJe|@t zPe}FC$*f5mK4ZEd)Z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uo)_uCw`P*tTXQ=1zIDs3^Wb|&-TxnD-1jvA diff --git a/screenManager.c b/screenManager.c index 9f45edd..46077b4 100644 --- a/screenManager.c +++ b/screenManager.c @@ -82,8 +82,26 @@ void drawMenu(char *options[], int lenght) { } +/* + ( ) ( ) ) + ) ( ) ( ( + ( ) ( ) ) + _____________ + <_____________> ___ + | |/ _ \ + | | | | + | |_| | + ___| |\___/ +/ \___________/ \ +\_____________________/ +*/ + +void tasse() { + printf(" ( ) ( ) )\n ) ( ) ( (\n ( ) ( ) )\n _____________\n <_____________> ___\n | |/ _ \\\n | | | |\n | |_| |\n ___| |\\___/\n/ \\___________/ \\\n\\_____________________/\n"); +} + void menuConf(ptConf confChain, ptListener listenerChain) { - 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"}; + 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); @@ -98,15 +116,15 @@ void menuConf(ptConf confChain, ptListener listenerChain) { ptConf px = confChain; while (px -> next != NULL) { - 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)); + printf(" Id : %d\n Titre : %s\n Conferencier : %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(" Moyenne des notes : %d\n", confGradeAvg(px)); } printf("\n"); px = px -> next; @@ -123,15 +141,15 @@ void menuConf(ptConf confChain, ptListener listenerChain) { char speaker[20]; id = findConfId(confChain); - printf("Titre de la conference : "); + printf(" Titre de la conference : "); scanf("%29s", &title); - printf("Nom du conferencier : "); + printf(" Nom du conferencier : "); scanf("%19s", &speaker); - printf("Jour : "); + printf(" Jour : "); scanf("%d", &day); - printf("Mois : "); + printf(" Mois : "); scanf("%d", &month); - printf("Année : "); + printf(" Annee : "); scanf("%d", &year); addConf(confChain, id, title, speaker, day, month, year); @@ -144,7 +162,7 @@ void menuConf(ptConf confChain, ptListener listenerChain) { { int id; - printf("Id de la conference à supprimer : "); + printf(" Id de la conference a supprimer : "); scanf("%d", &id); removeConf(confChain, id); @@ -156,27 +174,31 @@ void menuConf(ptConf confChain, ptListener listenerChain) { case 4: { int day, month, year, time; - printf("Jour : "); + printf(" Jour : "); scanf("%d", &day); - printf("Mois : "); + printf(" Mois : "); scanf("%d", &month); - printf("Annee : "); + printf(" Annee : "); scanf("%d", &year); - time = day + 31 * month * 365 * year; + time = day + 31 * month + 365 * year; ptConf px = confChain; while(px -> next != NULL) { - if ((px -> day + px -> month * 31 + px -> year * 365) < time) { + 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); + menuConf(confChain, listenerChain); } @@ -194,7 +216,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { system("cls"); drawMenu(options, 4); goToCoords(0, 12); - printf("Que voulez-vous faire ? : "); + printf(" Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -205,7 +227,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { ptListener py = listenerChain; while (py -> next != NULL) { - printf("id : %d\nname: %s\nage: %d\nlevel: %d\n", py -> id, py -> name, py -> age, py -> level); + printf(" Id : %d\n Nom: %s\n Age: %d\n Niveau: %d\n", py -> id, py -> name, py -> age, py -> level); if (py -> confs -> next != NULL) { printConfList(py -> confs); } @@ -223,15 +245,19 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { char name[20]; id = findListenerId(listenerChain); - printf("Nom : "); + printf(" Nom : "); scanf("%19s", &name); - printf("Age : "); + printf(" Age : "); scanf("%d", &age); - printf("Niveau : "); + printf(" Niveau : "); scanf("%d", &level); - addListener(listenerChain, id, name, age, level); - saveListeners(listenerChain); + if (addListener(listenerChain, id, name, age, level) != -1) { + saveListeners(listenerChain); + } else { + printf(" Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n"); + system("pause"); + } menuAbo(confChain, listenerChain); break; } @@ -240,7 +266,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { { int id; - printf("Id de l'abonne à supprimer : "); + printf(" Id de l'abonne a supprimer : "); scanf("%d", &id); removeListener(listenerChain, id); @@ -264,7 +290,9 @@ void menu(ptConf confChain, ptListener listenerChain) system("cls"); drawMenu(options, 5); goToCoords(0, 13); - printf("Que voulez-vous faire ? : "); + tasse(); + printf("\n"); + printf(" Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -281,15 +309,20 @@ void menu(ptConf confChain, ptListener listenerChain) case 3: { int confId, listenerId, grade; - printf("Entrez l'ID de la conference : "); + printf(" Entrez l'ID de la conference : "); scanf("%d", &confId); - printf("Entrez l'ID du participant : "); + printf(" Entrez l'ID du participant : "); scanf("%d", &listenerId); - printf("Entrez la note attribuée par le participant : "); + printf(" Entrez la note attribuee par le participant : "); scanf("%d", &grade); - participateToConf(confChain, listenerChain, confId, listenerId, grade); - saveRelations(confChain); + if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) { + saveRelations(confChain); + } 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; } @@ -310,7 +343,7 @@ void menu(ptConf confChain, ptListener listenerChain) px = px -> next; } - printf("La conférence la mieux notée est : %s\n\n", confMax -> title); + printf(" La conférence la mieux notee est : %s\n\n", confMax -> title); system("pause"); menu(confChain, listenerChain); diff --git a/singleFile.c b/singleFile.c new file mode 100644 index 0000000..d8e8f57 --- /dev/null +++ b/singleFile.c @@ -0,0 +1,953 @@ +#include +#include +#include +#include + +//+----------------------------------------+ +//| Conf management | +//+----------------------------------------+ + +struct listenerList; + +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; + +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 printConfList(ptConfList confList); +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); +void printListenerList(ptListenerList listenerList); +int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); +int confGradeAvg(ptConf conf); +int confParticipations(ptConf conf); + +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; +} + +ptConf newConfChain() +{ + ptConf confChain = (ptConf)malloc(sizeof(tConf)); + + confChain->next = NULL; + + return confChain; +} + +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 = NULL; + px->next = (ptConf)malloc(sizeof(tConf)); + px->next->next = NULL; +} + +void removeConf(ptConf confChain, int id) +{ + ptConf px = confChain; + + if (px->next->next == NULL) + { + ptListenerList py = px->listeners; + + while (py->next != NULL) + { + ptConfList pz = py->listener->confs; + + while (pz->next != NULL) + { + if (pz->next->next) + + pz = pz->next; + } + + py = py->next; + } + + free(px->next); + px->next = NULL; + } + else if (px->id == id) + { + px->id = px->next->id; + strcpy(px->title, px->next->title); + strcpy(px->speaker, px->next->speaker); + px->day = px->next->day; + px->month = px->next->month; + px->year = px->next->year; + + ptConf tmp = px->next; + px->next = px->next->next; + free(tmp); + } + else + { + while (px->next != NULL && px->next->id != id) + { + px = px->next; + } + + if (px->next->id == id) + { + ptConf tmp = px->next; + px->next = px->next->next; + free(tmp); + } + } +} + +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; +} + +ptListener newListenerChain() +{ + ptListener listenerChain = (ptListener)malloc(sizeof(tListener)); + + listenerChain->prev = NULL; + listenerChain->next = NULL; + + return listenerChain; +} + +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 = NULL; + px->next = (ptListener)malloc(sizeof(tListener)); + px->next->next = NULL; + px->next->prev = px; + return 0; +} + +void removeListener(ptListener listenerChain, int id) +{ + ptListener px = listenerChain; + + if (px->next->next == NULL) + { + free(px->next); + px->next = NULL; + } + else if (px->id == id) + { + px->id = px->next->id; + strcpy(px->name, px->next->name); + px->age = px->next->age; + px->level = px->next->level; + + ptListener tmp = px->next; + px->next = px->next->next; + px->next->prev = px; + free(tmp); + } + else + { + while (px->next != NULL && px->next->id != id) + { + px = px->next; + } + + if (px->next->id == id) + { + ptListener tmp = px->next; + px->next = px->next->next; + px->next->prev = px; + free(tmp); + } + } +} + +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 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 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) + { + return -1; + } + + ptConf px = confChain; + ptListener py = listenerChain; + ptListenerList pz; + + while (px->next != NULL && px->id != confId) + { + px = px->next; + } + + pz = px->listeners; + 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; + 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; +} + +//+----------------------------------------+ +//| 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); + +void readConfs(ptConf confChain) +{ + FILE *file = fopen("./data/confs", "r"); + char line[100]; + char *token; + + 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 *token; + + 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); +} + +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)) + { + int confId = atoi(strtok(line, ":")); + + while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) + { + participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2)); + } + } + + fclose(file); +} + +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; + } + fclose(file); +} + +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; + } + fclose(file); +} + +void saveRelations(ptConf confChain) +{ + FILE *file = fopen("./data/relations", "w"); + ptConf px = confChain; + ptListenerList py; + while (px->next != NULL) + { + py = px->listeners; + + 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; + } + 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); + +void goToCoords(int x, int y) +{ + COORD coords; + + coords.X = x; + coords.Y = y; + + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coords); +} + +void drawHoryLine(char c, int lenght) +{ + int i = 0; + + while (i != lenght) + { + printf("%c", c); + i++; + } +} + +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++; + } +} + +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); +} + +void drawMenu(char *options[], int lenght) +{ + int max = strlen(options[0]); + int i; + + for (i = 0; i < lenght; i++) + { + if (strlen(options[i]) > max) + { + max = strlen(options[i]); + } + } + + 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; + + drawRectangle((columns - max - 4) / 2, 2, max + 4, lenght + 4); + + for (i = 0; i < lenght; i++) + { + goToCoords((columns - max - 4) / 2 + 2, 4 + i); + printf("%s", options[i]); + } +} + +/* + ( ) ( ) ) + ) ( ) ( ( + ( ) ( ) ) + _____________ + <_____________> ___ + | |/ _ \ + | | | | + | |_| | + ___| |\___/ +/ \___________/ \ +\_____________________/ +*/ + +void tasse() +{ + printf(" ( ) ( ) )\n ) ( ) ( (\n ( ) ( ) )\n _____________\n <_____________> ___\n | |/ _ \\\n | | | |\n | |_| |\n ___| |\\___/\n/ \\___________/ \\\n\\_____________________/\n"); +} + +void menuConf(ptConf confChain, ptListener listenerChain) +{ + 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); + printf("Que voulez-vous faire ? : "); + int choice; + scanf("%d", &choice); + + switch (choice) + { + case 1: + { + ptConf px = confChain; + + while (px->next != NULL) + { + printf(" Id : %d\n Titre : %s\n Conferencier : %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: + { + 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); + menuConf(confChain, listenerChain); + break; + } + + case 3: + { + int id; + + printf(" Id de la conference a supprimer : "); + scanf("%d", &id); + + removeConf(confChain, id); + saveConf(confChain); + menuConf(confChain, listenerChain); + break; + } + + 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 && 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); + + menuConf(confChain, listenerChain); + } + + case 5: + menu(confChain, listenerChain); + break; + + default: + break; + } +} + +void menuAbo(ptConf confChain, ptListener listenerChain) +{ + 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); + printf(" Que voulez-vous faire ? : "); + int choice; + scanf("%d", &choice); + + switch (choice) + { + case 1: + { + ptListener py = listenerChain; + + while (py->next != NULL) + { + printf(" Id : %d\n Nom: %s\n Age: %d\n Niveau: %d\n", py->id, py->name, py->age, py->level); + if (py->confs->next != NULL) + { + printConfList(py->confs); + } + printf("\n"); + py = py->next; + } + system("pause"); + menuAbo(confChain, listenerChain); + break; + } + + case 2: + { + 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); + } + else + { + printf(" Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n"); + system("pause"); + } + menuAbo(confChain, listenerChain); + break; + } + + case 3: + { + int id; + + printf(" Id de l'abonne a supprimer : "); + scanf("%d", &id); + + removeListener(listenerChain, id); + saveListeners(listenerChain); + menuAbo(confChain, listenerChain); + break; + } + + case 4: + menu(confChain, listenerChain); + break; + + default: + break; + } +} + +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/ Quitter"}; + system("cls"); + drawMenu(options, 5); + goToCoords(0, 13); + tasse(); + printf("\n"); + printf(" Que voulez-vous faire ? : "); + int choice; + scanf("%d", &choice); + + switch (choice) + { + case 1: + menuConf(confChain, listenerChain); + break; + + case 2: + menuAbo(confChain, listenerChain); + break; + + case 3: + { + 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); + } + 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: + { + 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 notee est : %s\n\n", confMax->title); + + system("pause"); + menu(confChain, listenerChain); + + break; + } + + case 5: + break; + + default: + break; + } +} + +//+----------------------------------------+ +//| Main function | +//+----------------------------------------+ + +int main() +{ + ptConf confChain = newConfChain(); + ptListener listenerChain = newListenerChain(); + + readConfs(confChain); + readListeners(listenerChain); + readRelations(confChain, listenerChain); + menu(confChain, listenerChain); + + return 0; +} \ No newline at end of file