Home/Low-level design/Library Management System

Library Management System

Title identity, copies, and loan ownership

Title identity and copy identity are different keys. Multiple copies share a title; a loan reserves one particular copy and records its owner. Check a member's existing active title before checking free copies, so exhaustion does not mask a duplicate-loan error.

cpp
std::map<std::string,Loan> active_by_copy;
// A return checks active_by_copy[id].member_id before erasing the row.

Sorting copy identifiers creates deterministic allocation. Returning a wrong owner's copy must not free it, while returning an unknown copy is a harmless false result. Catalog records remain immutable and loan state is separate, allowing availability to be derived consistently. Value snapshots prevent a caller rewriting loan ownership. Sequential service methods form the atomic boundary; there are no due dates or wall-clock decisions to complicate the model.

C++ contract conventions: numeric values use signed Int (long long); all inputs and intermediate arithmetic are within its representable range. Opt<T> means std::optional<T> and absence is std::nullopt; Vec<T> means std::vector<T>. Invalid documented arguments throw std::invalid_argument. Inputs passed by const reference remain caller owned. Returned containers and records own their contents. Calls use the declared C++ parameter types. Implicit conversions performed by the caller are outside the runtime validation contract. Unless a lesson states otherwise, string ordering is lexicographic over Unicode code points (Text) or UTF-8 identifiers (std::string).

Put it into practice

Implement the exercise in a full-screen workspace, then run its tests.

Open practice
Next lessonLRU Cache