Accueil     Soft. MacOSX     Soft. MacOS/PC     PHP     Python     ROMS GBA     TP d'info     DBZ-GT     Martingales     Galeries     Liens     @  

Exercice 5

program exo5_ligne_briser;
const
max = 10;
type
point = record
lettre: char;
x, y: real;
end;
ligne = record
nb: 1..10;
tab: array[1..max] of point;
end;

var
l, m: ligne;
i, j, p, q: integer;
s, min: real;

function longueur (a, b: point): real;
begin
longueur := sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
end;
{ Fin de 'longueur' }

function somme (a: ligne): real;
var
i: integer;
s: real;
begin
s := 0;
for i := 1 to a.nb - 1 do
s := s + longueur(a.tab[i], a.tab[i + 1]);
somme := s;
end;
{ Fin de 'somme' }

begin
writeln('Exercice 5 - http://www.Software-DS.com');
{ initialisation des données }
{ initialisation de la ligne brisée l }

l.nb := 3;
l.tab[1].lettre := 'A';
l.tab[1].x := 2.1;
l.tab[1].y := 5;
l.tab[2].lettre := 'B';
l.tab[2].x := 3.5;
l.tab[2].y := 7;
l.tab[3].lettre := 'C';
l.tab[3].x := 5.0;
l.tab[3].y := 8.5;

{ initialisation de la ligne brisée m }
m.nb := 4;
m.tab[1].lettre := 'D';
m.tab[1].x := 0;
m.tab[1].y := 0.5;
m.tab[2].lettre := 'E';
m.tab[2].x := 1.5;
m.tab[2].y := 1.1;
m.tab[3].lettre := 'F';
m.tab[3].x := 2.5;
m.tab[3].y := 3;
m.tab[4].lettre := 'G';
m.tab[4].x := 5.5;
m.tab[4].y := 4.6;

{ Question d: }
writeln('La longueur de la ligne brisée l est : ', somme(l) : 4);
writeln('La longueur de la ligne brisée m est : ', somme(m) : 4);

{ Question e: }
min := 100;
{ on iniatilise la distance la + courte }
for i := 1 to 3 do
for j := 1 to 4 do
begin
s := longueur(l.tab[i], m.tab[j]);
if s < min then
begin
p := i;
{ mémorisation des points de l et m }
q := j;
min := s;
{ nouveau minimum }
end;
end;
writeln;
writeln('La distance [', l.tab[p].lettre, m.tab[q].lettre, '] est la plus courte;');
writeln;
writeln('©2001 All Rights Reserved to www.Software-DS.com');
{ ©2001 All Rights Reserved to http://www.Software-DS.com 16/10/01 }
end.





Haut de la page - Page précédente - Page générée en 0.00195 sec.
Recherche personnalisée
 

1843945 visiteurs.   ©2001-2023 All Rights Reserved to Software-DS.com
Made with a mac  
Confidentialité