An architect uses a program to calculate the area of trapezoidal roof sections of a building.
Lines 4 and 22 of the algorithm below are incomplete.
Complete the algorithm by state what should be written in Box A (Line 4) and Box B (Line 22).
1
2 # Area of a Trapezium
3
4 FUNCTION CalculateArea( [Box A] )
5
6
7 BEGIN FUNCTION
8
9 SET calc TO ((pSideA + pSideB) / 2) * pHeight
10 RETURN calc
11
12 END FUNCTION
13
14
15 # Main program
16
17 RECEIVE sideA FROM (REAL) KEYBOARD
18 RECEIVE sideB FROM (REAL) KEYBOARD
19 RECEIVE height FROM (REAL) KEYBOARD
20
21
22 SET area TO CalculateArea( [Box B] )
23
24 SEND "Area: " & area & " square units" TO DISPLAY
25
26 IF (area >= 50) AND (area <= 150) THEN
27 SEND "Standard size" TO DISPLAY
28 ELSE
29 SEND "Custom size" TO DISPLAY
30 END IF
Box A (Line 4)
Box B (Line 22)
29 exam-style questions on Edexcel GCSE Computer Science Subprograms, covering Built-in and user-devised subprograms, Functions versus procedures, and Global and local variables. Each one has a worked solution and a mark scheme showing where the marks go.