Track a shared manifest and an independent copy

A school supply application represents a shipment manifest using a hidden storage structure. You interact with each manifest only through these specified operations:

  • count(x) returns the current number of notebooks recorded in manifest x as an integer value.
  • add(x, n) increases that manifest's recorded count by n notebooks.
  • remove(x, n) decreases that manifest's recorded count by n notebooks. Every removal below is valid.
  • copy(x) creates an independent manifest containing the same count as x at that moment.

Manifest M initially records 18 notebooks. Name A is an alias for M: both names refer to the same manifest. Name C refers to the independent manifest returned by copy(M).


Names M and A refer to one manifest, while C refers to an independent copied manifest.


The application then performs these actions in order:

  1. Store the integer returned by count(A) in saved.
  2. Call add(C, 7).
  3. Call remove(A, 5).
  4. Call add(M, 2).
  5. Call remove(C, 4).

A previously returned integer does not update when a manifest changes. Find the final values returned by count(M) and count(C), and the final value of saved. Give each as a whole-number count of notebooks.

Your answers

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 Procedural and Data Abstraction Questions: