Skip to content

Course home

Boolean operations in a programming language

Boolean operations in a programming language

EasyMedium
123456789101112131415161718
Question 14

A programmer is writing a subroutine to determine if an item is available within a customer's budget.

1   SUBROUTINE CheckDiscount(itemID, maxPrice)
2       ids ← ['A102', 'B205', 'C309']
3       prices ← [15.50, 24.00, 8.99]
4       i ← 0
5       found ← false
6       WHILE i < 3
7           IF ids[i] = itemID THEN
8               IF prices[i] <= maxPrice THEN
9                   found ← true
10              ENDIF
11          ENDIF
12          i ← i + 1
13      ENDWHILE
14      RETURN found
15  ENDSUBROUTINE

Lines 7 and 8 could be replaced with a single line.

Select the option that corresponds to the correct new line.

A

IF ids[i] = itemID OR prices[i] <= maxPrice THEN\text{IF ids[i] = itemID OR prices[i] <= maxPrice THEN}IF ids[i] = itemID OR prices[i] <= maxPrice THEN

B

IF ids[i] = itemID AND prices[i] <= maxPrice THEN\text{IF ids[i] = itemID AND prices[i] <= maxPrice THEN}IF ids[i] = itemID AND prices[i] <= maxPrice THEN

C

IF NOT (ids[i] = itemID AND prices[i] <= maxPrice) THEN\text{IF NOT (ids[i] = itemID AND prices[i] <= maxPrice) THEN}IF NOT (ids[i] = itemID AND prices[i] <= maxPrice) THEN

D

IF ids[i] = itemID AND prices[i] > maxPrice THEN\text{IF ids[i] = itemID AND prices[i] > maxPrice THEN}IF ids[i] = itemID AND prices[i] > maxPrice THEN

Markscheme

Boolean operations in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /Boolean operations in a programming language

19 exam-style questions on AQA GCSE Computer Science Boolean operations in a programming language. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank