Lycée Pilote de Sousse
Devoir de Contrôle N° 1
Année scolaire : 2012/2013
Matière : Informatique Durée : 1H
Mr. Med Abdallah Mani Classe : 4 Math
Nom & Prénom : ……….
Note : ……. / 20
Exercice 1. (4 points) Donner la variable résultat, le résultat et son type de chacune des instructions suivantes :
Expression Résultat Type du Résultat
L long(‘’lycée’’) L= 5 Entier
Ch1 souschaine(‘’Baccalauréat’’,1,3) CH1=’’Bac’’ Chaine de caractéres
P pos(‘’a’’,’’Programmation’’) P =6 Entier
Ch2 ch1 + ‘’2013’’ CH2 =’’Bac2013’’ Chaine de caractéres
Efface (ch,1,5) où ch=’’Baccalauréat’’ CH = ‘’lauréat’’ Chaine de caractéres
Insère (‘’ga’’,ch,4) où ch=’’Lange’’ CH = ‘’Langage’’ Chaine de caractéres
Convch (2012, ch) CH = ‘’2012’’ Chaine de caractéres
Valeur (‘’5,26’’, n, e) N = 5.26 E = 0
Réel Entier Exercice 2. (2 points) Evaluer les expressions suivantes :
5 + 2 * 4 MOD 3 – 6 DIV 2 * 3
…………
-2
……… Pour a=60 et b=21 (a-b/3=69) OR (a MOD 2=0) AND NOT(b div 2 <> 1)
…………FAUX…………
NOT(‘D’<’A’) OR (succ(ord(‘A’))=pred(ord(‘B’)))
………VRAI…………
Pour a=13 et b=14 et c=3 NOT(b+15- a MOD 3 <a-10*c-b) XOR (c=a-b)
………… VRAI …………
Exercice 3. (4 points)
Ecrire l’algorithme d’une procédure Extract qui permet d’extraire les caractères non alphabétiques à partir d’une chaine donnée comme paramètre.
Exemple :
Pour la chaine ‘’a253M%xdMA$d2sS’’ il faut retourner la nouvelle chaine
‘’aMxdMAdsS’’
program Devoir;
uses WinCrt;
var ch:string;
procedure extract (var chf:string);
var i:byte;
begin i:=0;
repeat i:=i+1;
if not(upcase(ch[i]) in ['A'..'Z']) then begin
delete(ch,i,1);
i:=i-1;
end;
until i>length(ch);
end;
begin
writeln('Donner une chaine ch:');
readln(ch);
extract(ch);
writeln('La nouvelle chaine est :',ch);
end.
P a g e | 1
Problème.
(10 points)Ecrire l’analyse et l’algorithme du programme Devoir qui permet de remplir un tableau par n caractères alphabétiques dans l’ordre croissant puis de l’éclater en deux tableaux CONSONNES et VOYELLES.
Sachant que les indices du tableau vont de ‘’A’’ à ‘’Z’’.
Exemple.
Pour n = 10
A D H U a e f o x y
A B C D E F G H I J
Tableau de CONSONNES.
D H f x
A B C D
Tableau de VOYELLES.
A U a e o y
A B C D E F
program Devoir;
uses WinCrt;
var n:byte;
i,j,k:char;
ch:string;
t,tc,tv:array['A'..'Z'] of char;
begin repeat
writeln('Donner la taille du tableau entre 1 et 26');
readln(n);
until (n in [1..26]);
writeln('Donner T[A] un caractére alphabétique');
readln(t['A']);
for i:='B' to chr(ord('A')+n-1) do repeat
writeln('Donner T[',i,']=');
readln(t[i]);
until (t[i]>t[pred(i)]);
P a g e | 2
j:='A';
K:='A';
for i:='A' to chr(ord('A')+n-1) do
if upcase(t[i]) in ['A','E','I','U','O','Y'] then begin
tv[k]:=t[i];
k:=succ(k);
end else begin tc[j]:=t[i];
j:=succ(j);
end;
for i:='A' to chr(ord('A')+n-1) do write (t[i], ' | ');
writeln;
for i:='A' to pred(j) do write (tc[i], ' | ');
writeln;
for i:='A' to pred(k) do write (tv[i], ' | ');
end.
Correction Modulaire
program Devoir;
uses WinCrt;
type
tab=array['A'..'Z'] of char;
var
n:integer;
i,j,k:char;
t,tc,tv:tab;
procedure remplir(var nf:integer;var tf:tab);
begin repeat
writeln('Donner la taille du tableau entre 1 et 26');
readln(nf);
until (nf in [1..26]);
P a g e | 3
writeln('Donner T[A] un caractére alphabétique');
readln(tf['A']);
for i:='B' to chr(ord('A')+nf-1) do repeat
writeln('Donner T[',i,']=');
readln(tf[i]);
until (tf[i]>tf[pred(i)]);
end;
procedure affiche(tf:tab;cf:char);
begin
for i:='A' to cf do write (tf[i], ' | ');
end;
procedure trait (tf:tab;nf:integer;var tcf:tab;var jf:char;var tvf:tab;var kf:char);
begin jf:='A';
Kf:='A';
for i:='A' to chr(ord('A')+nf-1) do
if upcase(tf[i]) in ['A','E','I','U','O','Y'] then begin
tvf[kf]:=tf[i];
kf:=succ(kf);
end else begin
tcf[jf]:=tf[i];
jf:=succ(jf);
end;
end;
begin
remplir(n,t);
trait(t,n,tc,j,tv,k);
affiche(t,chr(ord('A')+n-1));
writeln;
affiche(tc,pred(j));
writeln;
affiche(tv,pred(k));
end.
P a g e | 4