cours0708/P5B/cobol/exercices/palind1.cbl

91 lines
2.8 KiB
Plaintext
Raw Normal View History

2008-11-25 21:11:16 +00:00
IDENTIFICATION DIVISION.
PROGRAM-ID. palind.
AUTHOR. OD.
*-------------------------------------------*
* PROGRAMME DE VERIFICATION D'UN PALINDROME *
*-------------------------------------------*
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*--------------------------*
* DEFINITION DES VARIABLES *
*--------------------------*
* MOT DONNE PAR L'UTILISATEUR
77 MT-UTIL PICTURE X(255) VALUE SPACE.
* MOT SANS ESPACE
77 MT-SS-SPC PICTURE X(255) VALUE SPACE.
* MOT INVERSE
77 MT-INV PICTURE X(255) VALUE SPACE.
* RESULTAT DU PROGRAMME (ICI ON DIRA "CECI EST UN PALINDROME")
* OU PAS)
77 RESULTAT PICTURE X(30) VALUE SPACE.
* BOOLEEN
77 PLND PICTURE 9 VALUE ZERO.
* 88 EST VALUE ZERO.
* 88 ESTPAS VALUE 1.
* CURSEURS
* - CURSEUR-DEPART
77 CRSR-DP PICTURE 999 VALUE 1.
* - CURSEUR-ARRIVEE
77 CRSR-RRV PICTURE 999 VALUE 1.
PROCEDURE DIVISION.
*NOM DU PROGRAMME
PRINCIPAL SECTION.
DEBUT.
PERFORM SAISIE.
CORPS.
PERFORM TRAITER.
FIN.
DISPLAY RESULTAT.
DISPLAY "FIN DU TRAITEMENT".
STOP RUN.
*SAISIE DU MOT
SAISIR SECTION.
SAISIE.
DISPLAY "Saisissez une phrase : " WITH NO ADVANCING.
ACCEPT MT-UTIL.
DISPLAY "MOT SAISI : " MT-UTIL.
*TRAITEMENT DE LA PHRASE
TRAITEMENT SECTION.
TRAITER.
PERFORM SPPR-SPC UNTIL CRSR-DP EQUAL TO 255.
MOVE 255 TO CRSR-DP.
MOVE 1 TO CRSR-RRV.
PERFORM COPIER UNTIL CRSR-DP EQUAL TO ZERO.
PERFORM COMPARER.
PERFORM DEDUIRE.
*SUPPRESSION DES ESPACES DU MOT DE DEPART
SPPR-SPC.
IF (MT-UTIL(CRSR-DP:1) NOT EQUAL TO SPACE) THEN
STRING MT-UTIL(CRSR-DP:1) DELIMITED BY SIZE INTO
MT-SS-SPC WITH POINTER CRSR-RRV.
ADD 1 TO CRSR-DP.
*COPIE DE LA CHAINE DE DEPART VERS UNE CHAINE D'ARRIVEE
COPIER.
IF (MT-UTIL(CRSR-DP:1) NOT EQUAL TO SPACE) THEN
STRING MT-UTIL(CRSR-DP:1) DELIMITED BY SIZE INTO MT-INV
WITH POINTER CRSR-RRV.
SUBTRACT 1 FROM CRSR-DP.
*COMPARAISON DE LA CHAINE DE CARACT<43>RE
COMPARER.
DISPLAY "MOT DEPART : " MT-SS-SPC.
DISPLAY "MOT ARRIVEE : " MT-INV.
IF (MT-SS-SPC EQUAL TO MT-INV) THEN
MOVE 1 TO PLND
ELSE MOVE ZERO TO PLND.
*DEDUCTION LOGIQUE DU RESULTAT
DEDUIRE.
IF (PLND EQUAL ZERO) THEN
MOVE "CE N'EST PAS UN PALINDROME" TO RESULTAT
ELSE MOVE "C'EST UN PALINDROME" TO RESULTAT.