← All Paper 2 problems·All lessons
Paper 2 scenario practice

Capstone — school report system

The scenario
A school wants a program to process end-of-term marks for 5 students. The program must: 1. Read 5 (name, mark) pairs into TWO parallel arrays — one for names (STRING), one for marks (INTEGER). - Each mark must be VALIDATED: in range 0-100 inclusive. Invalid marks are REJECTED and the user is prompted again for the same student. 2. SORT the arrays by mark DESCENDING using a bubble sort. Names must STAY PAIRED with their marks during the sort — when two marks swap, their names also swap. 3. OUTPUT the top 3 to the screen, with rank labels: '1st: <name> — <mark>', etc. 4. WRITE all 5 students (name and mark, in sorted order) to a file called "report.txt", one per line. Write a program in pseudocode (or a high-level language of your choice). This is a capstone problem — it combines validation, parallel arrays, sorting, and file I/O. Marks will be awarded across all four areas.
Lessons that prepare for this: Lesson 19 — Pseudocode and flowcharts · Lesson 20 — Sorting algorithms · Lesson 24 — Arrays · Lesson 26 — File handling · Lesson 27 — Validation
Marking scheme — total 15 marks
Cambridge IGCSE 0478 Paper 2
  • 2
    Declare arrays and helpers: DECLARE names : ARRAY[1:5] OF STRING and marks : ARRAY[1:5] OF INTEGER. Plus the loop counters and a temp variable for swapping.
  • 4
    Read and validate input: FOR i ← 1 TO 5: read name; REPEAT read mark UNTIL it is in range 0-100. The validation must re-prompt for the SAME student until the mark is valid (not skip the student). Both arrays populated correctly.
  • 4
    Bubble sort with PAIRED swap: Outer FOR loop, inner FOR loop with adjacent comparison on marks. When a swap is needed, BOTH arrays must be swapped (marks AND names) so the pairing is preserved. Three temp variables (or two — one for marks, one for names) used in each swap.
  • 2
    Output top 3 to screen: After sorting, output the names and marks at positions 1, 2, 3 with rank labels.
  • 3
    Write all 5 students to file: OPENFILE "report.txt" FOR WRITE. FOR i ← 1 TO 5: WRITEFILE one line containing names[i] and marks[i]. CLOSEFILE "report.txt".
Hints — reveal one at a time, only if stuck
Your pseudocode workspace
1 line