Carry the state into the next call

A warehouse operation transfer(k) moves whole units from a source bin to a destination bin. Its precondition is 1≤k≤old⁡(source)1\leq k\leq\operatorname{old}(\text{source}). Its postcondition on normal return is:


source=old⁡(source)−k,destination=old⁡(destination)+k.\text{source}=\operatorname{old}(\text{source})-k, \qquad \text{destination}=\operatorname{old}(\text{destination})+k.


Initially, the source contains 72 units and the destination contains 19 units. The warehouse calls transfer(16) and then transfer(25). Both calls return normally, and no other operation changes either bin.


Find the final source quantity, the final destination quantity, and the largest permitted integer request for a third call. Give each answer in whole units, with zero decimal places. Each old value belongs to the call currently executing.


A starting inventory is followed by two transfer calls in their execution order.


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 Design by Contract Questions: