3Medium
0/3

A power system engineer is designing a renewable energy microgrid. The iterative algorithm below is used to calculate how many modular battery banks (each consisting of usable storage capacity and a reserve overhead to prevent deep discharge) are required to meet a specified total energy demand.

constant USABLE_CAPACITY ← 2400
constant RESERVE_CAPACITY ← 600
OUTPUT 'Enter the total energy required in Wh'
totalEnergy ← USERINPUT
totalBankCapacity ← USABLE_CAPACITY + RESERVE_CAPACITY
numberOfBanks ← 0
REPEAT
    totalEnergy ← totalEnergy - totalBankCapacity
    numberOfBanks ← numberOfBanks + 1
UNTIL totalEnergy ≤ 0

The engineer realizes that using a loop is inefficient and unnecessary. They decide to rewrite the algorithm using a combination of the DIV and MOD operators with selection.

  • DIV calculates integer division, e.g. 14 DIV 5=214 \text{ DIV } 5 = 214 DIV 5=2
  • MOD calculates the remainder after integer division, e.g. 14 MOD 5=414 \text{ MOD } 5 = 414 MOD 5=4

Complete this new algorithm by stating the code that should be written in the boxes labelled A, B, and C. This new algorithm must calculate the same final result for the variable numberOfBanks as the original loop-based algorithm.

constant USABLE_CAPACITY ← 2400
constant RESERVE_CAPACITY ← 600
OUTPUT 'Enter the total energy required in Wh'
totalEnergy ← USERINPUT
totalBankCapacity ← USABLE_CAPACITY + RESERVE_CAPACITY
numberOfBanks ← totalEnergy DIV totalBankCapacity
IF [ A ] MOD [ B ] > 0 THEN
    numberOfBanks ← [ C ]
ENDIF
[3]

Arithmetic operations in a programming language Questions

Practise AQA GCSE Computer Science Arithmetic operations in a programming language with exam-style questions for GCSE Computer Science. 7 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Arithmetic operations in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /Arithmetic operations in a programming language