ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions
5 marks · Fixed and conditional loops
When this code is evaluated it is found to be inefficient. Explain how to make this code more efficient. A tester enquired why the total score was displayed as below: Total score: 180.60 Explain the problem with the program that this output has highlighted. The code below is written to store the names of a maximum of 40 competitors in an archery competition. … Line 80 SET stop TO TRUE Line 81 SET count TO 0 Line 82 WHILE NOT(stop) AND count <= 40 DO Line 83 RECEIVE nextPerson FROM (STRING) KEYBOARD Line 84 IF nextPerson = "NO" THEN Line 85 SET stop TO FALSE Line 86 ELSE Line 87 <store name entered> Line 88 SET count TO count + 1 Line 89 END IF Line 90 END WHILE Line 91 SEND "Total archers " & count TO DISPLAY … Describe why this code will not function as expected. In an archery game, players score points when they hit the target. The points entered are whole numbers in the range 0 to 10. The game has 10 rounds and each player shoots two arrows in each round. The program below is written to record a player’s score. … Line 24 SET totalScore TO 0.00 Line 25 SEND "round1" TO DISPLAY Line 26 RECEIVE arrow1 FROM (REAL) KEYBOARD Line 27 RECEIVE arrow2 FROM (REAL) KEYBOARD Line 28 SET roundTotal1 TO arrow1 + arrow2 Line 29 SET totalScore TO totalScore + roundTotal1 … Line 70 SEND "round10" TO DISPLAY Line 71 RECEIVE arrow19 FROM (REAL) KEYBOARD Line 72 RECEIVE arrow20 FROM (REAL) KEYBOARD Line 73 SET roundTotal10 TO arrow19 + arrow20 Line 74 SET totalScore TO totalScore + roundTotal10 Line 75 < display all ten round totals > Line 76 SEND "TotalScore: " & totalScore TO DISPLAY
• use a loop for each round (10 times) • use a loop for each the two arrows within one round • array used to replace roundtotals • running total inside loop Award 1 mark for each bullet. Maximum 3 marks. Also accept: • replacing 10 running total lines with one line of code • use sum function to calculate totalscore rather than do a running total • scores are real values but should be integers • no input validation for data entry Award 1 mark for any one bullet. Could explain that user entered .60 instead of 60 and as real accepted this was ok for data entry. (The condition means) the loop will never execute/run. Also allow, 41 competitors may be entered. At line 80 stop should be set to FALSE At line 82 the condition could be stop = TRUE (or just stop)