Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 18, 2016
0 parents commit f32c2b2
Show file tree
Hide file tree
Showing 180 changed files with 44,503 additions and 0 deletions.
@@ -0,0 +1,5 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. ShortestProgram.
PROCEDURE DIVISION.
DisplayPrompt.
DISPLAY "I did it".
@@ -0,0 +1,14 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. CobolGreeting.
*>Program to display COBOL greetings
DATA DIVISION.
WORKING-STORAGE SECTION.
01 IterNum PIC 9 VALUE 5.

PROCEDURE DIVISION.
BeginProgram.
PERFORM DisplayGreeting IterNum TIMES.
STOP RUN.

DisplayGreeting.
DISPLAY "Greetings from COBOL".
@@ -0,0 +1,19 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. DoCalc.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FirstNum PIC 9 VALUE ZEROS.
01 SecondNum PIC 9 VALUE ZEROS.
01 CalcResult PIC 99 VALUE 0.
01 UserPrompt PIC X(38) VALUE
"Please enter two single digit numbers".
PROCEDURE DIVISION.
CalculateResult.
DISPLAY UserPrompt
ACCEPT FirstNum
ACCEPT SecondNum
COMPUTE CalcResult = FirstNum + SecondNum
DISPLAY "Result is = ", CalcResult
STOP RUN.

@@ -0,0 +1,51 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing4-1.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 UserName PIC X(20).

*> Receiving data item for DATE system variable: Format is YYMMDD
01 CurrentDate.
02 CurrentYear PIC 99.
02 CurrentMonth PIC 99.
02 CurrentDay PIC 99.

*> Receiving data item for DAY system variable: Format is YYDDD
01 DayOfYear.
02 FILLER PIC 99.
02 YearDay PIC 9(3).

*> Receiving item for TIME: Format is HHMMSSss s = S/100
01 CurrentTime.
02 CurrentHour PIC 99.
02 CurrentMinute PIC 99.
02 FILLER PIC 9(4).

*> Receiving item for DATE YYYYMMDD system variable: Format is YYYYMMDD
01 Y2KDate.
02 Y2KYear PIC 9(4).
02 Y2KMonth PIC 99.
02 Y2KDay PIC 99.

*> Receiving item for DAY YYYYDDD system variable: Format is YYYYDDD
01 Y2KDayOfYear.
02 Y2KDOY-Year PIC 9(4).
02 Y2KDOY-Day PIC 999.
PROCEDURE DIVISION.
Begin.
DISPLAY "Please enter your name - " WITH NO ADVANCING
ACCEPT UserName
DISPLAY "**********************"
ACCEPT CurrentDate FROM DATE
ACCEPT DayOfYear FROM DAY
ACCEPT CurrentTime FROM TIME
ACCEPT Y2KDate FROM DATE YYYYMMDD
ACCEPT Y2KDayOfYear FROM DAY YYYYDDD
DISPLAY "Name is " UserName
DISPLAY "Date is " CurrentDay "-" CurrentMonth "-" CurrentYear
DISPLAY "Today is day " YearDay " of the year"
DISPLAY "The time is " CurrentHour ":" CurrentMinute
DISPLAY "Y2KDate is " Y2kDay SPACE Y2KMonth SPACE Y2KYear
DISPLAY "Y2K Day of Year is " Y2KDoy-Day " of " Y2KDOY-Year
STOP RUN.
21 changes: 21 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch04/Listing4-2 Add two numbers.cbl
@@ -0,0 +1,21 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing4-2.
AUTHOR. Michael Coughlan.
*> Accepts two numbers from the user, multiplies them together
*> and then displays the result.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE 5.
01 Num2 PIC 9 VALUE 4.
01 Result PIC 99 VALUE ZEROS.

PROCEDURE DIVISION.
CalculateResult.
DISPLAY "Enter a single digit number - " WITH NO ADVANCING
ACCEPT Num1
DISPLAY "Enter a single digit number - " WITH NO ADVANCING
ACCEPT Num2
MULTIPLY Num1 BY Num2 GIVING Result
DISPLAY "Result is = ", Result
STOP RUN.
41 changes: 41 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-1.cbl
@@ -0,0 +1,41 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-1.
AUTHOR. Michael Coughlan.
*> Shows how user defined class names are created and used
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CLASS HexNumber IS "0" THRU "9", "A" THRU "F"
CLASS RealName IS "A" THRU "Z", "a" THRU "z", "'", SPACE.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 NumIn PIC X(4).
01 NameIn PIC X(15).

