GCE O/L Information & Communication Technology study materials
GCE O/L Information & Communication Technology study resources

The Mark-Recording Program with the Minus-One Problem

GCE O/L Information & Communication Technology · Put your knowledge to work in context.

All case studies

The Mark-Recording Program with the Minus-One Problem

A small tuition institute uses a program to summarise the results of a class of ten students. The clerk enters each mark from 0 to 100, but when a student is absent the clerk types -1 so that the absence is visible on the printout. The current pseudocode is:

total = 0 count = 0 FOR i = 1 TO 10 INPUT mark total = total + mark count = count + 1 NEXT i average = total / count IF average >= 50 THEN PRINT 'Pass group' ELSE PRINT 'Fail group'

The clerk enters: 60, 55, 72, 48, 65, 58, -1, -1, -1, 90.

1. Trace the pseudocode with the given data. State the output, and explain the two separate faults that make the output misleading.

Read the worked answer

Trace

  • Sum = 60 + 55 + 72 + 48 + 65 + 58 - 1 - 1 - 1 + 90 = 445
  • count = 10 (the loop counts every iteration, including absences)
  • average = 445 / 10 = 44.5
  • 44.5 < 50, so the program prints 'Fail group'

Fault 1: the absence marker is treated as a mark. Three absent students contribute -3 to the total and still inflate the divisor to 10. The seven students who actually sat scored 448 in total, so their true mean is 448 / 7 = 64.0, which is a comfortable pass. The program therefore reports the opposite conclusion to the truth.

Fault 2: the wrong question is answered. The institute needs each student's own pass or fail decision. A single group average can hide a student on 48 inside a strong class, or hide a student on 90 inside a weak one.

A third, smaller issue is that no validation exists: a typing error such as 1000 or -7 would be accepted silently.

2. Rewrite the pseudocode so that absent students are excluded from the average, each student receives an individual pass or fail, and impossible marks are rejected.

Read the worked answer
total = 0
count = 0
FOR i = 1 TO 10
    INPUT name
    INPUT mark
    IF mark = -1 THEN
        PRINT name, 'Absent'
    ELSE IF mark < 0 OR mark > 100 THEN
        PRINT name, 'Invalid mark - not recorded'
    ELSE
        IF mark >= 50 THEN
            PRINT name, 'Pass'
        ELSE
            PRINT name, 'Fail'
        END IF
        total = total + mark
        count = count + 1
    END IF
NEXT i
IF count > 0 THEN
    PRINT 'Average of students present = ', total / count
ELSE
    PRINT 'No valid marks entered'
END IF

Why this is correct

  • The selection is a three-way decision: absent, invalid, or a genuine mark. Only genuine marks reach the accumulator and the counter, so the divisor is the number of students who sat.
  • The individual result is printed inside the loop, where the single mark is known, rather than from a group average.
  • Guarding count > 0 prevents a division-by-zero crash if the whole class is absent, which is a realistic edge case the original would not survive.
  • A better long-term design would store absence as a blank or a separate flag rather than a magic number, since -1 will eventually collide with a real mark if the marking scale ever changes.

3. Describe two validation checks you would add and give a set of test data, with expected outputs, that would prove the corrected program handles boundaries and absences properly.

Read the worked answer

Validation checks

  1. Range check: a mark must be either -1 (absent) or a whole number from 0 to 100. Anything else is rejected and re-entered.
  2. Presence/type check: the program must not accept a blank or text entry in place of a mark, because a blank becomes 0 or crashes the arithmetic. A limit check on the loop count would also protect against an operator entering more students than the array or report allows.

Test data (boundary and exception testing)

Input mark Expected output What it proves
50 Pass Lower pass boundary is inside the pass band
49 Fail Just below the boundary is not rounded up
100 Pass Upper boundary accepted
101 Invalid mark Upper boundary is enforced
-1 Absent Absence is excluded from the average

Expected summary: with 50, 49, 100 and -1 entered, count = 3, total = 199, average = 66.33, and the report shows one absent student. This set proves the boundary conditions are correct and that the -1 bug cannot return; testing only ordinary marks such as 60 or 70 would have missed it entirely.