Data types and structures

EasyMedium
12345678910
Question 10
Medium

An automated smart-grid utility system uses a program to calculate seasonal surcharges for household energy consumption.

The pseudocode for this calculation is shown below. The items SURCHARGE_RATE and PEAK_THRESHOLD_KWH are constants.

1  CONST REAL SURCHARGE_RATE
2  SET SURCHARGE_RATE TO 0.12
3  CONST REAL PEAK_THRESHOLD_KWH
4  SET PEAK_THRESHOLD_KWH TO 350.0

5
6  SEND "SmartGrid Billing Utility Active" TO DISPLAY
7  SEND "Enter total electricity consumed (kWh):" TO DISPLAY
8  RECEIVE totalKWh FROM (REAL) KEYBOARD
9
10 IF totalKWh > PEAK_THRESHOLD_KWH THEN
11   SET surcharge TO (totalKWh - PEAK_THRESHOLD_KWH) * SURCHARGE_RATE
12 ELSE
13   SET surcharge TO 0.00
14 ENDIF
15
16 SET baseCost TO totalKWh * 0.15
17 SET finalBill TO baseCost + surcharge
18 SEND "Surcharge Applied: " & surcharge TO DISPLAY
19 SEND "Total Bill: " & finalBill TO DISPLAY

Explain why it is good programming practice to define values like SURCHARGE_RATE and PEAK_THRESHOLD_KWH as constants, rather than using raw literal values (such as 0.12 or 350.0) directly in the calculations.

[3]

Data types and structures Questions

  1. GCSE
  2. /Computer Science
  3. /Data types and structures