ITPEC IP October 2024 Question 6

A power company charges electricity bill shown in the table below.

Units used per monthPer unit cost(in 1/100 US$)
First 100 units5
Next 200 units10
Over 300 units15

Function computeBill receives the number of units used per month as an argument and returns the electricity bill in 1/100 dollars. Which of the following is an appropriate combination of pieces of code to be inserted in A and B in the program?

[Program]
○ integer: computeBill(integer: units)
integer: bill
if (units ≤ 100)
bill ← A
elseif (units ≤ 300)
bill ← 100 × 5 + (units - 100) × 10
else
bill ← B
endif
return bill
OptionAB

Explanation

A: units × 5, B: 100 × 5 + 200 × 10 + (units − 300) × 15 — each band of units is charged only at its own rate.

The tariff is progressive, and the given middle branch shows the pattern:

  • •up to 100 units: every unit is in the first band, so the bill is units × 5 (blank A)
  • •101 to 300 units: the full first band 100 × 5 plus the units above 100 at 10 (given)
  • •over 300 units: the full first band 100 × 5 = 500, the full second band of 200 units 200 × 10 = 2000, and only the units above 300 at 15, (units - 300) × 15 (blank B)

Check with 350 units: 500 + 2000 + 50 × 15 = 3250.

Answer (d)

Why not others:

  • •(a) — both blanks wrong: A charges (units − 100) × 5, negative for 80 units, and B charges every unit above 200 twice, at 10 and again at 15
  • •(b) — B is right, but A subtracts the first band's width from units that all lie inside the first band
  • •(c) — A is right, but B charges all units above 100 at 10 and starts the top band at 200 instead of 300, so units above 200 are billed twice

Key rule: In a tiered tariff, charge every completed band at its full width and only the usage above the last threshold at the top rate.

Algorithm and Programming · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.