Errors as values or exceptions

F-ERRREP-V4-3hard

Tell unknown items from empty ones

A clinic dispensary hands out units from a kit, totals order quantities and serves items from its stock.

What needs to change

Repair serve so an unknown item is reported differently from one that has run out.

Reproduce

  1. Use `clang++ -std=c++2c -Wall -Wextra -pedantic main.cpp -o main && ./main` with the ticket’s sample stdin; compare the unknown-item message and waiting count.

Acceptance criteria

Your review marks · Saved in this browser. Test acceptance is tracked separately.

Notes

The file contains its headers, readRows, the UnknownItem and OutOfStock types, the stock, dispense, serve and main.

Input: a patient’s name and an item on each line. The stock holds 2 bandages and 1 splint.

Input uses LF/CRLF records, ordinary ASCII space/tab field separators and ASCII space/tab/CR framing. Names, item codes and invalid words are opaque valid UTF-8 tokens; other characters, including BOM and NEL, remain part of a token. A physical line has at most 4096 bytes.

There are at most 50 requests. Each name or item token has at most 64 UTF-8 bytes and contains no ASCII space, tab, CR or LF. The supplied reader receives valid records.

Sign in to open this exercise

The ticket brief is public. Sign in to access the exercise. Paid exercises require Pro.

Sign in