Checking independence between batch calls

A laboratory program calls an energy-summary module once per test batch. Its interface promises to return the total energy for the current batch, in joules, independently of earlier batches.


Two implementations use the same inputs and output units:

  • Implementation R resets its internal total to zero at the start of every call, adds the current batch's readings, and returns the total.
  • Implementation P sets its internal total to zero only when the program starts. Each call adds the current batch's readings to the retained total and returns it.

The retained total is hidden state: stored information from earlier calls that is not supplied as a current input. Both implementations run in separate, newly started programs. Each receives the three batches below in the listed order.


Complete the table with the returned energies. Enter exact integers; all outputs are in joules.

CallCurrent batch readings (J)R output (J)P output (J)
12, 3
24, 1
36, 2

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Modular Programming Questions: