Note AcademyNote Academy

Computer Science · May / June 2024 · Paper 21 · Question 4

0478

As printed in the paper

The question as text

This pseudocode algorithm is intended to allow, at random, between 1 and 20 values to be entered and totalled. The total and average of the entered values are output at the end of the algorithm. 01 DECLARE Loop : STRING 02 DECLARE Limit : INTEGER 03 DECLARE Value : REAL 04 DECLARE Total : REAL 05 Total 0 06 Limit ROUND(RANDOM() * 19,0) + 1 07 IF Loop 1 TO Limit 08 OUTPUT "Enter a number" 09 INPUT Loop 10 Total Total * Value 11 NEXT Loop 12 OUTPUT "The total of the numbers entered is ", Total 13 OUTPUT "The average of the numbers entered is ", Total / Limit

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme
  • 4(a)[4]

    One mark per mark point

    Line 01 / DECLARE Loop : STRING

    should be DECLARE Loop : INTEGER

    Line 07 / IF Loop ← 1 TO Limit

    should be FOR Loop ← 1 TO Limit

    Line 09 / INPUT Loop

    should be INPUT Value

    Line 10 / Total ← Total * Value

    should be Total ← Total + Value

    Correct algorithm:

    01 DECLARE Loop : INTEGER

    02 DECLARE Limit : INTEGER

    03 DECLARE Value : REAL

    04 DECLARE Total : REAL

    05 Total ← 0

    06 Limit ← ROUND(RANDOM() * 19,0) + 1

    07 FOR Loop ← 1 TO Limit

    08 OUTPUT "Enter a number"

    09 INPUT Value

    10 Total ← Total + Value

    11 NEXT Loop

    12 OUTPUT "The total of the numbers entered is ", Total

    13 OUTPUT "The average number entered is ", Total / Limit

  • 4(b)[2]

    One mark per mark point

    Correct use of ROUND with 2 arguments separated by comma, for example ROUND( 5, 2) (in statement 13) … • … (Total / Limit,1) correct arguments

    For example:

    OUTPUT "The average of the numbers entered is ",

    ROUND(Total / Limit,1)

  • 4(c)[4]

    One mark per mark point, max four

    After line 09 / after the input
    Insert a WHILE / pre-condition loop…
    … to check if the value entered is between 1 and 500 inclusive
    If the value is not in range, output an error message
    … and insert another input statement for re-input.

    Or

    Before line 08 / before the input message
    start a REPEAT / post-condition loop
    After line 09 / after the input
    … close the REPEAT loop by checking if the value entered was between 1 and 500 inclusive
    If it wasn’t, (the loop will repeat) for the number to be re-input / If it was, the program continues.

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.