-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-differenttypes.cob
99 lines (91 loc) · 3.59 KB
/
05-differenttypes.cob
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
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
90
91
92
93
94
95
96
97
98
99
IDENTIFICATION DIVISION.
PROGRAM-ID. Different_Types.
****************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT contact-file ASSIGN TO "contacts.dat".
****************************
DATA DIVISION.
FILE SECTION.
FD contact-file.
01 home-address.
05 first-name PIC X(20).
05 last-name PIC X(20).
05 zip PIC 99999.
05 street PIC X(30).
05 city PIC X(30).
01 email-address.
05 first-name PIC X(20).
05 last-name PIC X(20).
05 email PIC X(20).
WORKING-STORAGE SECTION.
01 switch PIC X.
****************************
PROCEDURE DIVISION.
* Read data for contact-file.
DISPLAY "Do you wish to enter a home address (h) or "
"an email address (e)? [h/e]".
ACCEPT switch.
OPEN OUTPUT contact-file.
IF switch = "h" THEN
DISPLAY "[+] Enter home address:"
DISPLAY " First name : "
ACCEPT first-name IN home-address
DISPLAY " Last name : "
ACCEPT last-name IN home-address
DISPLAY " ZIP code : "
ACCEPT zip IN home-address
DISPLAY " Street : "
ACCEPT street IN home-address
DISPLAY " City : "
ACCEPT city IN home-address
WRITE home-address
ELSE IF switch = "e" THEN
DISPLAY "[+] Enter email address:"
DISPLAY " First name : "
ACCEPT first-name IN email-address
DISPLAY " Last name : "
ACCEPT last-name IN email-address
DISPLAY " Email : "
ACCEPT email IN email-address
WRITE email-address
ELSE
DISPLAY "Unknown option '" switch "'."
END-IF.
CLOSE contact-file.
DISPLAY "---".
* Display entries of contact-file.
DISPLAY "Are you expecting a home address (h) or "
"an email address (e)? [h/e]".
ACCEPT switch.
OPEN INPUT contact-file.
*** What would happen if we do not specify the target record in READ?
* READ contact-file.
IF switch = "h" THEN
READ contact-file INTO home-address
DISPLAY "[+] Home address is:"
DISPLAY " First name : "
DISPLAY first-name IN home-address
DISPLAY " Last name : "
DISPLAY last-name IN home-address
DISPLAY " ZIP code : "
DISPLAY zip IN home-address
DISPLAY " Street : "
DISPLAY street IN home-address
DISPLAY " City : "
DISPLAY city IN home-address
ELSE IF switch = "e" THEN
READ contact-file INTO email-address
DISPLAY "[+] Enter email address:"
DISPLAY " First name : "
DISPLAY first-name IN email-address
DISPLAY " Last name : "
DISPLAY last-name IN email-address
DISPLAY " Email : "
DISPLAY email IN email-address
ELSE
DISPLAY "Unknown option '" switch "'."
END-IF.
CLOSE contact-file.
STOP RUN.