Structured programming and subroutines (procedures and functions)

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142
Question 20
Easy

A software engineer writing the temperature-monitoring software shown in Figure 1 decided to refactor the code by implementing it as a subroutine called FindMax. Line 1 was removed, and the array temps was defined as a parameter of the subroutine, which now returns the value of max_temp.

Figure 1

1  temps ← [18.5, 19.2, 21.0, 17.8, 16.5, 20.1]
2  max_temp ← temps
3  i ← 1
4  WHILE i < 6
5      IF temps[i] > max_temp THEN
6          max_temp ← temps[i]
7      ENDIF
8      i ← i + 1
9  ENDWHILE

State two advantages of implementing this logic as a subroutine rather than keeping it as inline code.

[2]

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)