cours0708/P5B/cobol/exercices/conson.cbl
2008-11-25 22:11:16 +01:00

84 lines
2.7 KiB
COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. conson.
AUTHOR. OD.
*----------------------------------------------*
* PROGRAMME QUI CONSONNE UN MOT (NORMALEMENT) *
*----------------------------------------------*
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*--------------------------*
* DEFINITION DES VARIABLES *
*--------------------------*
77 MOT PICTURE X(30) VALUE SPACE.
77 RETOUR PICTURE X(30) VALUE SPACE.
77 RESULTAT PICTURE X(6) VALUE SPACE.
77 LETTRE PICTURE X VALUE SPACE.
77 CHIFFRE PICTURE 99 VALUE 2.
77 POINTEUR1 PICTURE 99 VALUE 2.
77 POINTEUR2 PICTURE 9 VALUE 2.
01 VOYELLES.
05 LTR-AMAJ PICTURE X VALUE "A".
05 LTR-EMAJ PICTURE X VALUE "E".
05 LTR-IMAJ PICTURE X VALUE "I".
05 LTR-OMAJ PICTURE X VALUE "O".
05 LTR-UMAJ PICTURE X VALUE "U".
05 LTR-YMAJ PICTURE X VALUE "Y".
05 LTR-AMIN PICTURE X VALUE "a".
05 LTR-EMIN PICTURE X VALUE "e".
05 LTR-IMIN PICTURE X VALUE "i".
05 LTR-OMIN PICTURE X VALUE "o".
05 LTR-UMIN PICTURE X VALUE "u".
05 LTR-YMIN PICTURE X VALUE "y".
01 ESPACES PICTURE X(12) VALUE SPACE.
PROCEDURE DIVISION.
*NOM DU PROGRAMME
PRINCIPAL SECTION.
DEBUT.
PERFORM SAISIE.
CORPS.
PERFORM TRAITEMENT.
FIN.
DISPLAY "Mot consonné : " RESULTAT.
DISPLAY "FIN DU TRAITEMENT". STOP RUN.
*SAISIE DU MOT
SAISIR SECTION.
SAISIE.
DISPLAY "Saisissez un mot : "
WITH NO ADVANCING.
ACCEPT MOT.
*TRAITEMENT DU MOT
TRAITER SECTION.
TRAITEMENT.
INSPECT MOT CONVERTING VOYELLES TO ESPACES AFTER MOT(1:1).
MOVE MOT(1:1) TO RETOUR.
PERFORM CONCATENER UNTIL CHIFFRE EQUAL TO 30.
PERFORM TRANSMISSION.
*CONCATENER LA CHAINE OBTENUE POUR SUPPRIMER LES ESPACES
CONCATENER.
MOVE MOT(CHIFFRE:1) TO LETTRE.
IF (POINTEUR1 < 10) THEN
MOVE POINTEUR1 TO POINTEUR2
END-IF
SUBTRACT 1 FROM POINTEUR2.
IF LETTRE IS EQUAL TO RETOUR(POINTEUR2:1) THEN
MOVE SPACE TO LETTRE.
IF (LETTRE IS NOT EQUAL TO SPACE OR POINTEUR1 IS EQUAL TO
6) THEN
STRING LETTRE(1:1) INTO RETOUR WITH POINTER POINTEUR1
END-IF.
ADD 1 TO CHIFFRE.
*TRANSMET LE RESULTAT DES 6 PREMIERS CARACTERES A LA VARIABLE
* RESULAT
TRANSMISSION.
MOVE RETOUR(1:6) TO RESULTAT.