Trace a credit-pool contract

A laboratory's CreditPool ADT starts with 20 available credits. For positive integer k, spend(k) returns true and subtracts k if enough credits are available; otherwise it returns false and changes nothing. refund(k) adds k, returns no value, and requires k not to exceed the number already spent.


The calls in the table run consecutively on the same pool. Complete each missing result using true or false, and each availability using an exact integer number of credits.

CallReturned resultAvailable credits after call
spend(6)
spend(15)
refund(3)No value
spend(8)

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 Abstract Data Types (ADTs) Questions: