Skip to content

Instantly share code, notes, and snippets.

@krismuniz
Last active July 26, 2017 22:21
Show Gist options
  • Save krismuniz/2c0876157e898da9b76511111d6d0a5e to your computer and use it in GitHub Desktop.
Save krismuniz/2c0876157e898da9b76511111d6d0a5e to your computer and use it in GitHub Desktop.
Various COBOL programs for SICI4144 – Fall 2016

Various COBOL programs for SICI4144 – Fall 2016

These are a couple excersise programs for my programming languages class. In this example we learned the basics of the language, its roots, and explored the structured programming paradigm.

Programs

  • calc2000 A simple future-value calculator (prog-calc.cbl)
  • calcGPA GPA calculator (prog-calcGPA.cbl)
  • stu1000 Creates a student list report taking file as input (prog-stu1000.cbl)
******************************************************************
* program name: calc2000
* description: Calculates the future value of an investment
* compiler: GnuCOBOL / OpenCOBOL
* author: Kristian Muniz <[email protected]>
* class: SICI 4144
* date: Wednesday, August 24th, 2016
******************************************************************
identification division.
program-id. calc2000.
environment division.
input-output section.
data division.
file section.
working-storage section.
01 user-entries.
05 number-entered pic 9 value 1.
05 investment-amount pic 99999.
05 number-of-years pic 99.
05 yearly-interest-rate pic 99v9.
01 work-fields.
05 future-value pic 9(7)v99.
05 year-counter pic 999.
05 edited-future-value pic z,zzz,zzz.99.
procedure division.
000-calculate-future-values.
perform 100-calculate-future-value
until number-entered = zero.
display "End of session.".
stop run.
100-calculate-future-value.
display "----------------------------------------".
display SPACE
display "To end program enter 0 -----------------".
display "To perform another calculation, enter 1.".
accept number-entered.
display "----------------------------------------".
display SPACE
if number-entered = 1
perform 110-get-user-values
move investment-amount to future-value
move 1 to year-counter
perform 120-calculate-next-fv
until year-counter > number-of-years
move future-value to edited-future-value
display "Future value = " edited-future-value.
110-get-user-values.
display "Enter investment amount (xxxxxx) ------.".
accept investment-amount.
display "Enter number of years (xx) ------------.".
accept number-of-years.
display "Enter yearly interest rate (xx.x) -----.".
accept yearly-interest-rate.
120-calculate-next-fv.
compute future-value rounded =
future-value +
(future-value * yearly-interest-rate / 100).
add 1 to year-counter.
******************************************************************
* program name: calcGPA
* description: Calculates GPA given grade points & credits
* compiler: GnuCOBOL / OpenCOBOL
* author: Kristian Muniz <[email protected]>
* class: SICI 4144
* date: Monday, September 5th, 2016
******************************************************************
identification division.
program-id. calcGPA1.
data division.
file section.
working-storage section.
01 user-input.
05 letter-input pic X.
05 credits pic 99.
05 grade-points pic 99.
01 work-fields.
05 first-run pic X value "Y".
05 gpa pic 99v99.
01 presentation.
05 gpa-edited pic Z9.99.
procedure division.
000-main-procedure.
perform 100-prompt-execution
until letter-input = "N".
display "End of session.".
stop run.
100-prompt-execution.
display "--------------------------------------------------".
if first-run = "Y"
display "Do you want to calculate a GPA (Y/N)?"
else
display "Do you want to calculate another GPA (Y/N)?"
end-if.
accept letter-input.
if letter-input = "Y"
perform 200-calculate-gpa.
200-calculate-gpa.
display "--------------------------------------------------".
display "Enter the number of grade points for the semester.".
accept grade-points.
display "Enter the number of credits taken.".
accept credits.
* # calculate and present gpa
compute gpa = grade-points / credits.
move gpa to gpa-edited.
display "Your grade point average is " gpa-edited.
* # set first-run switch to false
move "N" to first-run.
******************************************************************
* program name: stu1000
* description: Creates a student list report
* compiler: GnuCOBOL / OpenCOBOL
* author: Kristian Muniz <[email protected]>
* class: SICI 4144
* date: Wednesday, October 14th, 2016
******************************************************************
identification division.
program-id. stu1000.
environment division.
input-output section.
file-control.
select stumast assign to
"c:\users\kris\documents\stu1000\stumast.dat".
select stulist assign to
"c:\users\kris\documents\stu1000\stulist.lprt".
data division.
file section.
fd stumast.
01 student-master-record.
05 sm-student-id pic 9(9).
05 sm-student-status pic X.
88 enrolled value "E".
88 inactive value "I".
05 sm-student-name-and-address.
10 sm-student-name pic x(25).
10 sm-date-of-birth.
15 sm-dob-year pic 9(4).
15 sm-dob-month pic 9(2).
15 sm-dob-year pic 9(2).
10 sm-student-address pic x(25).
10 sm-student-city pic x(11).
10 sm-student-state pic x(2).
10 sm-zip-code pic 9(5).
10 sm-zip-code-ext pic 9(4).
05 sm-student-progress-summary.
10 sm-class-standing pic 9.
88 freshman value 1.
88 sophomore value 2.
88 junior value 3.
88 senior value 4.
10 sm-major pic x(4).
10 sm-units-completed pic 9(3).
10 sm-total-grade-points pic 9(3).
10 sm-units-in-progress pic 9(3).
fd stulist.
01 print-area pic x(132).
working-storage section.
01 switches.
05 stumast-eof-switch pic x value "N".
88 stumast-eof value "Y".
01 print-fields.
05 page-count pic s9(3) value 0.
05 lines-on-page pic s9(3) value +55.
05 line-count pic s9(3) value +99.
05 space-control pic s9.
01 total-fields.
05 total-students pic 9(5) value 0.
01 calculated-fields.
05 student-gpa pic 9v99.
01 current-date-and-time.
05 cd-year pic 9999.
05 cd-month pic 99.
05 cd-day pic 99.
05 cd-hours pic 99.
05 cd-minutes pic 99.
05 filler pic x(9).
01 heading-line-1.
05 filler pic x(7) value "DATE: ".
05 hl1-month pic 9(2).
05 filler pic x(1) value "/".
05 hl1-day pic 9(2).
05 filler pic x(1) value "/".
05 hl1-year pic 9(4).
05 filler pic x(2) value space.
05 filler pic x(20) value "STUDENT LISTING ".
05 filler pic x(20) value space.
05 filler pic x(15) value " PAGE: ".
05 hl1-page-number pic zzz9.
05 filler pic x(37) value space.
01 heading-line-2.
05 filler pic x(7) value "TIME: ".
05 hl2-hours pic 9(2).
05 filler pic x(1) value ":".
05 hl2-minutes pic 9(2).
05 filler pic x(58) value space.
05 filler pic x(10) value "STU_1000".
05 filler pic x(52) value space.
01 heading-line-3.
05 filler pic x(20) value "STUDENT ID STUDENT".
05 filler pic x(10) value " NAME ".
05 filler pic x(10) value space.
05 filler pic x(20) value "CLASS GPA ".
05 filler pic x(116) value space.
01 working-fields.
05 wk-student-id pic XXXBXXBXXXX.
01 student-line.
05 sl-student-id-formatted.
10 first-three pic x(3).
10 filler pic x(1) value '-'.
10 middle-two pic x(2).
10 filler pic x(1) value '-'.
10 last-four pic x(4).
05 filler pic x(2) value space.
05 sl-student-name pic x(25).
05 filler pic x(2) value space.
05 sl-student-class pic x(9).
05 filler pic x(2) value space.
05 sl-student-gpa pic 9.99.
05 filler pic x(77) value space.
01 total-line.
05 filler pic x(16) value "TOTAL STUDENTS: ".
05 tl-students pic ZZ,ZZ9.
05 filler pic x(110) value space.
procedure division.
000-prepare-student-report.
open input stumast
output stulist.
perform 100-format-report-heading.
perform 200-prepare-student-lines
until stumast-eof-switch = "Y".
perform 300-print-totals.
close stumast
stulist.
stop run.
100-format-report-heading.
move function current-date to current-date-and-time.
move cd-month to hl1-month.
move cd-day to hl1-day.
move cd-year to hl1-year.
move cd-hours to hl2-hours.
move cd-minutes to hl2-minutes.
200-prepare-student-lines.
perform 210-read-student-record.
if stumast-eof-switch = "N"
perform 220-print-student-line.
210-read-student-record.
read stumast
at end
set stumast-eof to true.
220-print-student-line.
if line-count >= lines-on-page
perform 230-print-heading-lines.
move sm-student-id to wk-student-id.
move wk-student-id to sl-student-id-formatted.
move sm-student-name to sl-student-name.
move sm-class-standing to sl-student-class.
evaluate true
when freshman
move 'FRESHMAN' to sl-student-class
when sophomore
move 'SOPHOMORE' to sl-student-class
when junior
move 'JUNIOR' to sl-student-class
when other
move 'SENIOR' to sl-student-class
end-evaluate.
compute sl-student-gpa =
(sm-total-grade-points / sm-units-completed).
move student-line to print-area.
write print-area after advancing space-control lines.
add 1 to total-students.
add 1 to line-count.
move 1 to space-control.
230-print-heading-lines.
add 1 to page-count.
move page-count to hl1-page-number.
move heading-line-1 to print-area.
write print-area after advancing page.
move heading-line-2 to print-area.
write print-area after advancing 1 lines.
move heading-line-3 to print-area.
write print-area after advancing 2 lines.
move zero to line-count.
move 2 to space-control.
300-print-totals.
move total-students to tl-students.
move total-line to print-area.
write print-area after advancing 2 lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment