Skip to content
Book 6: Algorithms, Programming and Logic

Book 6 · Chapter 0

How Paper 2 works

Exam craftExam craftB6·0

This chapter is in the ebook.

Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.

Open in the ebook

About this chapter

This chapter is about how the paper works rather than one syllabus section. Its companion material arrives with the chapter.

The paper at a glance

Short code B6·0·10

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

What each command word wants

Short code B6·0·11

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Pseudocode that earns marks

Short code B6·0·12

// Counts the library books returned late
CONSTANT MaxDays ← 14
DECLARE Kept : INTEGER
DECLARE Late : INTEGER
DECLARE Book : INTEGER
Late ← 0
FOR Book ← 1 TO 3
    OUTPUT "Days kept for book ", Book, "?"
    INPUT Kept
    IF Kept > MaxDays
      THEN
        OUTPUT "Late by ", Kept - MaxDays, " days"
        Late ← Late + 1
      ELSE
        OUTPUT "On time"
    ENDIF
NEXT Book
OUTPUT Late, " book(s) returned late"
Written the Cambridge way: a comment, a CONSTANT, every variable declared, ← for assignment, keywords in capitals and the body of each statement indented. Lines beginning › are the values typed in.

Output

Days kept for book 1?
› 10
On time
Days kept for book 2?
› 17
Late by 3 days
Days kept for book 3?
› 14
On time
1 book(s) returned late
Run and checked before printing

Program code: the scenario only

Short code B6·0·13

DECLARE Laps : INTEGER
REPEAT
    OUTPUT "Number of laps (1 to 40)?"
    INPUT Laps
    IF Laps < 1 OR Laps > 40
      THEN
        OUTPUT "Error: 1 to 40 only"
    ENDIF
UNTIL Laps >= 1 AND Laps <= 40
OUTPUT "Accepted: ", Laps
A range check in a REPEAT loop: the prompt and the error message are outputs, so they appear in the run.

Output

Number of laps (1 to 40)?
› 0
Error: 1 to 40 only
Number of laps (1 to 40)?
› 45
Error: 1 to 40 only
Number of laps (1 to 40)?
› 12
Accepted: 12
Run and checked before printing
print("Number of laps (1 to 40)?")
Laps = int(input())
while Laps < 1 or Laps > 40:
    print("Error: 1 to 40 only")
    print("Number of laps (1 to 40)?")
    Laps = int(input())
print("Accepted:", Laps)
The same range check in Python, VB.NET and Java. Python has no REPEAT loop, so the first input comes before a WHILE loop. All three give the same output for 0, 45 and 12.

Output

Number of laps (1 to 40)?
Error: 1 to 40 only
Number of laps (1 to 40)?
Error: 1 to 40 only
Number of laps (1 to 40)?
Accepted: 12
Run and checked before printing

Flowcharts by the rules

Short code B6·0·14

DECLARE Laps : INTEGER
REPEAT
    OUTPUT "Number of laps (1 to 40)?"
    INPUT Laps
    IF Laps < 1 OR Laps > 40
      THEN
        OUTPUT "Error: 1 to 40 only"
    ENDIF
UNTIL Laps >= 1 AND Laps <= 40
OUTPUT "Accepted: ", Laps
A range check in a REPEAT loop: the prompt and the error message are outputs, so they appear in the run.

Output

Number of laps (1 to 40)?
› 0
Error: 1 to 40 only
Number of laps (1 to 40)?
› 45
Error: 1 to 40 only
Number of laps (1 to 40)?
› 12
Accepted: 12
Run and checked before printing

Trace tables without lost marks

Short code B6·0·15

Output

Size?
› 80
Size?
› 95
Size?
› 70
Size?
› 90
3 files, 245 MB
Run and checked before printing
DECLARE Size : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
Total ← 0
Count ← 0
OUTPUT "Size?"
INPUT Size
WHILE Size > 0 AND Total + Size <= 300 DO
    Total ← Total + Size
    Count ← Count + 1
    OUTPUT "Size?"
    INPUT Size
ENDWHILE
OUTPUT Count, " files, ", Total, " MB"
Predict: the same download program is run with the file sizes 120, 150 and 40. What does it output?

Output

Size?
› 120
Size?
› 150
Size?
› 40
2 files, 270 MB
Run and checked before printing

Timing the paper

Short code B6·0·16

Output

Size?
› 120
Size?
› 150
Size?
› 40
2 files, 270 MB
Run and checked before printing

How the 15-mark scenario is marked

Short code B6·0·17

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

A scenario, planned and written

Short code B6·0·18

// Declarations: not needed in the exam
DECLARE Name : ARRAY[1:30] OF STRING
DECLARE Books : ARRAY[1:30, 1:4] OF INTEGER
DECLARE Total : ARRAY[1:30] OF INTEGER
DECLARE Pupils : INTEGER
DECLARE Pupil : INTEGER
DECLARE Week : INTEGER
DECLARE Number : INTEGER
DECLARE Golds : INTEGER
DECLARE Best : INTEGER
DECLARE ClassTotal : INTEGER
DECLARE Average : REAL

// R1: number of students (1 to 30)
REPEAT
    OUTPUT "How many students (1 to 30)?"
    INPUT Pupils
    IF Pupils < 1 OR Pupils > 30
      THEN
        OUTPUT "Error: 1 to 30 only"
    ENDIF
UNTIL Pupils >= 1 AND Pupils <= 30

// R2: each name, then 4 weeks of books
FOR Pupil ← 1 TO Pupils
    OUTPUT "Name of student ", Pupil, "?"
    INPUT Name[Pupil]
    Total[Pupil] ← 0
    FOR Week ← 1 TO 4
        // R3: validate the books (0 to 10)
        REPEAT
            OUTPUT "Books in week ", Week, "?"
            INPUT Number
            IF Number < 0 OR Number > 10
              THEN
                OUTPUT "Error: 0 to 10 only"
            ENDIF
        UNTIL Number >= 0 AND Number <= 10
        Books[Pupil, Week] ← Number
        // R4: add to this student's total
        Total[Pupil] ← Total[Pupil] + Number
    NEXT Week
NEXT Pupil

// R5: each total; mark and count Golds
Golds ← 0
Best ← 1
ClassTotal ← 0
FOR Pupil ← 1 TO Pupils
    OUTPUT Name[Pupil], ": ", Total[Pupil]
    IF Total[Pupil] >= 12
      THEN
        OUTPUT "Gold award"
        Golds ← Golds + 1
    ENDIF
    // R6: position of the highest total
    IF Total[Pupil] > Total[Best]
      THEN
        Best ← Pupil
    ENDIF
    ClassTotal ← ClassTotal + Total[Pupil]
NEXT Pupil
OUTPUT "Gold awards: ", Golds
OUTPUT "Most books: ", Name[Best]
OUTPUT "Their total: ", Total[Best]
Average ← ROUND(ClassTotal / Pupils, 1)
OUTPUT "Class average: ", Average
The whole reading-challenge program in pseudocode. Each comment names the requirement its section meets. It was run with the test data given below; the declarations at the top are not needed in the exam.
Run and checked before printing
# lists hold 30 students; positions start at 0
Name = [""] * 30
Books = [[0, 0, 0, 0] for S in range(30)]
Total = [0] * 30
# R1: input and validate the number of students
print("How many students (1 to 30)?")
Students = int(input())
while Students < 1 or Students > 30:
    print("Error: 1 to 30 only")
    print("How many students (1 to 30)?")
    Students = int(input())
# R2: each name, then the books for each week
for Student in range(Students):
    print("Name of student " + str(Student + 1) + "?")
    Name[Student] = input()
    for Week in range(4):
        # R3: validate the books read (0 to 10)
        print("Books in week " + str(Week + 1) + "?")
        Number = int(input())
        while Number < 0 or Number > 10:
            print("Error: 0 to 10 only")
            print("Books in week " + str(Week + 1) + "?")
            Number = int(input())
        Books[Student][Week] = Number
        # R4: add the week to the student's total
        Total[Student] = Total[Student] + Number
# R5: output every total; mark and count Golds
Golds = 0
Best = 0
ClassTotal = 0
for Student in range(Students):
    print(Name[Student] + ":", Total[Student])
    if Total[Student] >= 12:
        print("Gold award")
        Golds = Golds + 1
    # R6: keep the position of the highest total
    if Total[Student] > Total[Best]:
        Best = Student
    ClassTotal = ClassTotal + Total[Student]
print("Gold awards:", Golds)
print("Most books:", Name[Best])
print("Their total:", Total[Best])
print("Class average:", round(ClassTotal / Students, 1))
The reading-challenge program in Python, VB.NET and Java, given the same 19 inputs (0, then 3 students, with 11 and −1 rejected). Python's lists start at 0, so it adds 1 to each number it shows; VB.NET and Java leave position 0 unused, so the numbers match the scenario.

Output

How many students (1 to 30)?
Error: 1 to 30 only
How many students (1 to 30)?
Name of student 1?
Books in week 1?
Books in week 2?
Books in week 3?
Error: 0 to 10 only
Books in week 3?
Books in week 4?
Name of student 2?
Books in week 1?
Books in week 2?
Books in week 3?
Books in week 4?
Name of student 3?
Books in week 1?
Books in week 2?
Error: 0 to 10 only
Books in week 2?
Books in week 3?
Books in week 4?
Amna: 14
Gold award
Bilal: 8
Chen: 15
Gold award
Gold awards: 2
Most books: Chen
Their total: 15
Class average: 12.3
Run and checked before printing

Where marks are lost

Short code B6·0·19

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Workbook: How Paper 2 works

Short code W6·0 · Algorithms, Programming and Logic Workbook

The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.

Ask Z about How Paper 2 works
Buy ZAK's books — WhatsApp the books desk: Buy the booksPrint or ebook