Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
Question 85

A programmer is writing an algorithm to output and sum the quarterly performance figures for four regional branches of a retail business during three quarters of a year. Each branch has 3 sales figures recorded, making 12 historical records in total.

The algorithm in Figure 1 contains a logical error and does not process all of the sales figures.

Figure 1

1  regions ← ['North', 'East', 'South', 'West']
2  sales ← [120, 150, 130, 90, 110, 95, 200, 210, 205, 80, 85, 90]
3  totalSales ← 0
4  FOR i ← 0 TO 3
5      area ← regions[i]
6      OUTPUT 'Region: ', area
7      FOR j ← 0 TO 1
8          OUTPUT 'Quarterly Record: ', j + 1
9          val ← sales[i * 3 + j]
10         OUTPUT val
11         totalSales ← totalSales + val
12     ENDFOR
13 ENDFOR

How could the error in the algorithm in Figure 1 be corrected so that all sales figures are processed?

A

Change line number 3 to: totalSales ← -1

B

Change line number 4 to: FOR i ← 0 TO 4

C

Change line number 7 to: FOR j ← 0 TO 2

D

Change line number 9 to: val ← sales[j * 4 + i]

Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

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

Question bank