commit
This commit is contained in:
parent
63e83a9601
commit
bd738652a5
13 changed files with 1115 additions and 39 deletions
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"stdlib.h": "c"
|
||||||
|
}
|
||||||
|
}
|
23
chaise.bat
Normal file
23
chaise.bat
Normal file
|
@ -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
|
35
conf.c
35
conf.c
|
@ -49,6 +49,20 @@ void removeConf(ptConf confChain, int id) {
|
||||||
ptConf px = confChain;
|
ptConf px = confChain;
|
||||||
|
|
||||||
if (px -> next -> next == NULL) {
|
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);
|
free(px -> next);
|
||||||
px -> next = NULL;
|
px -> next = NULL;
|
||||||
} else if (px -> id == id) {
|
} else if (px -> id == id) {
|
||||||
|
@ -99,7 +113,11 @@ ptListener newListenerChain() {
|
||||||
return listenerChain;
|
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;
|
ptListener px = listenerChain;
|
||||||
|
|
||||||
while (px -> next != NULL) {
|
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 = (ptListener) malloc(sizeof(tListener));
|
||||||
px -> next -> next = NULL;
|
px -> next -> next = NULL;
|
||||||
px -> next -> prev = px;
|
px -> next -> prev = px;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeListener(ptListener listenerChain, int id) {
|
void removeListener(ptListener listenerChain, int id) {
|
||||||
|
@ -187,7 +206,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener,
|
||||||
void printListenerList(ptListenerList listenerList) {
|
void printListenerList(ptListenerList listenerList) {
|
||||||
ptListenerList px = listenerList;
|
ptListenerList px = listenerList;
|
||||||
|
|
||||||
printf("Participants : ");
|
printf(" Participants : ");
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
printf("%s(%d) ", px -> listener -> name, px -> grade);
|
printf("%s(%d) ", px -> listener -> name, px -> grade);
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
|
@ -195,7 +214,11 @@ void printListenerList(ptListenerList listenerList) {
|
||||||
printf("\n");
|
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;
|
ptConf px = confChain;
|
||||||
ptListener py = listenerChain;
|
ptListener py = listenerChain;
|
||||||
ptListenerList pz;
|
ptListenerList pz;
|
||||||
|
@ -207,7 +230,7 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i
|
||||||
pz = px -> listeners;
|
pz = px -> listeners;
|
||||||
while (pz -> next != NULL) {
|
while (pz -> next != NULL) {
|
||||||
if (pz -> listener -> id == listenerId) {
|
if (pz -> listener -> id == listenerId) {
|
||||||
return;
|
return -2;
|
||||||
}
|
}
|
||||||
pz = pz -> next;
|
pz = pz -> next;
|
||||||
}
|
}
|
||||||
|
@ -217,11 +240,13 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i
|
||||||
}
|
}
|
||||||
|
|
||||||
if (px -> id != confId || py -> id != listenerId) {
|
if (px -> id != confId || py -> id != listenerId) {
|
||||||
return;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
addListenerToListenerList(px -> listeners, py, grade);
|
addListenerToListenerList(px -> listeners, py, grade);
|
||||||
addConfToConfList(py -> confs, px, grade);
|
addConfToConfList(py -> confs, px, grade);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int confGradeAvg(ptConf conf) {
|
int confGradeAvg(ptConf conf) {
|
||||||
|
|
4
conf.h
4
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);
|
void removeConf(ptConf confChain, int id);
|
||||||
int findListenerId(ptListener listenerChain);
|
int findListenerId(ptListener listenerChain);
|
||||||
ptListener newListenerChain();
|
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 removeListener(ptListener listenerChain, int id);
|
||||||
void addConfToConfList(ptConfList confList, ptConf conf, int grade);
|
void addConfToConfList(ptConfList confList, ptConf conf, int grade);
|
||||||
void printConfList(ptConfList confList);
|
void printConfList(ptConfList confList);
|
||||||
void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade);
|
void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade);
|
||||||
void printListenerList(ptListenerList listenerList);
|
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 confGradeAvg(ptConf conf);
|
||||||
int confParticipations(ptConf conf);
|
int confParticipations(ptConf conf);
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,4 @@
|
||||||
8,Therories_du_complots,Jean_Benoit,1,4,2021
|
8,Therories_du_complots,Jean_Benoit,1,4,2021
|
||||||
9,Le_lacet_irlandais,Mick_Oconnell,31,3,2022
|
9,Le_lacet_irlandais,Mick_Oconnell,31,3,2022
|
||||||
10,Litterature_et_SF,Terry_Pratchett,15,5,2021
|
10,Litterature_et_SF,Terry_Pratchett,15,5,2021
|
||||||
|
11,Les_chaises_en_bois,David,24,12,2023
|
||||||
|
|
|
@ -18,3 +18,4 @@
|
||||||
18,Marion,17,1
|
18,Marion,17,1
|
||||||
19,Tom,17,1
|
19,Tom,17,1
|
||||||
20,Sebastien,45,5
|
20,Sebastien,45,5
|
||||||
|
21,Jean,50,5
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
1:1;12,2;12,12;0
|
1:12;0,1;4
|
||||||
|
9:20;5
|
||||||
|
|
11
dataBackup/confs
Normal file
11
dataBackup/confs
Normal file
|
@ -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
|
21
dataBackup/listeners
Normal file
21
dataBackup/listeners
Normal file
|
@ -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
|
2
dataBackup/relations
Normal file
2
dataBackup/relations
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
1:12;0,1;4
|
||||||
|
9:20;5
|
BIN
main.exe
BIN
main.exe
Binary file not shown.
|
@ -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) {
|
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");
|
system("cls");
|
||||||
drawMenu(options, 5);
|
drawMenu(options, 5);
|
||||||
goToCoords(0, 13);
|
goToCoords(0, 13);
|
||||||
|
@ -98,15 +116,15 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
|
||||||
ptConf px = confChain;
|
ptConf px = confChain;
|
||||||
|
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
printf("Id : %d\nTitre : %s\nConférencier : %s\n", px -> id, px -> title, px -> speaker);
|
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(" Date : %d/%d/%d\n",px -> day, px -> month, px -> year);
|
||||||
printf("Nombre de participants : %d\n", confParticipations(px));
|
printf(" Nombre de participants : %d\n", confParticipations(px));
|
||||||
if (px -> listeners -> next != NULL ) {
|
if (px -> listeners -> next != NULL ) {
|
||||||
printListenerList(px -> listeners);
|
printListenerList(px -> listeners);
|
||||||
}
|
}
|
||||||
int avg;
|
int avg;
|
||||||
if ((avg = confGradeAvg(px) != -1)) {
|
if ((avg = confGradeAvg(px) != -1)) {
|
||||||
printf("Moyenne des notes : %d\n", confGradeAvg(px));
|
printf(" Moyenne des notes : %d\n", confGradeAvg(px));
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
|
@ -123,15 +141,15 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
|
||||||
char speaker[20];
|
char speaker[20];
|
||||||
|
|
||||||
id = findConfId(confChain);
|
id = findConfId(confChain);
|
||||||
printf("Titre de la conference : ");
|
printf(" Titre de la conference : ");
|
||||||
scanf("%29s", &title);
|
scanf("%29s", &title);
|
||||||
printf("Nom du conferencier : ");
|
printf(" Nom du conferencier : ");
|
||||||
scanf("%19s", &speaker);
|
scanf("%19s", &speaker);
|
||||||
printf("Jour : ");
|
printf(" Jour : ");
|
||||||
scanf("%d", &day);
|
scanf("%d", &day);
|
||||||
printf("Mois : ");
|
printf(" Mois : ");
|
||||||
scanf("%d", &month);
|
scanf("%d", &month);
|
||||||
printf("Année : ");
|
printf(" Annee : ");
|
||||||
scanf("%d", &year);
|
scanf("%d", &year);
|
||||||
|
|
||||||
addConf(confChain, id, title, speaker, day, month, year);
|
addConf(confChain, id, title, speaker, day, month, year);
|
||||||
|
@ -144,7 +162,7 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
printf("Id de la conference à supprimer : ");
|
printf(" Id de la conference a supprimer : ");
|
||||||
scanf("%d", &id);
|
scanf("%d", &id);
|
||||||
|
|
||||||
removeConf(confChain, id);
|
removeConf(confChain, id);
|
||||||
|
@ -156,27 +174,31 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
int day, month, year, time;
|
int day, month, year, time;
|
||||||
printf("Jour : ");
|
printf(" Jour : ");
|
||||||
scanf("%d", &day);
|
scanf("%d", &day);
|
||||||
printf("Mois : ");
|
printf(" Mois : ");
|
||||||
scanf("%d", &month);
|
scanf("%d", &month);
|
||||||
printf("Annee : ");
|
printf(" Annee : ");
|
||||||
scanf("%d", &year);
|
scanf("%d", &year);
|
||||||
|
|
||||||
time = day + 31 * month * 365 * year;
|
time = day + 31 * month + 365 * year;
|
||||||
|
|
||||||
ptConf px = confChain;
|
ptConf px = confChain;
|
||||||
|
|
||||||
while(px -> next != NULL) {
|
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;
|
ptConf py = px -> next;
|
||||||
removeConf(confChain, px -> id);
|
removeConf(confChain, px -> id);
|
||||||
px = py;
|
px = py;
|
||||||
|
} else if ((px -> day + px -> month * 31 + px -> year * 365) < time && px == confChain) {
|
||||||
|
removeConf(confChain, px -> id);
|
||||||
} else {
|
} else {
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveConf(confChain);
|
||||||
|
|
||||||
menuConf(confChain, listenerChain);
|
menuConf(confChain, listenerChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +216,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
system("cls");
|
system("cls");
|
||||||
drawMenu(options, 4);
|
drawMenu(options, 4);
|
||||||
goToCoords(0, 12);
|
goToCoords(0, 12);
|
||||||
printf("Que voulez-vous faire ? : ");
|
printf(" Que voulez-vous faire ? : ");
|
||||||
int choice;
|
int choice;
|
||||||
scanf("%d", &choice);
|
scanf("%d", &choice);
|
||||||
|
|
||||||
|
@ -205,7 +227,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
ptListener py = listenerChain;
|
ptListener py = listenerChain;
|
||||||
|
|
||||||
while (py -> next != NULL) {
|
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) {
|
if (py -> confs -> next != NULL) {
|
||||||
printConfList(py -> confs);
|
printConfList(py -> confs);
|
||||||
}
|
}
|
||||||
|
@ -223,15 +245,19 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
char name[20];
|
char name[20];
|
||||||
|
|
||||||
id = findListenerId(listenerChain);
|
id = findListenerId(listenerChain);
|
||||||
printf("Nom : ");
|
printf(" Nom : ");
|
||||||
scanf("%19s", &name);
|
scanf("%19s", &name);
|
||||||
printf("Age : ");
|
printf(" Age : ");
|
||||||
scanf("%d", &age);
|
scanf("%d", &age);
|
||||||
printf("Niveau : ");
|
printf(" Niveau : ");
|
||||||
scanf("%d", &level);
|
scanf("%d", &level);
|
||||||
|
|
||||||
addListener(listenerChain, id, name, age, level);
|
if (addListener(listenerChain, id, name, age, level) != -1) {
|
||||||
saveListeners(listenerChain);
|
saveListeners(listenerChain);
|
||||||
|
} else {
|
||||||
|
printf(" Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n");
|
||||||
|
system("pause");
|
||||||
|
}
|
||||||
menuAbo(confChain, listenerChain);
|
menuAbo(confChain, listenerChain);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +266,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
printf("Id de l'abonne à supprimer : ");
|
printf(" Id de l'abonne a supprimer : ");
|
||||||
scanf("%d", &id);
|
scanf("%d", &id);
|
||||||
|
|
||||||
removeListener(listenerChain, id);
|
removeListener(listenerChain, id);
|
||||||
|
@ -264,7 +290,9 @@ void menu(ptConf confChain, ptListener listenerChain)
|
||||||
system("cls");
|
system("cls");
|
||||||
drawMenu(options, 5);
|
drawMenu(options, 5);
|
||||||
goToCoords(0, 13);
|
goToCoords(0, 13);
|
||||||
printf("Que voulez-vous faire ? : ");
|
tasse();
|
||||||
|
printf("\n");
|
||||||
|
printf(" Que voulez-vous faire ? : ");
|
||||||
int choice;
|
int choice;
|
||||||
scanf("%d", &choice);
|
scanf("%d", &choice);
|
||||||
|
|
||||||
|
@ -281,15 +309,20 @@ void menu(ptConf confChain, ptListener listenerChain)
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
int confId, listenerId, grade;
|
int confId, listenerId, grade;
|
||||||
printf("Entrez l'ID de la conference : ");
|
printf(" Entrez l'ID de la conference : ");
|
||||||
scanf("%d", &confId);
|
scanf("%d", &confId);
|
||||||
printf("Entrez l'ID du participant : ");
|
printf(" Entrez l'ID du participant : ");
|
||||||
scanf("%d", &listenerId);
|
scanf("%d", &listenerId);
|
||||||
printf("Entrez la note attribuée par le participant : ");
|
printf(" Entrez la note attribuee par le participant : ");
|
||||||
scanf("%d", &grade);
|
scanf("%d", &grade);
|
||||||
|
|
||||||
participateToConf(confChain, listenerChain, confId, listenerId, grade);
|
if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) {
|
||||||
saveRelations(confChain);
|
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);
|
menu(confChain, listenerChain);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -310,7 +343,7 @@ void menu(ptConf confChain, ptListener listenerChain)
|
||||||
px = px -> next;
|
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");
|
system("pause");
|
||||||
menu(confChain, listenerChain);
|
menu(confChain, listenerChain);
|
||||||
|
|
953
singleFile.c
Normal file
953
singleFile.c
Normal file
|
@ -0,0 +1,953 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
//+----------------------------------------+
|
||||||
|
//| 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;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue