Year 10 · Computer Science · Summer 1

Software · Lesson 5 of 5

Programming practice: a scenario question

Exam practice7.9 Writing and amending algorithms8.2 Arrays

Year 10 · Computer Science · Software · Lesson 5 of 5

You will learn to

  • Plan a 15-mark scenario question in ten minutes: a numbered task list, the arrays and the variables.
  • Write the solution in fifteen minutes, with meaningful names and comments.
  • Test the solution in five minutes against the task list.
  • Use the mark scheme to find the requirements you met and the ones you missed.

Year 10 · Computer Science · Software · Lesson 5 of 5

Success criteria

You have got it when you can say:

  • I can turn a scenario into a numbered checklist of tasks.
  • I can write a solution that uses an array, a loop and validation.
  • I can mark my answer with the scheme and name one requirement I missed.

Year 10 · Computer Science · Software · Lesson 5 of 5

Retrieval starter

Questions from before. Write your answers, then show them.

  1. Last lesson

    An interpreter stops…

    A Only after translating everythingB NeverC At the first error it meets

    C. At the first error it meets

  2. Last unit

    17 MOD 5 is…

    A 3.4B 3C 2

    C. 2

  3. Earlier this year

    The ALU does…

    A Fetching instructionsB Storing filesC Arithmetic and logic

    C. Arithmetic and logic

Year 10 · Computer Science · Software · Lesson 5 of 5

Key words (1 of 4)

Algorithm
A precise, ordered set of steps that solves a problem.
Program development life cycle
The four stages of making a program: analysis, design, coding and testing.
Structure diagram
A top-down diagram that shows how a system is split into sub-systems.
Pseudocode
A structured, code-like way of writing an algorithm that is not tied to one language.

Year 10 · Computer Science · Software · Lesson 5 of 5

Key words (2 of 4)

Totalling
Keeping a running total by adding each value to a total variable.
Counting
Adding 1 to a counter variable each time something happens.
Bubble sort
Sorting by comparing neighbouring items and swapping them if they are in the wrong order, pass after pass.

Year 10 · Computer Science · Software · Lesson 5 of 5

Key words (3 of 4)

Validation
An automatic check that input data is reasonable and follows set rules.
Check digit
An extra digit calculated from the other digits, used to catch typing errors.
Variable
A named place in memory whose value can change while the program runs.
Identifier
The name given to a variable, constant, array or subroutine.

Year 10 · Computer Science · Software · Lesson 5 of 5

Key words (4 of 4)

Data type
The kind of value stored: INTEGER, REAL, CHAR, STRING or BOOLEAN.
Selection
Choosing which statements to run using a condition (IF or CASE).
Iteration
Repeating a block of statements in a loop.
Array
A data structure holding many values of the same data type under one name, each found by its index.

7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 1 of 5

Be precise, and amend with care

An algorithm must say exactly what to do. 'More than 50' is `> 50`. '50 or more' is `>= 50`. These give different results for 50.

Set every total, counter, highest and lowest to a start value before the loop. Use meaningful names like `PassCount`, not `x`, and `//` comments.

An amend question asks you to change a given algorithm. Find the line that controls the behaviour and change only that line.

7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 2 of 5

Be precise, and amend with care (continued)

Example: to make the bubble sort give descending order (largest first), change `>` to `<` in the comparison.

Words in the questionPseudocode
over 18 / more than 18`Age > 18`
18 or over / at least 18`Age >= 18`
under 18 / less than 18`Age < 18`
between 1 and 21 inclusive`Days >= 1 AND Days <= 21`
not equal to -1`Value <> -1`

7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 3 of 5

Be precise, and amend with care (continued)

e.g.Example
7, 3, 9, 2, 5 sorted with the amended line: Output: 9, 7, 5, 3, 2
// Original: sorts into ascending order (smallest first)
IF Numbers[Index] > Numbers[Index + 1]

// Amended: sorts into descending order (largest first)
IF Numbers[Index] < Numbers[Index + 1]

7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 4 of 5

Be precise, and amend with care (continued)

numbers = [7, 3, 9, 2, 5]
top = 5
swap = True
while swap == True and top > 1:
    swap = False
    for index in range(top - 1):
        # amended: < instead of > gives descending order
        if numbers[index] < numbers[index + 1]:
            temp = numbers[index]
            numbers[index] = numbers[index + 1]
            numbers[index + 1] = temp
            swap = True
    top = top - 1
print(numbers)

7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 5 of 5

Be precise, and amend with care (continued)

?Why?

Rewriting the whole algorithm wastes time and can add new errors. The examiner is looking for the one or two key changes.

!Watch out

`Days >= 1 AND <= 21` is wrong. Write the variable on both sides: `Days >= 1 AND Days <= 21`.

