Online worksheet ยท 1 of 4

Keep a rule true after every operation - Online practice 1

Read the information, then answer the questions. An adult may read the instructions aloud. Show your working where asked.

Read before answering

Inventory starts at 3. Invariant: stock is a non-negative integer. Process these operations in order: remove 5; add 2; remove 4. A removal larger than stock is rejected WITHOUT changing stock. Positive valid additions/removals otherwise update it. Every operation is independent and checked against current state.

Worksheet preview

  1. Trace stock after each operation from 3: remove 5, add 2, remove 4.
  2. Why would checking stock only when the screen first opens be insufficient?
  3. What should be recorded or shown when the first removal is rejected?

This exercise is included in the free preview. Register free to complete it and download the preview PDFs. No payment is required.

Register free

Already registered? Sign in