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:练习题
5 道选择题即时批改,另有 5 道文字题附完整解题步骤,全部围绕「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.
先自己写一遍答案,再对照解题步骤。
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.
先自己写一遍答案,再对照解题步骤。
Describe two characteristics of a function that distinguish it from a procedure within the Pearson Edexcel PLS.
先自己写一遍答案,再对照解题步骤。
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.
先自己写一遍答案,再对照解题步骤。
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.
先自己写一遍答案,再对照解题步骤。
* thinka提供的内容由AI生成,可能并非总是准确或最新。请将其用作辅助资源,并与官方材料进行核实。
想多做几道同类题目?立即开始练习这个课题,边做边批改。
立即练习