This commit is contained in:
Lukian LEIZOUR 2023-11-27 16:14:53 +01:00
parent c755619819
commit 63e83a9601
6 changed files with 153 additions and 85 deletions

46
conf.c
View file

@ -147,7 +147,7 @@ void removeListener(ptListener listenerChain, int id) {
}
}
void addConfToConfList(ptConfList confList, ptConf conf) {
void addConfToConfList(ptConfList confList, ptConf conf, int grade) {
ptConfList px = confList;
while (px -> next != NULL) {
@ -156,6 +156,7 @@ void addConfToConfList(ptConfList confList, ptConf conf) {
px -> conf = conf;
px -> next = (ptConfList) malloc(sizeof(tConfList));
px -> grade = grade;
px -> next -> next = NULL;
}
@ -164,13 +165,13 @@ void printConfList(ptConfList confList) {
printf("Participation aux conferences : ");
while (px -> next != NULL) {
printf("%s ", px -> conf -> title);
printf("%s(%d) ", px -> conf -> title, px -> grade);
px = px -> next;
}
printf("\n");
}
void addListenerToListenerList(ptListenerList listenerList, ptListener listener) {
void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) {
ptListenerList px = listenerList;
while (px -> next != NULL) {
@ -179,6 +180,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener)
px -> listener = listener;
px -> next = (ptListenerList) malloc(sizeof(tListenerList));
px -> grade = grade;
px -> next -> next = NULL;
}
@ -187,13 +189,13 @@ void printListenerList(ptListenerList listenerList) {
printf("Participants : ");
while (px -> next != NULL) {
printf("%s ", px -> listener -> name);
printf("%s(%d) ", px -> listener -> name, px -> grade);
px = px -> next;
}
printf("\n");
}
void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId) {
void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) {
ptConf px = confChain;
ptListener py = listenerChain;
ptListenerList pz;
@ -218,6 +220,36 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i
return;
}
addListenerToListenerList(px -> listeners, py);
addConfToConfList(py -> confs, px);
addListenerToListenerList(px -> listeners, py, grade);
addConfToConfList(py -> confs, px, grade);
}
int confGradeAvg(ptConf conf) {
ptListenerList px = conf -> listeners;
int total = 0, nb = 0;
while (px -> next != NULL) {
total += px -> grade;
nb++;
px = px -> next;
}
if (nb != 0) {
return total / nb;
} else {
return -1;
}
}
int confParticipations(ptConf conf) {
ptListenerList px = conf -> listeners;
int nb = 0;
while (px -> next != NULL) {
nb++;
px = px -> next;
}
return nb;
}