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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
| program GestionDuParcArboricole {Sébastien Degrève 1TL1};
uses crt;
CONST N = 1000;
TYPE Date = record
j,m,a : integer;
end;
TYPE Arbre = record
id : integer;
espece : integer;
d : Date;
taille : integer;
secteur : integer;
vie : boolean;
end;
VAR f : file of Arbre;
tab : array[1..N] of Arbre;
index_age : array[1..N] of integer;
index_taille : array[1..N] of integer;
ior : integer;
//a : arbre;
nr : integer;
choix : char;
////// ----------- Procedure affiche ------------ /////////
procedure affiche(a : Arbre);
begin
writeln('num id de l''arbre : ',a.id);
writeln('num id de l''espece : ',a.espece);
end;
////// ----------- Procedure init ------------ /////////
procedure init;
var i:integer;
begin
Assign(f,'C:\Documents and Settings\Sébastien\Bureau\arbre.data');
ior := IOResult;
writeln('ior = ',ior); // readln;
Reset(f);
ior := IOResult;
writeln('ior = ',ior); // readln;
if (ior <> 0) then Rewrite(f);
nr := filesize(f);
writeln('nr = ',nr);
writeln('file size : ',filesize(f));
for i:=1 to nr do
begin
read(f,tab[i]);
affiche(tab[i]);
end;
close(f);
end;
////// ----------- Procedure stat ------------ /////////
procedure stat;
var i,z:integer;
begin
ClrScr;
writeln(' Menu d''affichage par espece ');
writeln(' _______________________________');
writeln('');
for i:=1 to nr do
begin
//read(f,tab[i].espece);
writeln(i,'. ',tab[i].espece);
end;
writeln('');
writeln('Entrez le numero de l''espece souhaite');
readln(z);
for i:=1 to nr do
begin
read(f,tab[i]);
if z = tab[i].espece then
begin
if tab[i].vie = true then
writeln('ID :',tab[i].id,' ''est un ',tab[i].espece);
end;
readln;
end;
end;
////// ----------- Procedure Tri age ------------ /////////
procedure tri_age;
var i,j,tampon:integer;
var a1,a2:real;
begin
for i:=1 to nr-1 do
for j := i+1 to nr do
begin
a1:=(tab[index_age[i]].d.a *10000 + tab[index_age[i]].d.m *100 + tab[index_age[i]].d.j);
a2:=(tab[index_age[j]].d.a *10000 + tab[index_age[j]].d.m *100 + tab[index_age[j]].d.j);
if a1>a2 then
begin
tampon := index_age[i];
index_age[i] := index_age[j];
index_age[i] := tampon;
end;
end;
writeln();
writeln(' Menu d''affichage par age ');
writeln(' ______________________________ ');
writeln();
for i:=1 to nr do
begin
writeln('[',i,'] = ',tab[index_age[i]].d.j,'/',tab[index_age[i]].d.m,'/',tab[index_age[i]].d.a);
end;
readln;
end;
////// ----------- Procedure Tri taille ------------ /////////
procedure tri_taille;//(a : arbre);
var i,j,tampon:integer;
var t1,t2:integer;
begin
for i:=1 to nr-1 do
for j := i+1 to nr do
t1:=(tab[index_taille[i]].taille);
t2:=(tab[index_taille[j]].taille);
if t1>t2 then
tampon := index_taille[i];
index_taille[i] := index_taille[j];
index_taille[i] := tampon;
writeln();
writeln(' Menu d''affichage par taille ');
writeln(' ________________________________ ');
writeln();
for i:=1 to nr do
begin
writeln('[',i,'] = ',tab[index_taille[i]].taille);
end;
readln;
end;
////// ----------- Procedure affiche Id ------------ /////////
procedure id_screen;
var i,z:integer;
begin
Clrscr;
writeln();
writeln(' Menu d''affichage par ID ');
writeln(' ______________________________ ');
writeln();
writeln('Entrez L''ID de l''arbre :');
writeln();
readln(z);
writeln('Donnees pour l''ID :',z);
writeln();
for i:=1 to nr do
begin
if z = tab[i].id then
begin
if tab[i].vie = true then
writeln('ID :',tab[i].id);
writeln('espece num ',tab[i].espece);
writeln('taille : ',tab[i].taille,'mètre');
writeln('age : ',tab[i].d.a,'an');
writeln('secteur :', tab[i].secteur);
writeln();
if tab[i].vie = false then
writeln('C''est arbre est mort');
end;
end;
readln;
end;
////// ----------- Procedure affichage Secteur ------------ /////////
procedure secteur;
var i,z,s:integer;
begin
ClrScr;
writeln(' Menu d''affichage par secteur ');
writeln(' _______________________________');
writeln();
writeln('1. Nord');
writeln('2. Sud');
writeln('3. Ouest');
writeln('4. Est');
writeln();
writeln('Entrez le secteur souhaite :');
writeln();
readln(z);
for i:=1 to nr do
begin
if z = (tab[i].secteur) then
begin
if tab[i].vie = true then
writeln('ID :',tab[i].id);
writeln('espece num ',tab[i].espece);
writeln('taille : ',tab[i].taille,'mètre');
s := 2008-tab[i].d.a;
writeln('age : ',s,'an');
writeln();
end;
end;
readln;
end;
////// ----------- Procedure Suppression abre ------------ /////////
procedure delete;
var i,z : integer;
begin
ClrScr;
writeln();
writeln(' Menu suppression d''arbre ');
writeln(' ____________________________');
writeln();
writeln('Entrez l''id de l''arbre à supprimer ');
readln(z);
for i := 1 to nr do
if z = tab[i].id then
begin
tab[i].vie := false;
end;
readln();
end;
////// ----------- Procedure menu ------------ /////////
procedure menu ;
begin
ClrScr;
writeln(' _____________________________');
writeln(' | Menu de gestion du parc |');
writeln(' |_____________________________|');
writeln();
writeln(' 1. Ajouter un arbre'); // procédure ajout
writeln(' 2. Afficher les statistiques d''une espece'); // procédure stat
writeln(' 3. Afficher un arbre et son espece via son ID'); //procédure id screen
writeln(' 4. Tri des arbres en fonction de leur age'); //procédure age
writeln(' 5. Tri des arbres en fonction de leur taille');//procédure taille
writeln(' 6. Affichage des abres par secteur'); //procédure secteur
writeln(' 7. Supprimer un arbre'); //procédure delete
writeln();
writeln(' 8. Creation aleatoire d''arbre');
writeln();
writeln(' 0. quitter');
writeln();
write(' Choix : ');
end;
////// ----------- Procedure ajout ------------ /////////
procedure ajout ;
begin
nr := nr+1;
writeln('nr = ',nr);
tab[nr].id:=nr;
Clrscr;
writeln();
writeln(' Menu d''ajout d''arbre ');
writeln(' _________________________');
writeln();
writeln();
writeln(' L''ID du nouvel arbre sera ',tab[nr].id);
writeln();
writeln();
writeln('Saisie des donnees');
writeln('__________________');
writeln();
writeln('1. Entrez l''espece');
readln(tab[nr].espece);
writeln('2.1 Entrez l''age (annee)');
readln(tab[nr].d.a);
writeln('2.2 Entrez l''age (mois)');
readln(tab[nr].d.m);
writeln('2.3 Entrez l''age (jour)');
readln(tab[nr].d.j);
writeln('3. Entrez la taille');
readln(tab[nr].taille);
writeln('4. Entrez le secteur (1. Nord / 2. Sud / 3. Ouest / 4. Est)');
readln(tab[nr].secteur);
tab[nr].vie := true;
writeln();writeln();
writeln('Encodage réussi avec succès');
writeln();
writeln('MERCI - retour menu');
readln;
end;
////// ----------- Procedure cloture ------------ /////////
procedure cloture;
var i:integer;
begin
Assign(f,'C:\Documents and Settings\Sébastien\Bureau\arbre.data');
ior := IOResult; writeln('ior = ',ior); //readln;
Rewrite(f);
ior := IOResult; writeln('ior = ',ior); //readln;
for i:=1 to nr do
begin
write(f,tab[i]);
ior := IOResult; writeln('ior = ',ior); readln;
writeln('On a écrit dans le fichier : ',tab[i].id,' ',
tab[i].espece);
end;
close(f);
// readln; //a dé-commenter pour voir le test ior
end;
////// ----------- Création aléatoire d'arbre ------------ /////////
procedure creation;
var i: integer;
begin
init;
for i:= 1 to random(20)+5 do
begin
nr:=nr+1;
tab[nr].id:=nr;
tab[nr].espece:=random(4);
tab[nr].d.a:=random(200)+1808;
tab[nr].d.m:=random(12)+1;
tab[nr].d.j:=random(30)+1;
tab[nr].taille:=random(24)+6;
tab[nr].secteur:=random(4);
tab[nr].vie := true;
end;
cloture;
end;
////// ----------- Programme principale ------------ /////////
BEGIN
init;
repeat
menu;
readln(choix);
case choix of
'1' : begin
ajout;
end;
'2' : begin
stat;
end;
'3' : begin
id_screen;
end;
'4' : begin
tri_age;
end;
'5' : begin
tri_taille;
end;
'6' : begin
secteur;
end;
'7' : begin
delete;
end;
'8' : begin
creation;
end;
end;
until choix = '0';
readln;
cloture;
END. |
Partager