The Pass Mark That Passed Nobody
A II PUC student writes an algorithm for the school result rule: read marks; if marks > 35 print 'Pass'; else print 'Fail'. The teacher tests marks = 35 and gets 'Fail', although the rule says exactly 35 is a pass. The same student writes a flowchart to find the largest of three numbers. It checks if a > b and a > c, then prints a; otherwise if b > a and b > c, it prints b; otherwise it prints c. With a = 10, b = 10, c = 5, it prints 5. The student argues that the logic is correct because it works for 10, 8, 5. The teacher wants the student to reason about boundary values, equality, and test-case design before writing C++ code. In the practical exam, the student must submit pseudocode and a dry-run table, and the teacher will award marks for the quality of the test cases, not only for the final output. The student has 45 minutes and may not use a computer.
1. Identify the boundary error in the result algorithm, rewrite it, and explain why 'it works for 10, 8, 5' is not evidence of correctness.
Read the worked answer
The error is the strict comparison. The rule says exactly 35 passes, but marks > 35 sends 35 to the else branch. The corrected decision is if (marks >= 35) print "Pass"; else print "Fail";, with input validation for marks below 0, above the maximum, or absent. The test 10, 8, 5 exercises only one path of the largest-of-three logic; it never tests equality, the middle value as maximum, negative values, or all-equal values. A single successful run shows that one input works, not that the algorithm is correct. Correctness needs reasoning about every branch and boundary, supported by a test table that includes 34, 35, and 36 for the pass rule.
2. Trace a=10, b=10, c=5 through the largest-of-three logic and correct it. Make sure ties print a correct maximum.
Read the worked answer
Trace: a > b is 10 > 10, false, so the first branch is skipped. b > a is also false, so control reaches the else and prints c, which is 5. The maximum is 10, so the output is wrong. The strict comparisons cannot distinguish 'greater than' from 'greater than or equal to', and with equal maxima the first two tests both fail. A corrected version is:
if (a >= b and a >= c) print a
else if (b >= a and b >= c) print b
else print c
This prints a correct maximum for ties: 10, 10, 5 prints 10, and 7, 7, 7 prints 7. The order of the tests still matters for which tied value is printed, but not for the value of the maximum.
3. Design four dry-run test cases for the corrected algorithm, including all equal, and explain what each catches.
Read the worked answer
| a | b | c | Expected | What the case catches |
|---|---|---|---|---|
| 10 | 8 | 5 | 10 | Baseline where the first value is largest |
| 10 | 10 | 5 | 10 | Tie for largest; catches the strict > error |
| 5 | 10 | 8 | 10 | Largest in the middle; catches an assumption that a wins |
| 7 | 7 | 7 | 7 | All equal; catches fall-through to c |
| -3 | -7 | -3 | -3 | Negative values and a tie; catches sign or initialization errors |
Each row should record the path taken, not just the printed answer. The all-equal case is especially important because it forces every > test to fail and exposes whether the final else is being used as a default rather than as a proven maximum. The negative case checks that the algorithm does not initialize the maximum to 0 or assume positive inputs.