PROCEDURE DIVISION.
Begin.
DISPLAY "Enter a Hex number - " WITH NO ADVANCING
ACCEPT NumIn.
IF NumIn IS HexNumber THEN
DISPLAY NumIn " is a Hex number"
ELSE
DISPLAY NumIn " is not a Hex number"
END-IF

DISPLAY "----------------------------------"
DISPLAY "Enter a name - " WITH NO ADVANCING
ACCEPT NameIn
IF NameIn IS ALPHABETIC
DISPLAY NameIn " is alphabetic"
ELSE
DISPLAY NameIn " is not alphabetic"
END-IF

IF NameIn IS RealName THEN
DISPLAY NameIn " is a real name"
ELSE
DISPLAY NameIn " is not a real name"
END-IF
STOP RUN.
38 changes: 38 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-10.cbl
@@ -0,0 +1,38 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-10.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PlayerGuess-A PIC 9 VALUE 1.
88 Rock-A VALUE 1.
88 Paper-A VALUE 2.
88 Scissors-A VALUE 3.

01 PlayerGuess-B PIC 9 VALUE 2.
88 Rock-B VALUE 1.
88 Paper-B VALUE 2.
88 Scissors-B VALUE 3.

PROCEDURE DIVISION.
BEGIN.
DISPLAY "Guess for player A (1=rock, 2=scissors, 3=paper) : "
WITH NO ADVANCING
ACCEPT PlayerGuess-A
DISPLAY "Guess for player B (1=rock, 2=scissors, 3=paper) : "
WITH NO ADVANCING
ACCEPT PlayerGuess-B
EVALUATE TRUE ALSO TRUE
WHEN Rock-A ALSO Rock-B DISPLAY "Draw"
WHEN Rock-A ALSO Paper-B DISPLAY "Player B wins"
WHEN Rock-A ALSO Scissors-B DISPLAY "Player A wins"
WHEN Paper-A ALSO Rock-B DISPLAY "Player A wins"
WHEN Paper-A ALSO Paper-B DISPLAY "Draw"
WHEN Paper-A ALSO Scissors-B DISPLAY "Player B wins"
WHEN Scissors-A ALSO Rock-B DISPLAY "Player B wins"
WHEN Scissors-A ALSO Paper-B DISPLAY "Player A wins"
WHEN Scissors-A ALSO Scissors-B DISPLAY "Draw"
WHEN OTHER DISPLAY "Evaluate problem"
END-EVALUATE
STOP RUN.


34 changes: 34 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-11.cbl
@@ -0,0 +1,34 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-11.
AUTHOR. Michael Coughlan.
*> Accepts two numbers and an operator from the user.
*> Applies the appropriate operation to the two numbers.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE 7.
01 Num2 PIC 9 VALUE 3.
01 Result PIC --9.99 VALUE ZEROS.
01 Operator PIC X VALUE "-".
88 ValidOperator VALUES "*", "+", "-", "/".


PROCEDURE DIVISION.
CalculateResult.
DISPLAY "Enter a single digit number : " WITH NO ADVANCING
ACCEPT Num1
DISPLAY "Enter a single digit number : " WITH NO ADVANCING
ACCEPT Num2
DISPLAY "Enter the operator to be applied : " WITH NO ADVANCING
ACCEPT Operator
EVALUATE Operator
WHEN "+" ADD Num2 TO Num1 GIVING Result
WHEN "-" SUBTRACT Num2 FROM Num1 GIVING Result
WHEN "*" MULTIPLY Num2 BY Num1 GIVING Result
WHEN "/" DIVIDE Num1 BY Num2 GIVING Result ROUNDED
WHEN OTHER DISPLAY "Invalid operator entered"
END-EVALUATE
IF ValidOperator
DISPLAY "Result is = ", Result
END-IF
STOP RUN.
33 changes: 33 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-2.cbl
@@ -0,0 +1,33 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-2.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CityCode PIC 9 VALUE ZERO.
88 CityIsDublin VALUE 1.
88 CityIsLimerick VALUE 2.
88 CityIsCork VALUE 3.
88 CityIsGalway VALUE 4.
88 CityIsSligo VALUE 5.
88 CityIsWaterford VALUE 6.
88 UniversityCity VALUE 1 THRU 4.
88 CityCodeNotValid VALUE 0, 7, 8, 9.
PROCEDURE DIVISION.
Begin.
DISPLAY "Enter a city code (1-6) - " WITH NO ADVANCING
ACCEPT CityCode
IF CityCodeNotValid
DISPLAY "Invalid city code entered"
ELSE
IF CityIsLimerick
DISPLAY "Hey, we're home."
END-IF
IF CityIsDublin
DISPLAY "Hey, we're in the capital."
END-IF
IF UniversityCity
DISPLAY "Apply the rent surcharge!"
END-IF
END-IF
STOP RUN.
29 changes: 29 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-3.cbl
@@ -0,0 +1,29 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-3.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 InputChar PIC X.
88 Vowel VALUE "A","E","I","O","U".
88 Consonant VALUE "B" THRU "D", "F","G","H"
"J" THRU "N", "P" THRU "T"
"V" THRU "Z".
88 Digit VALUE "0" THRU "9".
88 ValidChar VALUE "A" THRU "Z", "0" THRU "9".

