-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program1.cbl
301 lines (265 loc) · 11.7 KB
/
Program1.cbl
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
IDENTIFICATION DIVISION.
PROGRAM-ID. PATTCBL
******************************
*AUTHOR: JACKIE MARCANO *
******************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MAIN-MENU-INPUT.
05 PATTERN-SELECTION PIC 99.
88 PATTERN1 VALUE 1.
88 PATTERN2 VALUE 2.
88 PATTERN3 VALUE 3.
88 PATTERN4 VALUE 4.
88 PATTERN5 VALUE 5.
88 PATTERN6 VALUE 6.
88 PATTERN7 VALUE 7.
88 PATTERN8 VALUE 8.
88 PATTERN9 VALUE 9.
88 EXITPROG VALUE 10.
05 USR-SIZE PIC 9.
01 HALF-USR-SIZE PIC 9.
01 VARIATION1 PIC 9.
01 DUMMY PIC X.
01 USR-CONT PIC XXX.
01 COUNTER1 PIC 99.
01 COUNTER2 PIC 99.
01 BIN-CHANGER PIC 9.
01 CTR2-OUT PIC 9.
******************************************************************
SCREEN SECTION.
01 MAIN-MENU
BLANK SCREEN.
05 LINE 3 COLUMN 25 VALUE "************************".
05 LINE 4 COLUMN 25 VALUE "* PATTERN GENERATOR *".
05 LINE 5 COLUMN 25 VALUE "* BY *".
05 LINE 6 COLUMN 25 VALUE "* ALEK MARCANO MORALES *".
05 LINE 7 COLUMN 25 VALUE "************************".
05 LINE 9 COLUMN 23 VALUE "SELECT A PATTERN BETWEEN (1-9)".
05 LINE 3 COLUMN 60 VALUE "PATTERNS:".
05 LINE 4 COLUMN 60 VALUE "1.DESCENDING".
05 LINE 5 COLUMN 60 VALUE "2.DOUBLES DESCENDING".
05 LINE 6 COLUMN 60 VALUE "3.INVERTED SUB ASCENDING".
05 LINE 7 COLUMN 60 VALUE "4.INVERTED DESCENDING".
05 LINE 8 COLUMN 60 VALUE "5.ASCENDING".
05 LINE 9 COLUMN 60 VALUE "6.COUNT DOWN COUNT UP".
05 LINE 10 COLUMN 60 VALUE "7.PUSHED DESCENDING".
05 LINE 11 COLUMN 60 VALUE "8.BINARY DESCENDING".
05 LINE 12 COLUMN 60 VALUE "9.ARRAY LIST".
05 LINE 10 COLUMN 30 VALUE "TO EXIT ENTER 10".
05 LINE 11 COLUMN 35 PIC ZZ USING PATTERN-SELECTION.
05 LINE 12 COLUMN 25 VALUE "PRESS TAB TO CONTINUE".
05 LINE 14 COLUMN 22 VALUE
"ENTER THE SIZE FOR PATTERN (1-9)".
05 LINE 15 COLUMN 35 PIC Z USING USR-SIZE.
******************************************************************
01 PATTERN-DISPLAY
BLANK SCREEN.
05 LINE 1 COLUMN 25 VALUE
"WOULD YOU LIKE TO DO ANOTHER SIZE?".
05 LINE 1 COLUMN 60 USING USR-CONT PIC XXX.
05 LINE 2 COLUMN 25 VALUE
"IF ANSWER YES, PRESS TAB TO ENTER SIZE. (1-9)".
05 LINE 3 COLUMN 25 USING USR-SIZE PIC 9.
05 LINE 4 COLUMN 1.
01 ERROR-SCREEN
BLANK SCREEN.
05 LINE 5 COLUMN 10 VALUE
"VALUE INCORRECT. PLEASE CHOOSE BETWEEN 1 TO 10.".
05 LINE 6 COLUMN 10 USING DUMMY.
PROCEDURE DIVISION.
100-MAIN.
PERFORM UNTIL PATTERN-SELECTION = 10
MOVE ZERO TO PATTERN-SELECTION
MOVE ZERO TO USR-SIZE
MOVE SPACE TO USR-CONT
DISPLAY MAIN-MENU
ACCEPT MAIN-MENU
EVALUATE TRUE
WHEN PATTERN1
PERFORM 200-DOWN-ASCENDING-PATTERN
WHEN PATTERN2
PERFORM 300-DBL-ASCENDING-PATTERN
WHEN PATTERN3
PERFORM 400-RVRS-DESCENDING-PATTERN
WHEN PATTERN4
PERFORM 500-RVRS-ASCENDING-PATTERN
WHEN PATTERN5
PERFORM 600-DESCENDING-PATTERN
WHEN PATTERN6
PERFORM 700-ZIGZAG-PATTERN
WHEN PATTERN7
PERFORM 800-PUSHED-ASCENDING-PATTERN
WHEN PATTERN8
PERFORM 900-BINARY-ASCENDING-PATTERN
WHEN PATTERN9
PERFORM 1000-INDEX-LIST
WHEN EXITPROG
STOP RUN
WHEN OTHER
DISPLAY ERROR-SCREEN
ACCEPT ERROR-SCREEN
END-EVALUATE
END-PERFORM
STOP RUN.
200-DOWN-ASCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM 1 BY 1
UNTIL COUNTER1 GREATER THAN USR-SIZE
PERFORM VARYING COUNTER2 FROM 1 BY 1
UNTIL COUNTER2 GREATER THAN COUNTER1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
300-DBL-ASCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM 1 BY 1
UNTIL COUNTER1 GREATER THAN USR-SIZE
PERFORM VARYING COUNTER2 FROM 1 BY 1
UNTIL COUNTER2 GREATER THAN COUNTER1
MOVE COUNTER1 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
400-RVRS-DESCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM USR-SIZE BY -1
UNTIL COUNTER1 LESS THAN 1
PERFORM VARYING COUNTER2 FROM COUNTER1 BY -1
UNTIL COUNTER2 LESS THAN 1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
500-RVRS-ASCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM USR-SIZE BY -1
UNTIL COUNTER1 LESS THAN 1
PERFORM VARYING COUNTER2 FROM USR-SIZE BY -1
UNTIL COUNTER2 LESS THAN COUNTER1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
600-DESCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM USR-SIZE BY -1
UNTIL COUNTER1 LESS THAN 1
PERFORM VARYING COUNTER2 FROM 1 BY 1
UNTIL COUNTER2 GREATER THAN COUNTER1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
700-ZIGZAG-PATTERN.
COMPUTE HALF-USR-SIZE ROUNDED = USR-SIZE/2
MOVE HALF-USR-SIZE TO VARIATION1
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM 1 BY 1
UNTIL COUNTER1 GREATER THAN HALF-USR-SIZE
PERFORM VARYING COUNTER2 FROM 1 BY 1
UNTIL COUNTER2 GREATER THAN VARIATION1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
SUBTRACT 1 FROM VARIATION1
DISPLAY SPACE
IF COUNTER1 EQUALS HALF-USR-SIZE
MOVE 2 TO VARIATION1
PERFORM VARYING COUNTER1 FROM HALF-USR-SIZE BY 1
UNTIL COUNTER1 EQUAL TO USR-SIZE
PERFORM VARYING COUNTER2 FROM 1 BY 1
UNTIL COUNTER2 GREATER THAN VARIATION1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
ADD 1 TO VARIATION1
DISPLAY SPACE
END-PERFORM
END-IF
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
800-PUSHED-ASCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM 1 BY 1
UNTIL COUNTER1 GREATER THAN USR-SIZE
PERFORM VARYING COUNTER2 FROM COUNTER1 BY -1
UNTIL COUNTER2 LESS THAN 1
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT, " ", WITH NO ADVANCING
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
900-BINARY-ASCENDING-PATTERN.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM 1 BY 1
UNTIL COUNTER1 GREATER THAN USR-SIZE
MOVE 1 TO BIN-CHANGER
PERFORM VARYING COUNTER2 FROM 1 BY 1
UNTIL COUNTER2 GREATER THAN COUNTER1
DISPLAY BIN-CHANGER, " ", WITH NO ADVANCING
IF BIN-CHANGER = 1
THEN MOVE 0 TO BIN-CHANGER
ELSE
MOVE 1 TO BIN-CHANGER
END-IF
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
1000-INDEX-LIST.
PERFORM UNTIL USR-CONT = "NO "
MOVE SPACE TO USR-CONT
DISPLAY PATTERN-DISPLAY
PERFORM VARYING COUNTER1 FROM 0 BY 1
UNTIL COUNTER1 EQUAL TO USR-SIZE
PERFORM VARYING COUNTER2 FROM 0 BY 1
UNTIL COUNTER2 EQUAL TO USR-SIZE
IF COUNTER1 EQUAL TO COUNTER2 THEN
MOVE COUNTER2 TO CTR2-OUT
DISPLAY CTR2-OUT WITH NO ADVANCING
ELSE
DISPLAY ZERO WITH NO ADVANCING
END-IF
END-PERFORM
DISPLAY SPACE
END-PERFORM
ACCEPT PATTERN-DISPLAY
END-PERFORM.
END PROGRAM PATTCBL.