7.9 Writing and amending algorithms · The explanation · step 2 of 9 · part 1 of 3

The 15-mark scenario question: plan first

The last question on Paper 2 is a scenario worth 15 marks. Allow about 30 minutes. You may answer in pseudocode, Python, Visual Basic or Java.

Read the scenario twice. Underline every task. Make a numbered checklist and tick each item as you code it.

Sample scenario: a teacher records three tests for each of 30 students. Each test is out of 50. Names are already in `StudentName[1:30]`.

7.9 Writing and amending algorithms · The explanation · step 2 of 9 · part 2 of 3

The 15-mark scenario question: plan first (continued)

e.g.Example
Tasks in the sample scenario: 1. Input three marks per student and store them in StudentMark[1:30, 1:3]. 2. Validate each mark: 0 to 50. 3. Calculate and store each student's total in StudentTotal[1:30]. 4. Calculate each student's average, rounded to 1 decimal place. 5. Output each name with total and average. 6. Count and output the students with a total of 120 or more (a merit). 7. Output the class average total and the name of the student with the highest total. All inputs and outputs need suitable messages.

7.9 Writing and amending algorithms · The explanation · step 2 of 9 · part 3 of 3

The 15-mark scenario question: plan first (continued)

?Why?

Marks are given for meeting each requirement. A checklist stops you forgetting one, which is the most common way to lose marks here.

7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 1 of 4

How the 15 marks are awarded

Recent mark schemes use levels, not one mark per line. AO2 (applying techniques and data structures) gives up to 9 marks. AO3 (comments, identifiers, logic and accuracy) gives up to 6 marks.

The examiner reads the whole answer and picks the band that fits best. Minor syntax errors are ignored if the logic is clear.

7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 2 of 4

How the 15 marks are awarded (continued)

BandAO2: techniques and data structures (9)AO3: comments, names, accuracy (6)
Top7–9: all tasks covered with the right techniques; arrays store all the data5–6: fully commented, meaningful names, logical and accurate, meets all requirements
Middle4–6: some techniques suit the problem; some data stored correctly3–4: some comments, most names sensible, most requirements attempted
Low1–3: at least one technique used; some data stored, not well1–2: no useful comments, some sensible names, at least one requirement attempted

7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 3 of 4

How the 15 marks are awarded (continued)

e.g.Example
The model answer reaches the top bands because it: - inputs with messages and validates every mark (input, iteration, selection) - stores marks in the 2D array and totals in StudentTotal (data structures) - uses totalling, counting, maximum, average and ROUND - outputs every result with a message - has a comment for every section and meaningful names like MeritCount

7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 4 of 4

How the 15 marks are awarded (continued)

?Why?

Because marks come in bands, a working answer to every task beats a perfect answer to half of them. Attempt every requirement, even if one part is rough.

The explanation · 6 more steps

More on the lesson page

The lesson page has the rest of the explanation, step by step:

  • Model answer in pseudocode and Python
  • What an array is
  • Using a variable as the index
  • 2D arrays: rows and columns
  • Nested loops to visit every element
  • Initialising a 2D array

Open the lesson page

Year 10 · Computer Science · Software · Lesson 5 of 5

Quick quiz · 1 of 3

An IDE provides…

  1. A An editor, a run button and a debugger
  2. B Only the keyboard
  3. C The operating system

A. An editor, a run button and a debugger

Integrated development environment: everything for writing code in one app.

Year 10 · Computer Science · Software · Lesson 5 of 5

Quick quiz · 2 of 3

Which of these is system software?

  1. A A word processor
  2. B A game
  3. C The operating system

C. The operating system

System software runs the computer. Applications do jobs for people.

Year 10 · Computer Science · Software · Lesson 5 of 5

Quick quiz · 3 of 3

The bootloader…

  1. A Translates Python
  2. B Prints documents
  3. C Loads the operating system from storage into RAM at start-up

C. Loads the operating system from storage into RAM at start-up

It lives in ROM and runs first when the power comes on.

Year 10 · Computer Science · Software · Lesson 5 of 5

Exit ticket

Answer on paper before you go. Then check.

  1. An interrupt is…

    A A signal that makes the CPU pause and deal with somethingB A type of virusC A loop that never ends

    A. A signal that makes the CPU pause and deal with something A key press or a printer out of paper. The CPU saves its place, handles it, carries on.

  2. A compiler…

    A Only checks spellingB Translates the whole program once into machine codeC Translates one line at a time, every run

    B. Translates the whole program once into machine code It produces an executable file. Errors are reported at the end.

Year 10 · Computer Science · Software · Lesson 5 of 5

Homework and the challenge

Homework

The CS 4 quiz.

End-of-unit challenge

End-of-unit test: past-paper questions on topic 4, plus the scenario question.