PROCEDURE DIVISION.
Begin.
DISPLAY "Enter a character :- " WITH NO ADVANCING
ACCEPT InputChar
IF ValidChar
DISPLAY "Input OK"
ELSE
DISPLAY "Invalid character entered"
END-IF
IF Vowel
DISPLAY "Vowel entered"
END-IF
IF Digit
DISPLAY "Digit entered"
END-IF
STOP RUN.
26 changes: 26 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-4.cbl
@@ -0,0 +1,26 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-4.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MakeOfCar PIC X(10).
88 VolksGroup VALUE "skoda", "seat",
"audi", "volkswagen".
88 GermanMade VALUE "volkswagen", "audi",
"mercedes", "bmw",
"porsche".
PROCEDURE DIVISION.
Begin.
DISPLAY "Enter the make of car - " WITH NO ADVANCING
ACCEPT MakeOfCar
IF VolksGroup AND GermanMade
DISPLAY "Your car is made in Germany by the Volkswagen Group."
ELSE
IF VolksGroup
DISPLAY "Your car is made by the Volkswagen Group."
END-IF
IF GermanMade
DISPLAY "Your car is made in Germany."
END-IF
END-IF
STOP RUN.
27 changes: 27 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-5.cbl
@@ -0,0 +1,27 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-5.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CountryCode PIC 999 VALUE ZEROS.
88 BritishCountry VALUES 3, 7, 10, 15.

01 CurrencyCode PIC 99 VALUE ZEROS.
88 CurrencyIsPound VALUE 14.
88 CurrencyIsEuro VALUE 03.
88 CurrencyIsDollar VALUE 28.

PROCEDURE DIVISION.
Begin.
DISPLAY "Enter the country code :- " WITH NO ADVANCING
ACCEPT CountryCode

IF BritishCountry THEN
SET CurrencyIsPound TO TRUE
END-IF
IF CurrencyIsPound THEN
DISPLAY "Pound sterling used in this country"
ELSE
DISPLAY "Country does not use sterling"
END-IF
STOP RUN.
6 changes: 6 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-6-TData.dat
@@ -0,0 +1,6 @@
08712351Teresa Casey LM042
08712352Padraig Quinlan LM051
08712353Kevin Tucker LM051
08712354Maria Donovan LM042
98712355Liam Lorigan LM110
98712356Fiachra Luo LM051
32 changes: 32 additions & 0 deletions 978-1-4302-6253-4_Coughlan_Ch05/Listing5-6.cbl
@@ -0,0 +1,32 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing5-6.
AUTHOR. Michael Coughlan.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT StudentFile ASSIGN TO "Listing5-6-TData.Dat"
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentDetails.
88 EndOfStudentFile VALUE HIGH-VALUES.
02 StudentId PIC X(8).
02 StudentName PIC X(25).
02 CourseCode PIC X(5).

PROCEDURE DIVISION.
Begin.
OPEN INPUT StudentFile
READ StudentFile
AT END SET EndOfStudentFile TO TRUE
END-READ
PERFORM UNTIL EndOfStudentFile
DISPLAY StudentName SPACE StudentId SPACE CourseCode
READ StudentFile
AT END SET EndOfStudentFile TO TRUE
END-READ
END-PERFORM
CLOSE StudentFile
STOP RUN.

0 comments on commit f32c2b2

Please sign in to comment.