-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmeuble.c
66 lines (58 loc) · 2.18 KB
/
immeuble.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "data/immeuble.h"
// Fonction pour initialiser un étage
void initialiser_etage(Etage *etage, int numero, const char *activites[], int nombre_activites) {
etage->numero_etage = numero;
etage->nombre_activites = nombre_activites;
for (int i = 0; i < nombre_activites; i++) {
etage->activites[i] = (char *)malloc(strlen(activites[i]) + 1);
strcpy(etage->activites[i], activites[i]);
}
}
// Fonction pour initialiser l'immeuble
void initialiser_immeuble(Immeuble *immeuble) {
const char *activites_par_etage[NOMBRE_ETAGES][MAX_ACTIVITES] = {
{"Entree principale"},
{"Bureau", "Salle d'attente"},
{"Salle de reunion"},
{"Cafeteria"},
{"Bureau", "Archives"},
{"Bureau"},
{"Salle de reunion"},
{"Cafeteria", "Coin detente"},
{"Bureau", "Open Space"},
{"Terrasse"}
};
const int nombre_activites_par_etage[NOMBRE_ETAGES] = {
1, 2, 1, 1, 2, 1, 1, 2, 2, 1
};
for (int i = 0; i < NOMBRE_ETAGES; i++) {
initialiser_etage(&immeuble->etages[i], i, activites_par_etage[i], nombre_activites_par_etage[i]);
}
}
// Fonction pour afficher les détails de l'immeuble
void afficher_immeuble(const Immeuble *immeuble) {
for (int i = 0; i < NOMBRE_ETAGES; i++) {
printf("Étage %d : ", immeuble->etages[i].numero_etage);
for (int j = 0; j < immeuble->etages[i].nombre_activites; j++) {
printf("%s", immeuble->etages[i].activites[j]);
if (j < immeuble->etages[i].nombre_activites - 1) {
printf(", ");
}
}
printf("\n");
}
}
// Fonction pour avoir toute les activités pour un étage spécifique
void activites_pour_etage(int etage, const Immeuble *immeuble) {
printf("Activités pour l'étage %d : ", etage);
for (int i = 0; i < immeuble->etages[etage].nombre_activites; i++) {
printf("%s", immeuble->etages[etage].activites[i]);
if (i < immeuble->etages[etage].nombre_activites - 1) {
printf(", ");
}
}
printf("\n");
}