Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
Question 51

Figure 1 shows an algorithm designed to validate booking times at a sports court and calculate the duration of the booking.

Figure 1

1  validBooking ← False
2  REPEAT
3      duration ← -1
4      OUTPUT 'Enter start hour'
5      startHour ← USERINPUT
6      OUTPUT 'Enter end hour'
7      endHour ← USERINPUT
8      IF startHour ≥ endHour THEN
9          OUTPUT 'Start hour must be before end hour'
10     ELSE
11         IF startHour > 12 THEN
12             OUTPUT 'Start hour must be before noon'
13         ELSE
14             validBooking ← True
15         ENDIF
16     ENDIF
17 UNTIL validBooking = True
18 duration ← endHour - startHour
19 OUTPUT duration

Table 1 shows three tests used to check the algorithm in Figure 1.

Complete the table to show what the values of the validBooking and duration variables would be at the end of each independent test execution.

Table 1

Test typeTest datavalidBookingduration
NormalstartHour10
endHour15
ErroneousstartHour14
endHour11
BoundarystartHour12
endHour16
[4]
Markscheme

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms

208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank