commit
This commit is contained in:
parent
c755619819
commit
63e83a9601
6 changed files with 153 additions and 85 deletions
46
conf.c
46
conf.c
|
@ -147,7 +147,7 @@ void removeListener(ptListener listenerChain, int id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addConfToConfList(ptConfList confList, ptConf conf) {
|
void addConfToConfList(ptConfList confList, ptConf conf, int grade) {
|
||||||
ptConfList px = confList;
|
ptConfList px = confList;
|
||||||
|
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
|
@ -156,6 +156,7 @@ void addConfToConfList(ptConfList confList, ptConf conf) {
|
||||||
|
|
||||||
px -> conf = conf;
|
px -> conf = conf;
|
||||||
px -> next = (ptConfList) malloc(sizeof(tConfList));
|
px -> next = (ptConfList) malloc(sizeof(tConfList));
|
||||||
|
px -> grade = grade;
|
||||||
px -> next -> next = NULL;
|
px -> next -> next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,13 +165,13 @@ void printConfList(ptConfList confList) {
|
||||||
|
|
||||||
printf("Participation aux conferences : ");
|
printf("Participation aux conferences : ");
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
printf("%s ", px -> conf -> title);
|
printf("%s(%d) ", px -> conf -> title, px -> grade);
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void addListenerToListenerList(ptListenerList listenerList, ptListener listener) {
|
void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) {
|
||||||
ptListenerList px = listenerList;
|
ptListenerList px = listenerList;
|
||||||
|
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
|
@ -179,6 +180,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener)
|
||||||
|
|
||||||
px -> listener = listener;
|
px -> listener = listener;
|
||||||
px -> next = (ptListenerList) malloc(sizeof(tListenerList));
|
px -> next = (ptListenerList) malloc(sizeof(tListenerList));
|
||||||
|
px -> grade = grade;
|
||||||
px -> next -> next = NULL;
|
px -> next -> next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,13 +189,13 @@ void printListenerList(ptListenerList listenerList) {
|
||||||
|
|
||||||
printf("Participants : ");
|
printf("Participants : ");
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
printf("%s ", px -> listener -> name);
|
printf("%s(%d) ", px -> listener -> name, px -> grade);
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId) {
|
void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) {
|
||||||
ptConf px = confChain;
|
ptConf px = confChain;
|
||||||
ptListener py = listenerChain;
|
ptListener py = listenerChain;
|
||||||
ptListenerList pz;
|
ptListenerList pz;
|
||||||
|
@ -218,6 +220,36 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addListenerToListenerList(px -> listeners, py);
|
addListenerToListenerList(px -> listeners, py, grade);
|
||||||
addConfToConfList(py -> confs, px);
|
addConfToConfList(py -> confs, px, grade);
|
||||||
|
}
|
||||||
|
|
||||||
|
int confGradeAvg(ptConf conf) {
|
||||||
|
ptListenerList px = conf -> listeners;
|
||||||
|
int total = 0, nb = 0;
|
||||||
|
|
||||||
|
while (px -> next != NULL) {
|
||||||
|
total += px -> grade;
|
||||||
|
nb++;
|
||||||
|
px = px -> next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nb != 0) {
|
||||||
|
return total / nb;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int confParticipations(ptConf conf) {
|
||||||
|
ptListenerList px = conf -> listeners;
|
||||||
|
int nb = 0;
|
||||||
|
|
||||||
|
while (px -> next != NULL) {
|
||||||
|
nb++;
|
||||||
|
px = px -> next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nb;
|
||||||
}
|
}
|
10
conf.h
10
conf.h
|
@ -16,6 +16,7 @@ typedef struct conf {
|
||||||
|
|
||||||
typedef struct confList {
|
typedef struct confList {
|
||||||
struct conf* conf;
|
struct conf* conf;
|
||||||
|
int grade;
|
||||||
struct confList* next;
|
struct confList* next;
|
||||||
} tConfList;
|
} tConfList;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ typedef struct listener {
|
||||||
|
|
||||||
typedef struct listenerList {
|
typedef struct listenerList {
|
||||||
struct listener* listener;
|
struct listener* listener;
|
||||||
|
int grade;
|
||||||
struct listenerList* next;
|
struct listenerList* next;
|
||||||
} tListenerList;
|
} tListenerList;
|
||||||
|
|
||||||
|
@ -47,10 +49,12 @@ int findListenerId(ptListener listenerChain);
|
||||||
ptListener newListenerChain();
|
ptListener newListenerChain();
|
||||||
void addListener(ptListener listenerChain, int id, char name[], int age, int level);
|
void 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);
|
void addConfToConfList(ptConfList confList, ptConf conf, int grade);
|
||||||
void printConfList(ptConfList confList);
|
void printConfList(ptConfList confList);
|
||||||
void addListenerToListenerList(ptListenerList listenerList, ptListener listener);
|
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);
|
void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade);
|
||||||
|
int confGradeAvg(ptConf conf);
|
||||||
|
int confParticipations(ptConf conf);
|
||||||
|
|
||||||
#endif // CONF_H
|
#endif // CONF_H
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1:3,2,1,6,11,12,13,14,15,16
|
1:1;12,2;12,12;0
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
void readConfs(ptConf confChain) {
|
void readConfs(ptConf confChain) {
|
||||||
FILE *file = fopen("./data/confs", "r");
|
FILE *file = fopen("./data/confs", "r");
|
||||||
char line[100];
|
char line[100];
|
||||||
char *tokens[6];
|
|
||||||
char *token;
|
char *token;
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
|
@ -15,17 +14,14 @@ void readConfs(ptConf confChain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file)) {
|
while (fgets(line, sizeof(line), file)) {
|
||||||
token = strtok(line, ",");
|
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, ","));
|
||||||
|
|
||||||
int i = 0;
|
addConf(confChain, id, title, speaker, day, month, year);
|
||||||
|
|
||||||
while (token != NULL && i < 6) {
|
|
||||||
tokens[i] = token;
|
|
||||||
i ++;
|
|
||||||
token = strtok(NULL, ",");
|
|
||||||
}
|
|
||||||
|
|
||||||
addConf(confChain, atoi(tokens[0]), tokens[1], tokens[2], atoi(tokens[3]), atoi(tokens[4]), atoi(tokens[5]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -34,7 +30,6 @@ void readConfs(ptConf confChain) {
|
||||||
void readListeners(ptListener listenerChain) {
|
void readListeners(ptListener listenerChain) {
|
||||||
FILE *file = fopen("./data/listeners", "r");
|
FILE *file = fopen("./data/listeners", "r");
|
||||||
char line[100];
|
char line[100];
|
||||||
char *tokens[4];
|
|
||||||
char *token;
|
char *token;
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
|
@ -43,17 +38,11 @@ void readListeners(ptListener listenerChain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file)) {
|
while (fgets(line, sizeof(line), file)) {
|
||||||
token = strtok(line, ",");
|
int id = atoi(strtok(line, ","));
|
||||||
|
char *name = strtok(NULL, ",");
|
||||||
int i = 0;
|
int day = atoi(strtok(NULL, ","));
|
||||||
|
int month = atoi(strtok(NULL, ","));
|
||||||
while (token != NULL && i < 4) {
|
addListener(listenerChain, id, name, day, month);
|
||||||
tokens[i] = token;
|
|
||||||
i ++;
|
|
||||||
token = strtok(NULL, ",");
|
|
||||||
}
|
|
||||||
|
|
||||||
addListener(listenerChain, atoi(tokens[0]), tokens[1], atoi(tokens[2]), atoi(tokens[3]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -62,10 +51,8 @@ void readListeners(ptListener listenerChain) {
|
||||||
void readRelations(ptConf confChain, ptListener listenerChain) {
|
void readRelations(ptConf confChain, ptListener listenerChain) {
|
||||||
FILE *file = fopen("./data/relations", "r");
|
FILE *file = fopen("./data/relations", "r");
|
||||||
char line[100];
|
char line[100];
|
||||||
char *tokens[50];
|
char *token1;
|
||||||
char *token;
|
char *token2;
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
printf("ça marche pas.");
|
printf("ça marche pas.");
|
||||||
|
@ -73,22 +60,13 @@ void readRelations(ptConf confChain, ptListener listenerChain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file)) {
|
while (fgets(line, sizeof(line), file)) {
|
||||||
token = strtok(line, ":");
|
int confId = atoi(strtok(line, ":"));
|
||||||
printf("%d\n", atoi(token));
|
|
||||||
|
|
||||||
i = 0;
|
while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) {
|
||||||
|
participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2));
|
||||||
while (token != NULL) {
|
|
||||||
tokens[i] = token;
|
|
||||||
i ++;
|
|
||||||
token = strtok(NULL, ",");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 1; j < i; j++) {
|
|
||||||
participateToConf(confChain, listenerChain, atoi(tokens[0]), atoi(tokens[j]));
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +102,7 @@ void saveRelations(ptConf confChain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (py -> next != NULL) {
|
while (py -> next != NULL) {
|
||||||
fprintf(file, "%d", py -> listener -> id);
|
fprintf(file, "%d;%d", py -> listener -> id, py -> grade);
|
||||||
if (py -> next -> next != NULL) {
|
if (py -> next -> next != NULL) {
|
||||||
fprintf(file, ",");
|
fprintf(file, ",");
|
||||||
} else {
|
} else {
|
||||||
|
|
BIN
main.exe
BIN
main.exe
Binary file not shown.
|
@ -83,10 +83,10 @@ void drawMenu(char *options[], int lenght) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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/ Retour"};
|
char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Suprimer une conference", "4/ Supprimer les conferences inferieures a une date", "5/ Retour"};
|
||||||
system("cls");
|
system("cls");
|
||||||
drawMenu(options, 4);
|
drawMenu(options, 5);
|
||||||
goToCoords(0, 12);
|
goToCoords(0, 13);
|
||||||
printf("Que voulez-vous faire ? : ");
|
printf("Que voulez-vous faire ? : ");
|
||||||
int choice;
|
int choice;
|
||||||
scanf("%d", &choice);
|
scanf("%d", &choice);
|
||||||
|
@ -94,21 +94,27 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
|
||||||
switch (choice)
|
switch (choice)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
system ("cls");
|
{
|
||||||
ptConf px = confChain;
|
ptConf px = confChain;
|
||||||
|
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
printf("id : %d\ntitle : %s\nspeaker : %s\n", px -> id, px -> title, px -> speaker);
|
printf("Id : %d\nTitre : %s\nConférencier : %s\n", px -> id, px -> title, px -> speaker);
|
||||||
printf("%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));
|
||||||
if (px -> listeners -> next != NULL ) {
|
if (px -> listeners -> next != NULL ) {
|
||||||
printListenerList(px -> listeners);
|
printListenerList(px -> listeners);
|
||||||
}
|
}
|
||||||
|
int avg;
|
||||||
|
if ((avg = confGradeAvg(px) != -1)) {
|
||||||
|
printf("Moyenne des notes : %d\n", confGradeAvg(px));
|
||||||
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
}
|
}
|
||||||
system("pause");
|
system("pause");
|
||||||
menuConf(confChain, listenerChain);
|
menuConf(confChain, listenerChain);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
|
@ -148,6 +154,33 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
|
{
|
||||||
|
int day, month, year, time;
|
||||||
|
printf("Jour : ");
|
||||||
|
scanf("%d", &day);
|
||||||
|
printf("Mois : ");
|
||||||
|
scanf("%d", &month);
|
||||||
|
printf("Annee : ");
|
||||||
|
scanf("%d", &year);
|
||||||
|
|
||||||
|
time = day + 31 * month * 365 * year;
|
||||||
|
|
||||||
|
ptConf px = confChain;
|
||||||
|
|
||||||
|
while(px -> next != NULL) {
|
||||||
|
if ((px -> day + px -> month * 31 + px -> year * 365) < time) {
|
||||||
|
ptConf py = px -> next;
|
||||||
|
removeConf(confChain, px -> id);
|
||||||
|
px = py;
|
||||||
|
} else {
|
||||||
|
px = px -> next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menuConf(confChain, listenerChain);
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
menu(confChain, listenerChain);
|
menu(confChain, listenerChain);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -168,7 +201,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
switch (choice)
|
switch (choice)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
system ("cls");
|
{
|
||||||
ptListener py = listenerChain;
|
ptListener py = listenerChain;
|
||||||
|
|
||||||
while (py -> next != NULL) {
|
while (py -> next != NULL) {
|
||||||
|
@ -182,6 +215,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
system("pause");
|
system("pause");
|
||||||
menuAbo(confChain, listenerChain);
|
menuAbo(confChain, listenerChain);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
|
@ -226,10 +260,10 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
|
||||||
|
|
||||||
void menu(ptConf confChain, ptListener listenerChain)
|
void menu(ptConf confChain, ptListener listenerChain)
|
||||||
{
|
{
|
||||||
char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Voir la participation a une conference", "6/ Quitter"};
|
char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Quitter"};
|
||||||
system("cls");
|
system("cls");
|
||||||
drawMenu(options, 6);
|
drawMenu(options, 5);
|
||||||
goToCoords(0, 14);
|
goToCoords(0, 13);
|
||||||
printf("Que voulez-vous faire ? : ");
|
printf("Que voulez-vous faire ? : ");
|
||||||
int choice;
|
int choice;
|
||||||
scanf("%d", &choice);
|
scanf("%d", &choice);
|
||||||
|
@ -246,27 +280,47 @@ void menu(ptConf confChain, ptListener listenerChain)
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
int confId, listenerId;
|
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 : ");
|
||||||
|
scanf("%d", &grade);
|
||||||
|
|
||||||
participateToConf(confChain, listenerChain, confId, listenerId);
|
participateToConf(confChain, listenerChain, confId, listenerId, grade);
|
||||||
saveRelations(confChain);
|
saveRelations(confChain);
|
||||||
menu(confChain, listenerChain);
|
menu(confChain, listenerChain);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
|
{
|
||||||
|
ptConf px = confChain;
|
||||||
|
int max = confGradeAvg(px);
|
||||||
|
ptConf confMax = px;
|
||||||
|
|
||||||
|
while (px -> next != NULL) {
|
||||||
|
int tmp = confGradeAvg(px);
|
||||||
|
if (tmp > max) {
|
||||||
|
confMax = px;
|
||||||
|
max = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
px = px -> next;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("La conférence la mieux notée est : %s\n\n", confMax -> title);
|
||||||
|
|
||||||
|
system("pause");
|
||||||
|
menu(confChain, listenerChain);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue