Testing (SQA National 5 Computing Science): Exam Questions

Exam code: X816 75

18 mins6 questions
1
2 marks

The code below should receive input and display a user’s name.

…
Line 3 DECLARE name INITIALLY ""
Line 4 SEND "Please type in your name" TO DISPLAY
Line 5 SD "Your name is" & name TO DISPLAY
Line 6 RECEIVE name FROM KEYBOARD
…

Identify the syntax error and logic error in the program code above.

2
1 mark

Input validation is required to ensure that a program will only accept the numbers 1 or 5.

State a numerical example of exceptional test data that could be used to test the design.

3
2 marks

A program is being written that will allow gamers to add money to their account using gift cards.

£25 gift card with a drawable gift box on a dark background featuring card number 0976 3421 6475 4377 in white text.

The program asks the user to enter their username, their five‑character password and the gift card number. The updated balance in the user’s account is then displayed.

Test data will be used to ensure this input validation works correctly. Complete the test table below.

Type of test

Input

Expected result

As4G5

Program will continue

Exceptional

Error message, ask to re‑enter

4a
6 marks

Edge Races are developing a program to process information on races with multiple stages.

The first race has four stages as shown below.

Race one

Stage D

Distance (km)

1

19.9

2

6.5

3

35.2

4

20.0

Flowchart with four stages connected by lines. Starts at "start," passes through "stage 1," "stage 2," "stage 3," "stage 4," and ends at "finish."

The design for part of the program is shown below.

6.1 Loop 4 times

6.2 Get valid distance for stage

The distance of a stage can range from 5 to 75 km.

(i) Using a design technique of your choice, refine step 6.2 to check the user enters a valid distance.

[4]

(ii) Test data is used to ensure the distance entered is valid.

[2]

State the type of test in the table below.

Type of test

Input

Expected results

67.6

Program continues

3.7

Program displays an error message

4b
3 marks

Edge Races classify races as ‘beginner’, ‘intermediate’ or ‘advanced’ based on the total distance of the race. The program displays the classification after calculating the total distance.

…
Line 25 <calculate the total distance for the race>
Line 26 IF totalDistance < 25 THEN
Line 27 SET race TO "beginner"
Line 28 END IF
Line 29 IF totalDistance >= 25 OR totalDistance <=100 THEN
Line 30 SET race TO "intermediate"
Line 31 END IF
Line 32 IF totalDistance > 100 THEN
Line 33 SET race TO "advanced"
Line 34 END IF
Line 35 SEND race TO DISPLAY
…

(i) When tested the code produced an unexpected result.

Identify the type of error in the code above.

[1]

(ii) The code above is inefficient.

Using a programming language of your choice, re‑write lines 26 to 34 to make this more efficient.

[2]

5
2 marks

Snooker uses seven different coloured balls, each worth a different number of points.

Pool player lining up a shot on a table with several balls scattered, focusing intently, in a black-and-white image.

Colour of ball

Points

Red

1

Yellow

2

Green

3

Brown

4

Blue

5

Pink

6

Black

7

A program has been written to record the number of points scored as each ball is potted.

State one example of extreme and exceptional test data that can be used for the input of points.

6
2 marks

Curling is a sport where stones are thrown down a lane of ice towards a target. In the example below, stone B is closest to the middle of the target and is the winner.

Two curling stones, labelled A and B, are on a curling target. Stone A is near the centre, while stone B is close to the outer circle of the target.

A computer program calculates the distance of each stone from the middle of the target. The code below has been written to identify the winning stone but produces the wrong output.

…
Line 20 IF stone_A_distance < stone_B_distance THEN
Line 21 SEND "Stone B is the winner." TO DISPLAY
Line 22 ELSE
Line 23 SEND "Stone A is the winner." TO DISPLAY
Line 24 END IF
…

State the type of error in the code above and how it can be corrected.