Une solution de l'exercice 5 du TP6 d'informatique en DEUG MIAS+MASS S1
PROGRAM tp6exc5;
VAR mot,resultat : string[255];
i,j : integer;
choix : char;
c : char;
BEGIN
repeat
(* saisie du mot *)
write('mot (en majuscule) ? ') ; readln(mot);
repeat
(* menu et choix *)
writeln;
writeln('-1- laisser invariant ce mot');
writeln('-2- coder ce mot');
writeln('-3- décoder ce mot');
writeln('-4- changer de mot');
writeln('-0- terminer');
repeat
write('Votre choix ? ');
readln(choix);
until (choix>='0') and (choix<='4');
(* traitement du mot *)
resultat:='';
case choix of
'1' : resultat:=mot;
'2' : for i:=1 to length(mot) do
begin
c:=mot[i];
for j:=1 to (length(mot) mod 26) do c:=succ(c);
if (c>'Z') then c:=chr(ord(c)-26) ;
resultat:=resultat+c;
end;
'3' : for i:=1 to length(mot) do
begin
c:=mot[i];
for j:=1 to (length(mot) mod 26) do c:=pred(c);
if (c<'A') then c:=chr(ord(c)+26) ;
resultat:=resultat+c;
end;
end; { case }
(* affichage du résultat *)
if (choix>'0') and (choix<'4') then
begin
writeln;
mot:=resultat;
writeln('résultat : ',mot);
end;
until (choix='0') or (choix='4') ;
until choix='0' ;
END.