*Cobol Program created by: Christopher Mayo-Logan
*This program will read an input file containing an individual's
*age, current savings and projected monthly savings. After
*processing, the output file will contain the amount of money
*the individual will contain upon starting college, assuming a
*5 percent rate of return. The purpose of the program was to
*get acquainted with COBOL and how to read, process and produce
*files. Note that the purpose did not include building a
*financial planning tool. With this purpose in mind, several
*liberties have been taken to simplify the calculations (Most
*notably that the entire sum of monthly savings was contributed
*at the beginning of a year).
identification division.
program-id. college-savings.
author. Chris Logan
date-written. 26-january-1999
environment division.
input-output section.
file-control.
select I-saving-info assign to disk
'a:\chris.dat'
organization is line sequential.
select Pchris-Report assign to disk
'a:\printc.dat'
organization is line sequential.
data division.
file section.
fd I-saving-info.
01 I-saving-info-record.
05 I-name pic x(25).
05 I-current-age pic 9(2).
05 I-current-savings pic 9(6).
05 I-monthly-savings pic 9(3).
fd Pchris-Report.
01 print-rec pic x(80).
working-storage section.
01 print-record.
05 header-1.
10 filler pic x(56) value spaces.
10 filler pic x(18)
value 'Saving for College'.
05 header-2.
10 filler pic x(4) value 'Name'.
10 filler pic x(21) value spaces.
10 filler pic x(7) value 'Current'.
10 filler pic x(7) value spaces.
10 filler pic x(8) value 'Years to'.
10 filler pic x(4) value spaces.
10 filler pic x(7) value 'Current'.
10 filler pic x(4) value spaces.
10 filler pic x(7) value 'Monthly'.
10 filler pic x(4) value spaces.
10 filler pic x(7) value 'balance'.
05 header-3.
10 filler pic x(27) value spaces.
10 filler pic x(3) value 'Age'.
10 filler pic x(11) value spaces.
10 filler pic x(4) value 'Save'.
10 filler pic x(6) value spaces.
10 filler pic x(7) value 'Savings'.
10 filler pic x(4) value spaces.
10 filler pic x(7) value 'Savings'.
10 filler pic x(4) value spaces.
10 filler pic x(5) value 'at 5%'.
05 detail-line.
10 p-name pic x(25) value spaces.
10 filler pic x(2) value spaces.
10 p-current-age pic z9 value zero.
10 filler pic x(12) value spaces.
10 p-yrs pic z9 value zero.
10 filler pic x(9) value spaces.
10 p-current-savings pic zzz9 value zero.
10 filler pic x(7) value spaces.
10 p-monthly-savings pic zzzz9 value zero.
10 filler pic x(6) value spaces.
10 p-total-savings pic zzzz9 value zero.
01 work-variables.
05 more-recs pic x(3) value 'yes'.
05 w-annual-savings pic 9(5) value zero.
05 w-total-savings pic 9(6) value zero.
05 w-accum-annual pic 9(6) value zero.
05 w-accum-curr pic 9(6) value zero.
05 w-annual-mult pic 99v999 value zero.
05 w-current-mult pic 99v999 value zero.
05 w-yrs pic 9(2) value zero.
Procedure division.
open input I-saving-info
output Pchris-report.
perform 100-print-headers.
perform 200-read-file until more-recs = 'no '.
close i-saving-info
pchris-report.
stop run.
100-print-headers.
write print-rec from header-1.
write print-rec from header-2.
write print-rec from header-3.
100-end.
200-read-file.
read I-saving-info
at end move 'no ' to more-recs
not at end perform 300-compute-savings
end-read.
200-end.
300-compute-savings.
compute w-yrs=18 - I-current-age.
perform 400-evaluate-years.
perform 500-do-the-math.
perform 600-print-detail.
300-end.
400-evaluate-years.
evaluate w-yrs
when 1 move 1.050 to w-current-mult
move 1.050 to w-annual-mult
when 2 move 1.103 to w-current-mult
move 2.153 to w-annual-mult
when 3 move 1.158 to w-current-mult
move 3.310 to w-annual-mult
when 4 move 1.216 to w-current-mult
move 4.526 to w-annual-mult
when 5 move 1.276 to w-current-mult
move 5.802 to w-annual-mult
when 6 move 1.340 to w-current-mult
move 7.142 to w-annual-mult
when 7 move 1.407 to w-current-mult
move 8.549 to w-annual-mult
when 8 move 1.477 to w-current-mult
move 10.026 to w-annual-mult
when 9 move 1.551 to w-current-mult
move 11.577 to w-annual-mult
when 10 move 1.629 to w-current-mult
move 13.206 to w-annual-mult
when 11 move 1.710 to w-current-mult
move 14.916 to w-annual-mult
when 12 move 1.796 to w-current-mult
move 16.712 to w-annual-mult
when 13 move 1.886 to w-current-mult
move 18.598 to w-annual-mult
when 14 move 1.980 to w-current-mult
move 20.578 to w-annual-mult
when 15 move 2.079 to w-current-mult
move 22.657 to w-annual-mult
when 16 move 2.183 to w-current-mult
move 24.839 to w-annual-mult
end-evaluate.
400-end.
500-do-the-math.
compute w-annual-savings = i-monthly-savings * 12.
compute w-accum-annual = w-annual-savings * w-annual-mult.
compute w-accum-curr = i-current-savings * w-current-mult.
compute w-total-savings = w-accum-annual + w-accum-curr.
500-end.
600-print-detail.
move I-name to P-name.
move I-current-age to P-current-age.
move I-current-savings to P-current-savings.
move I-monthly-savings to P-monthly-savings.
move w-total-savings to p-total-savings.
move w-yrs to p-yrs.
write print-rec from detail-line.
600-end.