Constructs

EasyMediumHard
123456789101112131415161718192021222324252627282930
Question 25
Medium

An automated greenhouse control program is being developed to display soil moisture records and calculate water usage costs. It displays each moisture level stored in an array of readings.

  • It sums up additional water allocations (in litres) entered by the user, until the user enters -1.0.
  • It then calculates a tax rate. When the total water allocated is over 150.0 litres, the tax rate is 18%. Otherwise, the tax rate is 8%.

Program Code

1: TAX_THRESHOLD = 150.0
2: moisture_readings = [45.2, 48.0, 39.5, 55.1, 42.8]
3: total_water = 0.0
4: print("Historical Moisture Levels:")
5: for level in moisture_readings:
6:     print(str(level) + "%")
7: allocation = float(input("Enter water volume in litres (-1 to stop): "))
8: while allocation != -1.0:
9:     total_water = total_water + allocation
10:    allocation = float(input("Enter water volume in litres (-1 to stop): "))
11: if total_water > TAX_THRESHOLD:
12:    tax_rate = 0.18
13: else:
14:    tax_rate = 0.08
15: final_cost = total_water * (1 + tax_rate)
16: print("Total cost of water: £" + str(final_cost))

Task

Identify the code features requested below from the program snippet shown above:

a.

Name of a constant used in the program

[1]
b.

Name of an array used in the program

[1]
c.

Line number of an initialisation of a variable with a real number

[1]
d.

Line numbers for a selection construct

[1]
e.

Line numbers for a repetition construct (condition-controlled loop)

[1]
f.

Line numbers for an iteration construct (count-controlled/collection loop)

[1]
g.

Line number for an instruction that outputs information to the screen

[1]

Constructs Questions

  1. GCSE
  2. /Computer Science
  3. /Constructs