A software developer is creating a program for a dog grooming company that has branches in Dundee, Edinburgh, Glasgow and Stirling - Scottish Highers Computing Science - Question 9 - 2023
Question 9
A software developer is creating a program for a dog grooming company that has branches in Dundee, Edinburgh, Glasgow and Stirling. The following data is stored abou... show full transcript
Worked Solution & Example Answer:A software developer is creating a program for a dog grooming company that has branches in Dundee, Edinburgh, Glasgow and Stirling - Scottish Highers Computing Science - Question 9 - 2023
Step 1
Using the test data shown, state the output.
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 output would show the dog IDs of those dogs that have visited either the Stirling or Dundee branch more than four times. Given the test data, the relevant dog IDs are:
G123 (7 visits at Glasgow)
A872 (6 visits at Stirling)
G876 (2 visits at Edinburgh)
A423 (6 visits at Stirling)
D321 (2 visits at Dundee)
D872 (2 visits at Dundee)
Therefore, the output from the code will be:
A872
A423
Step 2
Re-write Line 3 of the code to make this code fit for purpose.
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
The corrected Line 3 of the code should explicitly check against both conditions without causing a logic error:
IF (branch[i] = "Stirling" OR branch[i] = "Dundee") AND visits[i] > 4 THEN
Step 3
Identify a formal parameter and its associated actual parameter.
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
Formal parameter: petNo
Actual parameter: dogID
Step 4
Describe the operation of Line 24 during the execution of this program.
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
In Line 24, the procedure customerSearch is called with the arrays dogID, branch, and noOfVisits passed as actual parameters. This line initiates the search procedure that processes the input arrays to display dog IDs for those dogs that qualify for the discount based on their branch and visit count.
Step 5
Identify a local variable in the code.
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
One local variable in the code is i.
Step 6
Describe the scope of this local variable.
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 the local variable i is limited to the customerSearch procedure. It is only accessible within this procedure and exists only during its execution.
Step 7
Explain why using local variables increases the maintainability of program code.
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
Using local variables increases the maintainability of program code because it reduces the risk of unintended side effects by ensuring that variables are only accessible within their respective procedures or functions. This encapsulation helps clarify the code by limiting the interaction between different parts of the program, making it easier to debug and modify.
Step 8
Write the code to ask the user for the branch name and display how many dogs have made more than five visits to this branch.
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
Here is an example code snippet in Python to achieve this:
branch = input("Enter the branch name: ")
count = 0
for i in range(len(branch)):
if branch[i] == branch and noOfVisits[i] > 5:
count += 1
print(f'Dogs with more than five visits to {branch}: {count}')
Join the Scottish Highers students using SimpleStudy...