Test Grading Example

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TEST-CARDS
ASSIGN TO 'C:\PCOBWIN\ROGERS\TESTCARD.TXT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT GRADE-REPORT
ASSIGN TO 'C:\PCOBWIN\ROGERS\RESULTS.TXT'
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.

FD TEST-CARDS
DATA RECORD IS CARD-IN.
01 CARD-IN.
02 CARD-NAME PIC X(20).
02 CARD-ANSWERS.
03 CARD-ANSWER
OCCURS 20 TIMES PIC X.

FD GRADE-REPORT
DATA RECORD IS REPORT-LINE.
01 REPORT-LINE PIC X(80).

WORKING-STORAGE SECTION.

01 ANSWER-TABLE.
02 CORRECT-ANSWER
OCCURS 20 TIMES PIC X.

01 ANSWER-SUB PIC 9(2).

01 WS-SCORE PIC 9(3).

01 DETAIL-LINE.
02 DETAIL-NAME PIC X(20).
02 PIC X(5) VALUE SPACES.
02 DETAIL-SCORE PIC ZZ9.
02 PIC X VALUE '%'.
02 PIC X(5) VALUE SPACES.
02 DETAIL-LETTER PIC X.

01 DATA-REMAINS-SWITCH PIC X VALUE 'Y'.
88 NO-MORE-TESTS-TO-GRADE VALUE 'N'.

PROCEDURE DIVISION.
MAIN-LINE.
PERFORM LETS-GET-STARTED.
PERFORM GRADE-THE-TESTS
UNTIL NO-MORE-TESTS-TO-GRADE.
PERFORM CLEAN-UP.
STOP RUN.

LETS-GET-STARTED.
OPEN INPUT TEST-CARDS.
OPEN OUTPUT GRADE-REPORT.
* Read the answer key and save it
READ TEST-CARDS
AT END MOVE 'N' TO DATA-REMAINS-SWITCH.
MOVE CARD-ANSWERS TO ANSWER-TABLE.
* Read the first student's answers
READ TEST-CARDS
AT END MOVE 'N' TO DATA-REMAINS-SWITCH.

GRADE-THE-TESTS.
MOVE ZERO TO WS-SCORE.
PERFORM GRADE-A-TEST
VARYING ANSWER-SUB FROM 1 BY 1
UNTIL ANSWER-SUB > 20.
MOVE CARD-NAME TO DETAIL-NAME.
MOVE WS-SCORE TO DETAIL-SCORE.
IF WS-SCORE > 92
MOVE 'A' TO DETAIL-LETTER
ELSE IF WS-SCORE > 84
MOVE 'B' TO DETAIL-LETTER
ELSE IF WS-SCORE > 75
MOVE 'C' TO DETAIL-LETTER
ELSE IF WS-SCORE > 69
MOVE 'D' TO DETAIL-LETTER
ELSE
MOVE 'F' TO DETAIL-LETTER
END-IF
END-IF
END-IF
END-IF.
WRITE REPORT-LINE FROM DETAIL-LINE.
* Read the next student's answers
READ TEST-CARDS
AT END MOVE 'N' TO DATA-REMAINS-SWITCH.

GRADE-A-TEST.
* 20 questions are each worth 5 points
IF CARD-ANSWER (ANSWER-SUB) = CORRECT-ANSWER (ANSWER-SUB)
ADD 5 TO WS-SCORE.

CLEAN-UP.
CLOSE TEST-CARDS.
CLOSE GRADE-REPORT.

Input Data

                    ACBDAABCDDDAABDDAAAB
Jason Dube ACBDAABBDDDAABDDAAAB
Ashley Flynn ACBDAABCDDDAABDDAAAB
Adriane Gehl ACBDAABCDDDAABACAAAB
Rachel Holtz BCBBAABCDDDAABDDDAAB
Bryan King ACBCAA CABCAABDDAAAB
Amanda Solpa ACBDAABCDDAAABDDAAAB
Sean Theis ACBDAABCADCAACDDAAAC

Output Report

Jason Dube                95%     A
Ashley Flynn 100% A
Adriane Gehl 90% B
Rachel Holtz 85% B
Bryan King 75% D
Amanda Solpa 95% A
Sean Theis 80% C