Newer
Older
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// relations.c : definit le point d'entree pour l'application .
//
typedef int bool;
#define false 0
#define true -1
#include "stdlib.h"
#include "memory.h"
#include "stdio.h"
#include "string.h"
////////////////////////////////////////
// Exercice 1: Classement des Relations
typedef enum{
FRERE = 2, COUSIN, PARENT, ONCLE, EPOUX, AMI, VIT, CONNAIT,
CHEF, COLLEGUE, LOCATAIRE, TRAVAILLE, PROPRIETAIRE, SITUE, DECOUVERT
}rtype;
bool est_lien_parente(rtype id){
return false;
}
bool est_lien_professionel(rtype id){
return false;
}
bool est_lien_connaissance(rtype id){
return false;
}
char* toStringRelation(rtype id){
return "";
}
////////////////////////////////////////
// Exercice 2: Liste de pointeurs
typedef struct s_node{
void *val; // pointeur vers objet quelconque
struct s_node *suiv;
}*listeg;
listeg listegnouv(){
return NULL;
}
listeg adjtete(listeg lst, void *x){
return lst;
}
listeg adjqueue(listeg lst, void *x){
return lst;
}
listeg suptete(listeg lst){
return lst;
}
void *tete(listeg lst){
return NULL;
}
int longueur(listeg lst){
return -1;
}
bool estvide(listeg lst){
return false;
}
void detruire(listeg lst){
}
listeg rech(listeg lst, void *x, int(*comp)(void *, void *)){
return NULL;
}
////////////////////////////////////////
// Exercice 3: Construction du graphe
#define LONG_NOM_MAX 64
typedef enum{
PERSONNE=1, OBJET, ADRESSE, VILLE
}etype;
typedef struct s_entite{
char nom[LONG_NOM_MAX]; // le nom de l�entit� p.ex � Peugeot 106 �
etype ident; // l�identifiant associ�, p.ex OBJET
}*Entite;
//3.1 les structures de donn�es
typedef struct s_sommet{
// A DEFINIR
}*Sommet;
typedef struct s_arc{
// A DEFINIR
}*Arc;
typedef struct s_relations{
// A DEFINIR
}*Relations;
//3.2 les constructeurs
Entite creerEntite(char *s, etype e){
return NULL;
}
Sommet nouvSommet(Entite e){
return NULL;
}
Arc nouvArc(Entite e, rtype type){
return NULL;
}
void relationInit(Relations *g){
}
void relationFree(Relations *g){
}
//3.3 les comparaisons
int compEntite(void *e, void *string){
return 0;
}
int compSommet(void *s, void *string){
return 0;
}
int compArc(void *a, void *string){
return 0;
}
//3.4 ajout d'entites et de relations
void adjEntite(Relations g, char *nom, etype t){
}
// PRE CONDITION: id doit �tre coh�rent avec les types des sommets correspondants � x et y
// p.ex si x est de type OBJET, id ne peut pas etre une relation de parente
// PRE CONDITION: strcmp(nom1,nom2)!=0
void adjRelation(Relations g, char *nom1, char *nom2, rtype id){
}
////////////////////////////////////////
// Exercice 4: Explorer les relations entre personnes
// 4.1 listes de relations
listeg en_relation(Relations g, char *x){
return NULL;
}
listeg chemin2(Relations g, char *x, char *y){
return NULL;
}
// 4.2 verifier un lien de parente
// PRE CONDITION: strcmp(x,y)!=0
bool ont_lien_parente(Relations g, char *x, char *y){
return false;
}
// 4.3 tester connaissances
// PRE CONDITION: les sommets correspondants � x et y sont de type PERSONNE
// PRE CONDITION: strcmp(x,y)!=0
bool se_connaissent(Relations g, char *x, char *y){
return false;
}
// PRE CONDITION: les sommets correspondants � x et y sont de type PERSONNE
// PRE CONDITION: strcmp(x,y)!=0
bool se_connaissent_proba(Relations g, char *x, char *y){
return false;
}
// PRE CONDITION: les sommets correspondants � x et y sont de type PERSONNE
// PRE CONDITION: strcmp(x,y)!=0
bool se_connaissent_peutetre(Relations g, char *x, char *y){
return false;
}
////////////////////////////////////////
// Exercice 5: Affichages
void affichelg(listeg l, void(*aff)(void *)){
}
void afficheEntite(void *x){
}
void afficheArc(void *x){
}
////////////////////////////////////////
// Exercice 6: Parcours
void affiche_degre_relations(Relations r, char *x){
}
int main(){
int i,j;
Relations r; relationInit(&r);
// ajouter les entites de l'exemple
char *tabe[] ={"KARL","LUDOVIC","CELINE","CHLOE","GILDAS","CEDRIC","SEVERINE",
"PEUGEOT 106" ,"1, RUE DE LA RUE","STRASBOURG" };
for (i = 0; i < 7; i++) adjEntite(r, tabe[i], PERSONNE);
adjEntite(r, tabe[7], OBJET);
adjEntite(r, tabe[8], ADRESSE);
adjEntite(r, tabe[9], VILLE);
// ajouter les relations de l'exemple
adjRelation(r, tabe[0], tabe[1], FRERE);
adjRelation(r, tabe[0], tabe[2], AMI);
adjRelation(r, tabe[0], tabe[3], CONNAIT);
adjRelation(r, tabe[0], tabe[5], COUSIN);
adjRelation(r, tabe[0], tabe[7], PROPRIETAIRE);
adjRelation(r, tabe[0], tabe[8], PROPRIETAIRE);
adjRelation(r, tabe[3], tabe[4], VIT);
adjRelation(r, tabe[5], tabe[6], EPOUX);
adjRelation(r, tabe[5], tabe[8], LOCATAIRE);
adjRelation(r, tabe[7], tabe[8], DECOUVERT);
adjRelation(r, tabe[8], tabe[9], SITUE);
// explorer les relations
printf("%s est en relation avec:\n", tabe[0]);
affichelg(en_relation(r, tabe[0]),afficheArc);
printf("\n");
for (i = 0; i < 7; i++) for (j = i + 1; j < 10; j++)
{
printf("<%s> et <%s> ont les relations communes:\n", tabe[i], tabe[j]);
listeg ch = chemin2(r, tabe[i], tabe[j]);
affichelg(ch, afficheEntite);
printf("\n");
detruire(ch);
}
printf("\n\n");
for (i = 0; i < 10; i++) for (j = i + 1; j < 10; j++)
{
printf("<%s> et <%s> ont lien de parente: %s\n",
tabe[i], tabe[j], ont_lien_parente(r, tabe[i], tabe[j]) ? "vrai" : "faux");
}
printf("\n");
for (i = 0; i < 7; i++)
{
for (j = i + 1; j < 7; j++)
{
printf("<%s> et <%s> se connaissent: %s\n",
tabe[i], tabe[j], se_connaissent(r, tabe[i], tabe[j]) ? "vrai" : "faux");
printf("<%s> et <%s> se connaissent tres probablement: %s\n",
tabe[i], tabe[j], se_connaissent_proba(r, tabe[i], tabe[j]) ? "vrai" : "faux");
printf("<%s> et <%s> se connaissent peut etre: %s\n",
tabe[i], tabe[j], se_connaissent_peutetre(r, tabe[i], tabe[j]) ? "vrai" : "faux");
}
printf("\n");
}
affiche_degre_relations(r, tabe[3]);
relationFree(&r);
printf("\nPRESS RETURN\n");
char buff[64]; fscanf(stdin, "%s", buff);
return 0;
}