ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions

N5 Computing Science 2019 Question 19

11 marks · Selection and logical operators

Identify one logical operator in the above code. The program runs but does not meet the functional requirements stated in the rules. State the type of error that has occurred. The program has been edited as shown, but still breaks rule 3 and rule 4 of the game. … Line 3 DECLARE total INITIALLY 0 Line 4 DECLARE balls INITIALLY 3 Line 5 WHILE total < 50 AND balls > 0 DO Line 6 RECEIVE ballScore FROM KEYBOARD Line 7 SET total TO total + ballScore Line 8 SET balls TO balls − 1 Line 9 END WHILE Line 10 SEND "Well done! You have won a prize." TO DISPLAY Using a design technique of your choice, design a solution that meets the requirements of all four game rules. A single ball can achieve a variety of different possible scores. Two versions of input validation were coded and tested to check that only valid scores are entered. Version A … Line 6 RECEIVE ballScore FROM KEYBOARD Line 7 WHILE ballScore < 0 OR ballScore > 75 DO Line 8 RECEIVE ballScore FROM KEYBOARD Line 9 END WHILE Version B Line 1 DECLARE possScore INITIALLY [0,5,20,25,30,50,75] … Line 6 DECLARE found AS BOOLEAN INITIALLY false Line 7 REPEAT Line 8 RECEIVE ballScore FROM KEYBOARD Line 9 FOR check FROM 0 TO length(possScore)−1 DO Line 10 IF possScore[check] = ballScore THEN Line 11 SET found TO true Line 12 END IF Line 13 END FOR Line 14 UNTIL found Explain why it would not be appropriate to use the input validation shown in Version A. Name the data structure used in line 1 of Version B and state the data type that it is used to store. Name of data structure Data type stored Describe how the found variable is used in Version B. A fairground game involves throwing balls through holes in a large wooden board. Each hole scores different points. 50 20 5 75 30 25 The game is played using the following four rules. 1. A player starts with 3 balls and throws them one at a time. 2. If a ball is successfully thrown through a hole the points are added onto the player’s score. 3. The game ends immediately if a player’s score is greater than or equal to 50. 4. If the score reaches exactly 50 points the player is told they have won a prize. A program is written to keep the score for a player. … Line 3 DECLARE total INITIALLY 0 Line 4 DECLARE balls INITIALLY 3 Line 5 WHILE total < 50 AND balls > 0 DO Line 6 RECEIVE ballScoreOne FROM KEYBOARD Line 7 SET total TO total + ballScoreOne Line 8 SET balls TO balls − 1 Line 9 RECEIVE ballScoreTwo FROM KEYBOARD Line 10 SET total TO total + ballScoreTwo Line 11 SET balls TO balls − 1 Line 12 RECEIVE ballScoreThree FROM KEYBOARD Line 13 SET total TO total + ballScoreThree Line 14 SET balls TO balls − 1 Line 15 END WHILE Line 16 SEND "Well done! You have won a prize." TO DISPLAY

Marking scheme

(i) AND logic One mark each for • including conditional loop: total<50 AND balls>0 • including: - Input - total calculated - balls decremented • if total >= 50 set balls to 0/exit loop in correct place • if total = 50 then display prize message If a candidate writes line numbers assume that the code given in the question is included in their answer. “Correct place” for third bullet should be after the new total has been calculated but before the end of the loop. Accept variations of the same conditions (ball !=0, NOT(total>=50) etc). Conditional loop may be replaced by a design that repeats for each ball. In this case “balls decremented” would also not be required. User can enter a ball score (between 0 and 75) that was impossible to achieve. Data structure – array Data type - integer Do not allow “int” One mark each for • changed to true when a match is found • stops the loop

Previous question: N5 Computing Science 2019 Question 18

Next question: N5 Computing Science 2021 Question 1