Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Develop code

EasyMediumHard
123456789101112131415161718192021222324252627
Question 24

A school library tracks student book loans. The automated checkout duration is based on the student's secondary year group, which ranges from Year 7 to Year 13.

An algorithm must report the student's cohort name and loan period in days based on the year group number entered (e.g. 7 = Year 7, 13 = Year 13).

The following pseudocode algorithm does not produce accurate results. These are the test results:

InputExpected behaviourActual behaviour
8The Year 8 checkout period is 14 days.Potential runtime error: index out of range.
14The year group 14 is invalid.Potential runtime error: index out of range.
5The year group 5 is invalid.Potential runtime error: index out of range.

Figure 1 shows the lines of code with errors on lines 8, 9, and 10.

1 SET yearNames TO ["Year 7", "Year 8", "Year 9", "Year 10", "Year 11", "Year 12", "Year 13"]
2 SET loanPeriods TO [14, 14, 14, 21, 21, 28, 28]
3
4 SEND "Enter the year group (7-13). Enter 0 to exit." TO DISPLAY
5 RECEIVE yearGroup FROM (INTEGER) KEYBOARD
6
7 WHILE NOT (yearGroup = 0) DO
8     IF (yearGroup > 7) OR (yearGroup < 13) THEN
9         SET name TO yearNames[yearGroup]
10        SET period TO loanPeriods[yearGroup]
11
12        SEND "The " & name & " checkout period is " & period & " days." TO DISPLAY
13    ELSE
14        SEND "The year group " & yearGroup & " is invalid." TO DISPLAY
15    ENDIF
16
17    SEND "Enter the year group (7-13). Enter 0 to exit." TO DISPLAY
18    RECEIVE yearGroup FROM (INTEGER) KEYBOARD
19 END WHILE

Write the corrected replacement codes for line 8, line 9, and line 10.

[4]

Develop code Questions

  1. IGCSE
  2. /Computer Science
  3. /Develop code