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

Higher Computing Science 2022 Question 7

14 marks · Software analysis

One boundary of this app is that the app is for games between exactly two players. State two other boundaries for this app. The top‑level design of the main steps of the program is shown below. Complete the diagram to show the data flow for the program. Mini‑Golf Program Calculate result and Get player Find and display display winner’s name or names and hole(s)‑in‑one for display draw message scores each player playerAname playerBname playerAscores() playerBscores() Using a design technique of your choice, refine the following step. Calculate result and display winner’s name or display draw message A hole‑in‑one is achieved when a player completes the hole by taking just one shot. The app counts and displays the number of holes‑in‑one for a player. Below is the code used to implement this feature. When tested the code was found to contain errors. … Line 201 FUNCTION holesInOne (ARRAY OF INTEGER scores) RETURNS INTEGER Line 202 DECLARE noHolesInOne INITIALLY 0 Line 203 FOR index FROM 0 TO 8 DO Line 204 IF scores[index] = 1 THEN Line 205 SET noHolesInOne TO noHolesInOne + 1 Line 206 END IF Line 207 END FOR Line 208 RETURN noHolesInOne Line 209 END FUNCTION … Line 258 SEND playerAname & " has scored " & holesInOne(playerAname, playerAscores) & " hole(s)-in-one" TO DISPLAY … There is an error at the function call. Describe the error. Using a programming language of your choice, correct the error described in part (i). Programmers have control over the scope of a variable when writing code. Describe how the position of the declaration of a variable, within code, determines its scope. An app can be used to record two players’ scores on a 9 hole mini‑golf course. A player wins a hole if they have fewer shots than their opponent. For example, Claire has won the first hole taking only two shots compared to Tina’s four shots. After nine holes, Claire has won four holes and Tina has won two. Player A Claire 2 3 2 4 6 2 3 1 4 Hole 1 Hole 2 Hole 3 Hole 4 Hole 5 Hole 6 Hole 7 Hole 8 Hole 9 Player B Tina 4 4 3 2 2 2 3 3 4 Claire has won the most holes Claire has 1 hole(s)‑in‑one Tina has 0 hole(s)‑in‑one Both players’ names and their nine scores are entered. The app displays the name of the player who wins the most holes or a message stating the game has been drawn if the number of holes won is the same.

Marking scheme

• shots (per hole) >= 1 OR shots (per game)>=9 • exactly 9 scores for each player • number of holes-in-one >=0 OR <=9 • number of holes won is >= 0 OR <=9 1 mark for each bullet Maximum 2 marks In for both: playerAName playerBName playerAscores() playerBscores() Any additional inputs or outputs for either step then do not award the mark for that step. Indication of IN must be shown. • initialise/create count for A and B • IF statement for A win • IF statement for B win • increment count for A and B • output for A/B win • condition for draw 1 mark for each bullet Do not double penalise IF statement. Answer must make two separate comparisons (IFs) to account for possible drawn holes. Design: winsA = 0 winsB = 0 loop for 9 holes if playerAscores()<playerBscores() then winsA = winsA + 1 else if playerBscores()<playerAscores() then winsB = winsB + 1 end if end loop if winsA>winsB then display playerAname has won most holes else if winsB>winA then display playerBname has won most holes else if winsA=winsB then display game is drawn end if Description of additional parameter/ mismatch in the number of (actual vs formal) parameters. Call to function with correct parameter. holesInOne(playerAScores) Declaration inside subroutine (1 mark) then only accessible within that subroutine (therefore local) (1 mark). OR Declaration outside subroutines (1 mark) then accessible throughout entire program (therefore global) (1 mark). 1 mark for description of scope relating to both subroutine and entire program.

Previous question: Higher Computing Science 2022 Question 6

Next question: Higher Computing Science 2022 Question 8