Sunteți pe pagina 1din 4

D partement STPI e

Lundi 11 Avril 2011

I3 - Algorithmique
Dur e : 1h30 e Documents autoris s : AUCUN (calculatrice comprise) e Remarques : Veuillez lire attentivement les questions avant de r pondre. e Le bar` me donn est un bar` me indicatif qui pourra evoluer lors de la correction. e e e Rendez une copie propre. ` Nutilisez pas de crayon a papier.

Compr hension du cours (10 points) e

La gure 1 pr sente lanalyse decendante (vue en cours) du probl` me de transformation dune chane de cae e ract` res (repr sentant peut- tre un r el positif de la forme partie enti` re ou partie enti` re,partie d cimale e e e e e e e avec au moins un chiffre dans partie enti` re et partie d cimale) en r el. e e e
Chaine de caractres chaineEnRel Rel Boolen

Chaine de Caractres

positionVirgule

Naturel

Naturel Rel

dcalerVirguleVersGauche

Rel

Chaine de caractres Chaine de caractres Caractre positionCaractre

chaineEnNaturel Naturel

Naturel Boolen Rel Naturel puissanceNaturel Naturel Boolen Rel

Caractre

caractreEnNaturel

F IGURE 1 Analyse descendante tel que les (sous-)probl` mes : e positionVirgule permet dobtenir la position du caract` re virgule (,) dans une chane ch. Il retourne 0 si la e virgule nest pas pr sente ; e chaineEnNaturel permet dessayer de transformer une chane ch repr sentant un naturel en un naturel ; e d calerVirguleVersGauche permet de d caler la virgule dun r el x de n rangs vers la gauche ; e e e positionCaract` re permet dobtenir la position dun caract` re c dans une chane ch. Il retourne 0 si le caract` re e e e nest pas pr sent ; e caract` reEnNaturel permet dessayer de transformer un caract` re c en un naturel ; e e ` puissanceNaturel permet d lever un r el x a une puissance n naturel. e e

1.1

Conception pr liminaire e

Donnez la signature des fonctions et proc dures correspondant aux (sous-)probl` mes identi s par cette e e e analyse descendante.

1.2

Conception d taill e e e
On suppose que lon poss` de les fonctions suivantes : e fonction longueur (uneChaine : Chaine de caracteres) : Naturel fonction iemeCaractere (uneChaine : Chaine de caracteres, position : Naturel) : Caractere fonction sousChaine (uneChaine : Chaine de caracteres, debut,n : Naturel) : Caractere

1. Donnez le corps la proc dure/fonction du (sous-)probl` me positionCaractere qui retourne la e e premi` re position dun caract` re c sil est pr sent dans la chane ch (la position du premier caract` re e e e e de la chane ch vaut 1) et 0 sinon. 2. Donnez le corps de la proc dure/fonction du (sous-)probl` me chaineEnRel qui permet de transfore e e mer une chane ch en r el en sachant sil y a eu ou pas une erreur. e

D veloppement limit (6 points) e e


Lorsque x est proche de 0, (1 + x)a peut etre approxim a laide du d veloppement limit suivant : e` e e
n

1+
i=1

i j=1 (a

j + 1)

i!

xi

