A programmer wants to break down a complex problem into smaller, manageable parts. What is a primary benefit of using subprograms for this purpose?
Pearson Edexcel GCSE (9-1) · Computer Science (1CP2)
Subprograms: Practice Questions
5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on Subprograms.
A function is defined as follows:
function calculate(a, b)
return a * b + 2
endfunction
What is the output of print(calculate(3, 4))?
A subprogram is designed to update a user's score in a database but does not need to send any data back to the part of the program that called it. Which type of subprogram is this?
Which of the following describes the difference between a global variable and a local variable used within a subprogram?
Which of the following is a potential risk of using global variables instead of passing parameters to subprograms?
Explain why a programmer would use a function rather than a procedure when calculating the square root of a number.
Write your answer out first, then check it against the worked solution.
A variable total is declared inside a subprogram. Explain the effect on the program if you attempt to access total from the main program block.
Write your answer out first, then check it against the worked solution.
Describe two characteristics of a function that distinguish it from a procedure within the Pearson Edexcel PLS.
Write your answer out first, then check it against the worked solution.
A program uses a subprogram to calculate the total price of items including tax. The subprogram takes the price as an input and returns the final value.
(a) Explain one benefit of using subprograms in this scenario.
(b) Define the difference between a parameter and an argument in the context of this subprogram.
Write your answer out first, then check it against the worked solution.
Consider the following subprogram snippet:FUNCTION calculate(a, b)
global total
total = a + b
RETURN total * 2
ENDFUNCTION
(a) Distinguish between the local variables and global variables in this snippet.
(b) Explain one potential risk of using the global keyword inside a subprogram.
(c) Rewrite the subprogram so it does not use a global variable but still allows the calling program to use the sum.
Write your answer out first, then check it against the worked solution.
* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.
You've seen the model answer. Now get yours marked.
This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.
Want more questions like these? Get a fresh set on this topic, marked as you go.
Practise More