Een universiteit beschikt over een bestand met gegevens over ongeveer tienduizend studenten. Voor een statistisch onderzoek bekijkt men hun geboortedata. Hoeveel studenten zijn geboren in januari, hoeveel in februari enzovoort. Ook de spreiding over de dagen van de week wil men weten. Hoeveel studenten zijn geboren op een maandag, hoeveel op dinsdag enzovoort.
illustratie: Geert Nijmolen
De gegevens moeten terecht komen op het standaarduitvoerapparaat. Over
het bestand zijn de volgende gegevens bekend:
Bestandsnaam: Student
Implementornaam: disk
Blokkingsfactor: 8
Recordindeling:
Voor het bepalen van de dag van de week waarop een gegeven datum valt, is een algoritme gegeven in een PSD (figuur 6.3). Het COBOL-programma statistiek is daarna gegeven.
Figuur 6.3 Bepaal weekdag
IDENTIFICATION DIVISION. PROGRAM-ID. Statistiek. *Auteur: Andree Hollander *Datum: 1988/07/28 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. select student assign to disk. DATA DIVISION. FILE SECTION. FD student, block contains 8 records. 01 studentrecord. 02 filler pic X(10). 02 datum. 03 eeuw-jaar pic 9(4). 03 eeuw-jaar-los redefines eeuw-jaar. 04 eeuw pic 9(2). 04 jaar pic 9(2). 03 maand pic 9(2). 03 dag pic 9(2). 02 filler pic X(237). WORKING-STORAGE SECTION. 01 teltabellen. 02 maandaantal pic 9(5) occurs 12 times value zero. 02 weekdagaantal pic 9(5) occurs 7 times value zero. 01 weektabel value "zomadiwodovrza". 02 dagnaam pic XX occurs 7 times. 01 maandtabel value "janfebmrtaprmeijunjulaugsepoktnovdec". 02 maandnaam pic XXX occurs 12 times. 01 sub pic 99. 01 toonregel. 02 tekst pic XXXB. 02 aantal pic Z(5). 01 einde-bestand pic X, value "N" 01 rekenvelden. 02 A pic 9(5). 02 B pic 9(5). 02 C pic 9(5). 02 D pic 9(5). 02 weekdag pic 9. PROCEDURE DIVISION. Verwerk-bestand. Open input student perform with test after until einde-bestand = "J" read student next record at end move "J" to einde-bestand not at end add 1 to maandaantal(maand) perform bepaal-weekdag add 1 to weekdagaantal(weekdag + 1) end-read end-perform close student perform toon-resultaten Stop run. Bepaal-weekdag. *zie het PSD Bepaal Weekdag If maand > 2 then subtract 2 from maand else add 10 to maand subtract 1 from eeuw-jaar end-if compute A = (13 * maand - 1) / 5 compute B = jaar / 4 compute C = eeuw / 4 compute D = A + B + C + dag + jaar - 2 * eeuw + 700 divide D by 7 giving A remainder weekdag. * 0 = zo, 1 = ma, 2 = di, 3 = wo, 4 = do, 5 = vr, 6 = za Toon-resultaten. Display "RESULTATEN PER MAAND" perform with test after varying sub from 1 by 1 until sub >= 12 move maandnaam(sub) to tekst move maandaantal(sub) to aantal display toonregel end-perform display space display "RESULTATEN PER WEEKDAG" perform with test after varying sub from 1 by 1 until sub >= 7 move dagnaam(sub) to tekst move weekdagaantal(sub) to aantal display toonregel end-perform.