Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Subject:
Topics:
Avg
score:
–
Topics
done:
0/32

Totalling, counting, maximum, minimum and average

Practise 36 exam-style questions on Totalling, counting, maximum, minimum and average for Cambridge IGCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with an AI tutor on hand if you get stuck.

  • 36 questions
  • 1–6 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

1 mark

The array Values[1:20] holds 20 numbers.

Highest ← Values[1]
FOR Index ← 2 TO 20
    IF Values[Index] > Highest
      THEN
        Highest ← Values[Index]
    ENDIF
NEXT Index

Explain why the FOR loop starts at 2 and not at 1.

Model answer

Highest already holds Values[1], so comparing Values[1] with Highest would be pointless; the loop only needs to check the remaining elements, 2 to 20.

Explanation

Starting at 1 would still give the right answer, but it wastes one comparison. Starting at 2 only works because Highest was initialised to the first element.

Mark scheme
  1. 1 mark

    Values[1] has already been used as the starting value of Highest, so it does not need to be compared (with itself)

Question 2

2 marks

The array Lengths[1:3] holds the values 2.5, 3.0 and 4.2.

Total ← 0
FOR Index ← 1 TO 3
    Total ← Total + Lengths[Index]
NEXT Index
OUTPUT ROUND(Total / 3, 1)

State the value of Total after the loop and the value that is output.

Model answer

Total = 9.7
Output: 3.2

Explanation

The three lengths add up to 9.7, and 9.7 ÷ 3 = 3.2333... ROUND(..., 1) rounds this to one decimal place, giving 3.2.

Mark scheme
  1. 1 mark

    Total = 9.7

  2. 1 mark

    Output: 3.2

    Do not accept 3.23 or 3.233...

Question 3

3 marks

The table shows the two-dimensional array Points[1:3, 1:4]. Points[Team, Game] holds the points scored by a team in one game.

FOR Team ← 1 TO 3
    Total ← 0
    FOR Game ← 1 TO 4
        Total ← Total + Points[Team, Game]
    NEXT Game
    OUTPUT "Team ", Team, ": ", Total
NEXT Team

Give the output.

Array: Points. Table with columns "Team", "Game 1", "Game 2", "Game 3", "Game 4". Team: 1; Game 1: 3; Game 2: 1; Game 3: 0; Game 4: 3 | Team: 2; Game 1: 1; Game 2: 1; Game 3: 3; Game 4: 3 | Team: 3; Game 1: 0; Game 2: 3; Game 3: 1; Game 4: 0.

Model answer

Team 1: 7
Team 2: 8
Team 3: 4

Explanation

The outer loop takes one team (row) at a time and the inner loop adds up the four games in that row. Total is reset to 0 at the start of each team, inside the outer loop, so each output is the total for one team only.

Mark scheme
  1. 1 mark

    Team 1: 7

  2. 1 mark

    Team 2: 8

  3. 1 mark

    Team 3: 4

Question 4

5 marks

The global array Heights[1:100] holds the heights, in metres, of 100 trees.

Write pseudocode for a function CountAbove that takes a height limit as a parameter and returns the number of trees that are taller than the limit. Then write a statement that uses CountAbove to output the number of trees taller than 12.5 m.

Model answer

FUNCTION CountAbove(Limit : REAL) RETURNS INTEGER
    DECLARE Count : INTEGER
    DECLARE Tree : INTEGER
    Count ← 0
    FOR Tree ← 1 TO 100
        IF Heights[Tree] > Limit
          THEN
            Count ← Count + 1
        ENDIF
    NEXT Tree
    RETURN Count
ENDFUNCTION

OUTPUT "Trees taller than 12.5 m: ", CountAbove(12.5)

Explanation

The function counts with a local variable that starts at 0 each time it is called, and hands back the count with RETURN only after every element has been checked. The parameter makes the function reusable for any limit; the call goes inside the OUTPUT statement because a function returns a value.

Mark scheme
  1. 1 mark

    MP1 function header with a REAL parameter and RETURNS INTEGER, ended with ENDFUNCTION

    max 5; e.g. FUNCTION CountAbove(Limit : REAL) RETURNS INTEGER

  2. 1 mark

    MP2 counter initialised to 0 inside the function, before the loop

  3. 1 mark

    MP3 loop through all 100 elements of Heights

  4. 1 mark

    MP4 compares Heights[Index] > the parameter and adds 1 to the counter when true

  5. 1 mark

    MP5 returns the counter after the loop

    Do not accept RETURN inside the loop

  6. 1 mark

    MP6 OUTPUT statement that calls CountAbove(12.5) in an expression (not with CALL)

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

AI Tutor Hints first, answers after you try

Hi! Stuck? Ask me for a hint and I’ll help you work it out. Once you’ve checked your answer I can explain exactly where the marks are.