Worked example 1
The following pseudocode calculates the area of a circle. Identify the programming paradigm and justify your answer with reference to the code.
DECLARE Radius : REAL
DECLARE Area : REAL
PROCEDURE CalculateArea(InRadius : REAL)
Area <- 3.14159 * InRadius * InRadius
ENDPROCEDURE
OUTPUT "Enter the radius:"
INPUT Radius
CalculateArea(Radius)
OUTPUT "The area is: ", Area
Show solution outline
Paradigm: Procedural Programming (a type of Imperative paradigm).
Justification:
- Use of Procedures: The code is structured around a PROCEDURE named CalculateArea which contains a set of instructions to perform a task. [1 mark]
- Sequential Execution: The main part of the program follows a clear, step-by-step sequence of commands (OUTPUT, INPUT, procedure call, OUTPUT). [1 mark]
- Shared State / Global Variables: The procedure CalculateArea modifies a global variable Area, which is a common feature in procedural programming where data and operations are not tightly coupled. [1 mark]