• Aucun résultat trouvé

Note : ……. / 20

N/A
N/A
Protected

Academic year: 2022

Partager "Note : ……. / 20"

Copied!
4
0
0

Texte intégral

(1)

Lycée Pilote de Sousse

Devoir de Contrôle N° 2

Année scolaire : 2011/2012

Matière : Informatique Durée : 1H

Mr. Med Abdallah Mani Classe : 4 Tech

Nom & Prénom : ……….

Note : ……. / 20

Exercice 1. (4 points)

Soit la fonction suivante écrite en Pascal :

FUNCTION Traitement (d, f : integer ; T : tab) :integer ; VAR

m :integer ; BEGIN

m : = d;

FOR i : = d + 1 TO f DO IF T[i] < T[m] THEN

Begin

m : = i;

End;

Traitement : = m;

End;

Questions:

1/ Déterminer et compléter le nom et le type de cette fonction ainsi que la partie déclaration des variables locales.

2/ Quelle est la valeur renvoyée par la fonction Traitement si d=2, f=5 et le tableau T contient les éléments suivants :

T -10 5 0 -6 10 13

i 1 2 3 4 5 6

………traitement =4………

3/ Quel est le rôle de cette fonction ?

………rechercher le l’indice du minimum dans la partie du tableau T entre l’indice d et f………

4/ Compléter le tableau suivant :

Fonction Résultat

Trunc (10.23) 10

Round (10.50) 11

Frac (10.23) 0.23

Int (10.23) 10.00

Exercice 2. (4 points)

(2)

Proposer deux solutions au problème en utilisant 2 structures itératives différentes

Enlever tous les espaces d’une chaîne de

caractère.

Exemple : Si

ch = ‘Le devoir est facile’

Après exécution, Ch sera : ch = ‘Ledevoirestfacile’

Solution1

program espace ; uses wincrt;

var ch: string ; i,n : integer ;

begin

writeln('Donner une chaine :');

readln(ch);

n:=length(ch);

for i:=1 to n do begin if ch[i]=' ' then delete(ch,i,1);

n:=length(ch);

end;

writeln('la nouvelle chaine est : ', ch);

end.

Solution2

program espace ; uses wincrt;

var ch: string ; i,n : integer ;

begin

writeln('Donner une chaine :');

readln(ch);

n:=length(ch);

i:=1;

while i<=n do begin if ch[i]=' ' then

delete(ch,i,1);

inc(i);

n:=length(ch); end;

writeln('la nouvelle chaine est : ', ch);

end.

Solution3

program espace ; uses wincrt;

var ch: string ; i,n : integer ;

begin

writeln('Donner une chaine :');

readln(ch);

n:=length(ch);

i:=1;

repeat if ch[i]=' ' then

delete(ch,i,1);

inc(i);

until (i>length(ch));

writeln('la nouvelle chaine est : ', ch);

end.

Problème (12 points)

Ecrire un programme intitulé Insertion qui permet de :

- saisir une chaîne CH (minimum 10 caractères maximum 20 caractères) - de trier les éléments par code ASCII

- de lire un caractère C et vérifier son existence dans la chaîne : s’il existe, afficher à quelle position, sinon, l'insérer à sa bonne position dans la chaîne et afficher le résultat d'insertion.

Exemple : Pour CH = " Bacblanc2012"

Si C = "B"

Alors le programme affiche la chaîne : ‘B existe à la position 5’.

Si C = "A"

Alors le programme affiche la chaîne : "0122ABaabccln"

Questions

1. Analyser ce problème en le décomposant en modules (programme principal ainsi que chacun des modules envisagés).

2. En déduire les algorithmes correspondants.

Traduction Pascal : program insertion ; uses wincrt;

var

ch: string;

i,n : integer ; c:char;

procedure saisie(var fch:string);

(3)

begin repeat

writeln('Donner une chaine dont la longueur entre 10 et 20');

readln(fch);

until (length(fch) in [10..20]);

end;

Procedure permuter( var a:char; var b:char);

Var P : char;

begin p:=a;

a:=b;

b:=p;

end;

Procedure tri(var fch:string);

Var changer : boolean;

i,n: integer;

begin

n:=length(ch);

repeat

changer:=false;

for i:=1 to n-1 do

if fch[i] > fch[i+1] then begin

permuter (fch[i] ,fch[i+1]);

changer:=true;

end;

n := n-1 ;

until (n=1) or (changer = false);

end;

procedure inser(fc:char; var fch:string);

var i:integer;

begin

i:=length(fch);

while (fch[i] >fc) and (i>=1) do

(4)

begin

fch[i+1]:= fch[i];

i:= i-1;

end;

fch[i+1]:=fc;

end;

begin

saisie (ch);

tri(ch);

writeln(ch);

writeln('Donner un caractére :');

readln(c);

if pos(c,ch)<>0 then

writeln(c,' existe à la position ',pos(c,ch)) else

begin

inser(c,ch);

writeln(ch);

end;

end.

Références

Documents relatifs

2/ Analyser chacun des modules proposés et déduire l'algorithme du programme principal.

Corollaire 3.2.5 Tout module de de type fini sur un anneau principal est somme directe de son sous-module de torsion et d’un module

Le tableau ci-dessous récapitule l’ensemble des modules/matières dans lesquels intervient l’ESC : les modules généraux ainsi que les modules professionnels : dans ce cas,

Décomposer le problème en au moins deux modules dont une fonction.. Analyser le problème principal ainsi que les

over Noetherian rings are pseudo~coherent.) If the module A in Theorem 1 or 2 is pseudo-coherent, then the hypothesis that the An are finitely gene- rated (rather

modules and the structure of the complete lattice of all module nuclei is investigated.. It is shown that any module nucleus associated to

(of. We take any element a in f$'f. The remaining part of the corollary is immediate from the above.. In Theorem k below, we shall show the converse of Corollary in a special

This note was motivated by the results of Luigi Salce and Paolo Za- nardo on the existence and the structure of indecomposable finitely generated modules and