Donnez le corps de la fonction suivante qui calcule une approximation de (1 + x)a jusquau rang n : fonction unPlusXExpA (x,a : Reel, n : Naturel) : Reel Votre algorithme devra respecter les deux conditions suivantes : sa complexit doit etre en O(n) ; e vous utiliserez uniquement des variables locales et les param` tres formels donn s (vous nutiliserez aue e cune autre fonction, pas danalyse descendante).

3
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

Erreurs dans un programme Pascal (4 points)


Soit le programme pascal suivant :

program c h i f f r e m e n t C e s a r ; f u n c t i o n c a r a c t e r e A d m i s s i b l e ( u n C a r a c t e r e : Char ) : Boolean ; begin c a r a c t e r e A d m i s s i b l e : = ( u n C a r a c t e r e >= A and u n C a r a c t e r e <= Z ) or ( u n C a r a c t e r e >= a and u n C a r a c t e r e <= z ) or ( u n C a r a c t e r e = ) end ; f u n c t i o n d e c a l a g e ( u n C a r a c t e r e : Char ) : I n t e g e r ; begin i f ( u n C a r a c t e r e >= A ) and ( u n C a r a c t e r e <= Z ) t h e n d e c a l a g e : = ( o r d ( u n C a r a c t e r e )o r d ( A ) ) else i f ( u n C a r a c t e r e >= a ) and ( u n C a r a c t e r e <= z ) t h e n d e c a l a g e : = 2 6 + ( o r d ( u n C a r a c t e r e )o r d ( a ) ) else de c al a ge :=52 end ; f u n c t i o n c h i f f r e r P h r a s e ( u n e P h r a s e : S t r i n g ; u n e C l e : Char ) : C h a i n e ; var resultat : String ; leDecalage : Integer ; begin r e s u l t a t := ; le D ec a la ge := d e c a l a g e ( uneCle ) ; f o r i : = 1 t o l e n g t h ( u n e P h r a s e ) do i f c a r a c t e r e A d m i s s i b l e ( unePhrase [ i ] ) then r e s u l t a t := r e s u l t a t + c h i f f r e r C a r a c t e r e ( unePhrase [ i ] , leDecalage ) ;

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

c h i f f r e r P h r a s e := r e s u l t a t end ; f u n c t i o n c h i f f r e r C a r a c t e r e ( u n C a r a c t e r e : Char ; u n D e c a l a g e : I n t e g e r ) : Char ; var r e s u l t a t : Char ; i : Integer ; begin r e s u l t a t := unCaractere ; f o r i : = 1 . t o u n D e c a l a g e do case r e s u l t a t of Z : r e s u l t a t : = a ; z : r e s u l t a t := ; : r e s u l t a t : = A ; e l s e r e s u l t a t := succ ( r e s u l t a t ) end ; c h i f f r e r C a r a c t e r e := r e s u l t a t end ; f u n c t i o n finDeProgramme ( u n e P h r a s e : S t r i n g ) : Boolean ; begin finDeProgramme : = ( u p c a s e ( u n e P h r a s e ) = FIN . ) end ; function obtenirPhrase () : String ; var r e s u l t a t : Integer ; begin w r i t e ( Message a c h i f f r e r : ) ; readln ( r e s u l t a t ) ; o b t e n i r P h r a s e := r e s u l t a t end ; f u n c t i o n o b t e n i r C l e : Char ; var r e s u l t a t : Char ; begin w r i t e ( La c l e : ) ; repeat readln ( r e s u l t a t ) ; until caractereAdmissible ( resultat ) ; o b t e n i r C l e := r e s u l t a t end ; procedure m a c h i n e A C h i f f r e r ( ) ; var laCle : Char ; laPhrase : String ; begin laCle := o b t e n i r C l e ( ) ; l a P h r a s e := o b t e n i r P h r a s e ( ) ; w h i l e n o t finDeProgramme ( l a P h r a s e ) do begin writeln ( chiffrerPhrase ( laPhrase , laCle ) ) ; l a P h ra s e := o b t e n i r P h r a s e ( ) ; end end ; begin machineAChiffrer ( ) end ;

Sa compilation donne les informations suivantes :


1 2 3 4 $ fpc c h i f f r e m e n t C e s a r . pas Free P a s c a l Compiler v e r s i o n 2.4.0 2 [ 2 0 1 0 / 0 3 / 0 6 ] f o r x86 64 C o p y r i g h t ( c ) 1993 2009 by F l o r i a n K l a e m p f l T a r g e t OS : L i n u x f o r x86 64

5 6 7 8 9 10 11 12 13 14 15 16 17 18

Compiling c h i f f r e m e n t C e s a r . pas c h i f f r e m e n t C e s a r . pas (5 ,44) Error : and Char c h i f f r e m e n t C e s a r . pas (5 ,87) Error : and Char c h i f f r e m e n t C e s a r . pas (19 ,68) Error c h i f f r e m e n t C e s a r . pas (26 ,9) Error : c h i f f r e m e n t C e s a r . pas (27 ,41) Error c h i f f r e m e n t C e s a r . pas (28 ,39) Error c h i f f r e m e n t C e s a r . pas (28 ,51) Error c h i f f r e m e n t C e s a r . pas (38 ,11) Error SmallInt c h i f f r e m e n t C e s a r . pas (59 ,19) Error ShortString c h i f f r e m e n t C e s a r . pas (82 ,45) Error c h i f f r e m e n t C e s a r . pas (89 ,4) F a t a l : Fatal : Compilation aborted $

O p e r a t i o n and n o t s u p p o r t e d f o r t y p e s Char O p e r a t i o n and n o t s u p p o r t e d f o r t y p e s Char : I d e n t i f i e r not found Chaine I d e n t i f i e r not found i : I d e n t i f i e r not found i : I d e n t i f i e r not found c h i f f r e r C a r a c t e r e : I d e n t i f i e r not found i : Incompatible types : got Single expected : Incompatible types : got SmallInt expected : Can t r e a d o r w r i t e v a r i a b l e s o f t h i s t y p e Syntax e r r o r , . expected but ; found

Justiez chacune des erreurs et proposez une correction.

S-ar putea să vă placă și