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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
|
program exercice2;
uses crt;
type date = record
jj:integer;
mm:integer;
annee:integer;
end;
ouvrage = record
num_isbn:string;
titre:string;
annee:integer;
paru:integer;
maison_edition:string;
end;
//tableau pour ouvrage
tableau = array[1..999] of ouvrage;
personne = record
num_id:integer;
nom:string[20];
prenom:string[15];
date_nais:date;
etat:string;
date_dec:date;
nation:string[10];
nombre_ouvrage : integer;
list_ouvr:tableau;
end;
{Fichier d'enregistrements}
fic =file of personne;
var reponse , choix_1 , i , j, n :integer;
choix_2 : char;
rep:fic;
tab:tableau;
//declaration de la constante nulle
const
aucun : ouvrage = (num_isbn: '';titre:'' ;annee: 0;paru: 0;maison_edition:'');
{Attente d'une touche au clavier}
PROCEDURE pause;
begin
writeln;writeln('Presser une touche...');
readkey;
clrscr;
end;
{ Verification du fichier de donnees f}
PROCEDURE creationfichier(var f: fic);
var choix: integer;
begin
writeln;
repeat
write(' Detruire le fichier existant (1) ou Annuler (2) ? ');
readln(choix);
until (choix=1) or (choix=2);
if choix=1 then
begin
rewrite(f);
close(f);
writeln;writeln(' Ok.'); pause;
end;
end;
//procedure pour ajouter
procedure ajouter_auteur(var f:fic);
var
nouveau : personne;
begin
{Positionnement en fin de fichier}
reset(f);
seek(f,filesize(f));
{Saisie}
writeln;
with nouveau do
begin
writeln(' #: ', filepos(f)+1);
write('donner le numero d''identification de l''auteur : '); readln(num_id);
while(num_id < 1) or (num_id > 9999) do
begin
writeln('entrez un entier compris entre 1 et 9999');
read(num_id);
end;
write('donner son nom : '); readln(nom);
write('donner son prenom :'); readln(prenom);
writeln('donner la date de naissance (JJ/MM/ANNEE) ');
readln(date_nais.jj);
//pour la verification du jour
while(date_nais.jj<1) or (date_nais.jj>31) do
begin
writeln('entrez un jour valide ');
read(date_nais.jj);
end;
//pour la verification du mois
readln(date_nais.mm);
while(date_nais.mm<1) or (date_nais.jj>12) do
begin
writeln('entrez un mois valide entre 1 et 12 SVP ');
read(date_nais.jj);
end;
//pour la verification de l'année
readln(date_nais.annee);
while(date_nais.annee < 1900) or (date_nais.annee > 2016) do
begin
writeln('entrez une anne',chr(130),' entre 1900 et 2016 SVP ');
read(date_nais.annee);
end;
//question pour savoir si l'auteur est vivant ou mort
repeat
writeln('L''auteur est il d',chr(130),'ced',chr(130),' ? Entrez 0 pour oui ou 1 pour NON ?');
readln(reponse);
until (reponse = 0 ) or (reponse = 1 ) ;
etat :='vivant';
//si il est decedé
if (reponse = 0 ) then
begin
etat :='decede';
writeln('entrez la date du deces ');
read(date_nais.jj);
while(date_dec.jj<1) or (date_dec.jj>31) do
begin
writeln('entrez un jour valide ');
read(date_nais.jj);
end;
read(date_dec.mm);
readln(date_dec.annee);
end;
writeln('entrez sa nationalit',chr(130),' ');
readln(nation);
writeln('entrez le nombre d''ouvrage produit ');
readln(nombre_ouvrage);
while (nombre_ouvrage< 0) or (nombre_ouvrage>20) do
begin
writeln('entrez le nombre d''ouvrage produit (20 au plus)');
readln(nombre_ouvrage);
end;
for i:=1 to nombre_ouvrage do
begin
writeln('entrez le numero ISBN de livre : #',i);
readln(list_ouvr[i].num_isbn);
writeln('entrez le titre #',i);
readln(list_ouvr[i].titre);
writeln('entrez l''anne',chr(130),' de parution #',i);
readln(list_ouvr[i].paru);
writeln('entrez le nom de la maison d''edition ',i);
readln(list_ouvr[i].maison_edition);
writeln;writeln;
{Stockage}
write(f,nouveau);
end;
end;
end;
//ajouter un ouvrage à un auteur
procedure ajout_ouvrage(var f: fic);
var auteur:integer;
r: personne;
c: integer;
begin
writeln('entrez le numero ID de l''auteur :');
read(auteur);
writeln;
reset(f);
c:=0;
while not eof(f) do
begin
read(f,r);
if (r.num_id = auteur) then
begin
r.nombre_ouvrage := r.nombre_ouvrage +1;
writeln('entrez le numero ISBN de livre : #',i);
readln(r.list_ouvr[i].num_isbn);
writeln('entrez le titre #',i);
readln(r.list_ouvr[i].titre);
writeln('entrez l''anne',chr(130),' de parution #',i);
readln(r.list_ouvr[i].paru);
writeln('EDITION : ');
readln(r.list_ouvr[i].maison_edition);
writeln;writeln;
{Stockage}
write(f,r);
c:=c+1;
end;
end;
close(f);
if c=0 then writeln('Pas de correspondance , Veuillez essayer un autre ...');
pause;
end;
{Suppression à partir du numero id de l'auteur}
PROCEDURE supprimer_auteur(var f: fic);
var num,c:integer;
r:personne;
f2:fic;
begin
writeln('numéro ID de l''auteur');
readln(num);
//on assigne un nouveau nom et on creer le fichier en l'ouvrant lecture
assign(f2,'temp.dat');
rewrite(f2);
reset(f);
//tant qu'on atteint pas la fin du fichier
c:=0;
while not eof(f) do
begin
seek(f,c);
read(f,r);
if r.num_id <> num then //on deplace tous les auteurs avec un num_id differents dans le nouveau fichier
begin
write(f2,r);
end;
c:=c+1;
end;
close(f);
close(f2);
//on supprime le fichier original
erase(f);
//on renome l''ancien fichier
rename(f2,'auteur.dat');
if c=0 then writeln('Pas de correspondance , Veuillez essayer un autre ...');
end;
{Suppression une oeuvre}
PROCEDURE supprimer_oeuvre(var f: fic);
var num:string;
c:integer;
r:personne;
begin
writeln('numéro ISBN de lu livre');
readln(num);
reset(f);
//tant qu'on atteint pas la fin du fichier
c:=0;
while not eof(f) do
begin
seek(f,c);
read(f,r);
if r.list_ouvr[i].num_isbn = num then r.list_ouvr[i] := aucun;
c:=c+1;
end;
close(f);
if c=0 then writeln('Pas de correspondance , Veuillez essayer un autre ...');
end;
{Recherche dans le fichier f }
PROCEDURE recherche_annee(var f: fic);
var annee: integer;
r: personne;
c: integer;
begin
writeln;
write('Entrez une anne',chr(130),' pour obtenir les informations : '); readln(annee);
{Parcours de f avec affichage des auteurs}
writeln;
reset(f);
c:=0;
while not eof(f) do
begin
read(f,r);
if (r.date_nais.annee = annee ) or (r.date_dec.annee = annee ) then
begin
writeln('======================================================================================');
writeln(filepos(f),') AUTEUR : ', r.nom,' ', r.prenom,' NATIONALITE ', r.nation, ' ETAT : ',r.etat );
c:=c+1;
end;
end;
close(f);
if c=0 then writeln('Pas de correspondance , Veuillez essayer un autre ...');
pause;
end;
//pour la recherche sur un auteur concernant son ISBN
PROCEDURE recherche_isbn(var f: fic);
var isbn: string;
r: personne;
c: integer;
begin
writeln;
write('Entrez l''ISBN : '); readln(isbn);
{Parcours de f avec affichage des auteurs}
writeln;
reset(f);
c:=0;
while not eof(f) do
begin
read(f,r);
if (r.list_ouvr[i].num_isbn = isbn) then
if (r.etat ='vivant' ) then
begin
begin
writeln('=========================================================================');
writeln(filepos(f),'. ',r.list_ouvr[i].titre);
writeln('NOM : ', r.nom,' PREONOM: ', r.prenom,' NATIONALITE ', r.nation, ' NOMBRE D''OUVRAGES : ',r.nombre_ouvrage );
writeln('ne : ',r.date_nais.jj,'/',r.date_nais.mm,'/',r.date_nais.annee );
writeln('EDITION : ',r.list_ouvr[i].maison_edition);
c:=c+1;
end;
end;
end;
close(f);
if c=0 then writeln('Pas de correspondance , Veuillez essayer un autre ...');
pause;
end;
//pour l'affichage du sous menu 2
procedure affichage_sm_2();
begin
clrscr;
gotoxy(18,7);
writeln('OPERATIONS SUR LA BASE***');
gotoxy(20,9);
writeln('a: liste des auteurs d''un etat donne');
gotoxy(20,11);
writeln('b : informations sur l''auteur d''un ouvrage connu par son ISBN');
gotoxy(20,13);
writeln('c : ajout d''un auteur');
gotoxy(20,15);
writeln('d : ajout d''un ouvrage d''un auteur donnee');
gotoxy(20,17);
writeln('e: supprimer un auteur ');
gotoxy(20,19);
writeln('f: supprimer un ouvrage ');
gotoxy(20,21);
writeln('QUE VOULEZ VOUS FAIRE ?');
gotoxy(20,23);
readln(choix_2);
case choix_2 of
'a':begin
clrscr;
recherche_annee(rep);
end;
'b' :begin
clrscr;
recherche_isbn(rep);
end;
'c' :begin
clrscr;
ajouter_auteur(rep);
end;
'd':begin
clrscr;
ajout_ouvrage(rep);
end;
'e':begin
clrscr;
supprimer_auteur(rep);
pause;
end;
'f':begin
clrscr;
supprimer_oeuvre(rep);
pause;
end;
end;
end;
{Programme principal}
begin
{ Initialisations}
assign(rep,'auteur.dat');
//menu
repeat
clrscr;
writeln;
gotoxy(13,03);
writeln('---------------------------------------------------------');
for j:=4 to 22 do
begin
gotoxy(13,J);
writeln('-');
gotoxy(70,j);
writeln('-');
end;
gotoxy(20,7);
writeln('**Menu **************************** AUTEURS **');
gotoxy(20,11);
writeln('1:** Creation de la base ');
gotoxy(20,13);
writeln('2:** Operations sur la base ');
gotoxy(20,15);
writeln(' **Que voulez vous faire ? (1,2) **');
gotoxy(13,23);
writeln('---------------------------------------------------------');
gotoxy(17,19);
readln(choix_1);
case choix_1 of
1:begin
clrscr;
creationfichier(rep);
writeln('entrez le nombre d''enregistrement a effectuer');
readln(n);
for i:= 1 to n do
begin
ajouter_auteur(rep);
end;
end;
2:begin
affichage_sm_2();
end;
end;
until choix_1 = 0 ;
readln;
end. |
Partager