An app can be used to record two players' scores on a 9 hole mini-golf course - Scottish Highers Computing Science - Question 7 - 2022
Question 7
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,
Clai... show full transcript
Worked Solution & Example Answer:An app can be used to record two players' scores on a 9 hole mini-golf course - Scottish Highers Computing Science - Question 7 - 2022
Step 1
One boundary of this app is that the app is for games between exactly two players. State two other boundaries for this app.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The app is limited to a 9 hole mini-golf format.
The input scores must be non-negative integers.
Step 2
Complete the diagram to show the data flow for the program.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
playerAname
playerBname
playerAscores()
playerBscores()
Step 3
Using a design technique of your choice, refine the following step.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Initialize counters for wins:
winsA = 0
winsB = 0
Loop through each hole:
For each hole, compare scores:
If player A has a lower score, increment winsA by 1.
Else if player B has a lower score, increment winsB by 1.
Display results:
If winsA > winsB, display "Player A wins!"
Else if winsB > winsA, display "Player B wins!"
Otherwise, display "It's a draw!"
Step 4
Describe the error.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The error is that the function call holesInOne[playerAname, playerAscores()] should not directly index into the function. It requires passing an array of scores, rather than the player's name.
Step 5
Using a programming language of your choice, correct the error described in part (i).
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Correct function call: SEND playerAname & " has scored " & holesInOne(playerAscores()) & " hole(s)-in-one" TO DISPLAY.
Step 6
Describe how the position of the declaration of a variable, within code, determines its scope.
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The scope of a variable is determined by where it is declared. If declared inside a function, it is local and inaccessible outside. If declared globally, it is accessible throughout the program.
Join the Scottish Highers students using SimpleStudy...