0% found this document useful (0 votes)
25 views2 pages

P2 - 06 - A - Class Activity - Subroutine

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

P2 - 06 - A - Class Activity - Subroutine

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1

Worksheet Computer Science Paper 02


Practice Content: Unit 2.1- Data Structure - Subroutines

Learning outcomes: 2.6


2.6-(a) Understand what is meant by procedures , functions and parameters
2.6-(b) Define and use procedures and functions , with or without parameters
2.6-(c) Understand and use local and global variables

1. Draw a line to connect each data structure to the correct description.


Data Structure Description
Library routine a subroutine that does not have to return a value

Parameters the actual values passed to a subroutine at runtime

Procedure is the variable that takes on the value of an argument

Function is a sequence of program code that performs a specific task

Subroutine a standard subroutine that is available for immediate use

Arguments a subroutine that always returns a value.


2. Write a short program in your chosen programming language
o to define and use a subroutine
o to calculate CalArea()
o to display the area
- Design a program to calculate according to the following condition:
Area = Pi * Radius ^ 2 [ Pi = 3.14 ]
(a) Procedure without parameter Function without parameter
--- = 3.14 Pi = 3.14
PROCEDURE -------- () ---------- CalArea()
INPUT Radius INPUT Radius
------ = Pi * radius ^ 2 Area = -----------
OUTPUT “Area is:”, ----- ------ “Area is :”, Area
------------- ENDFUNCTION
----- CalArea() CALL CalArea()
(b) Procedure with parameter Function with parameter
Pi = 3.14 Pi = 3.14
FUNCTION CalArea(-------) FUNCTION CalArea(Radius)
Area = Pi * Radius ^ 2 Area = Pi * Radius ^ 2

// Main Program // Main Program


CALL CalArea (-----) CALL ------ (10)

3. Identify the following from the pseudocode.


PROCEDURE Plus(Number)
IF Number MOD 2 = 0 THEN
Number = Number + 10
ENDIF
ENDPROCEDURE
(a) What is the purpose of this algorithm?
------------------------------------------------------------------------------
------------------------------------------------------------------------------
(b) What is will be the output, if 3 and 4 is input the program.
------------------------------------------------------------------------------

© HSGICT 2023 P2 / Class Activity_06.A /Summer 2023


2

4. Draw a line to connect each data structure to the correct description.


Data Structure Description
Parameter is the value sent to a function or procedure
Argument is the variable that takes on the value of an argument

5. Read the following from the pseudocode.


01 Answer = 5
02 FUNCTION VaskarDC(Number ,Value)
03 Answer = Answer + (Number * 1.5)
04 RETURN Answer DIV Value
05 ENDFUNCTION
07
08 X=7
09 CALL VaskarDC(X,2)

(a) (i) State the keyword other than FUNCTION, that suggests the following code is a function.
----------------------------------------------------------------------------
(ii) State why the algorithm is a function and not a procedure.
----------------------------------------------------------------------------
(iii) State what meant by a return value.
----------------------------------------------------------------------------
(b) (i) State and describe the common build in function used in the program.
----------------------------------------------------------------------------
(ii) Explain the deference between a build in function and a user define function.
----------------------------------------------------------------------------
----------------------------------------------------------------------------
(c) State the name of the identifier used for the argument and identifier used for the parameters.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
(d) State the number of parameters there are in the code and name of them.

------------------------------------------------------------------------------
(e) Identify the local and global variable there are in the above program and name of them.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
(f) Give the line number(s) from the program of:
an Argument: ---- a Parameter: ----
a Local Variable: ---- a Global Variable: ----
a Function Definition: ---- a Return Value: ----
a Function Called: ---- A Build In Functions: ----

(g) Trace the algorithm to show the value returned when VaskarDC(7,2) is called.
Show each step of your working.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------

© HSGICT 2023 P2 / Class Activity_06.A /Summer 2023

You might also like