Programming Fundamentals Using C++

Case Studies · Tier 5 · Expert Introductory

Lectures L29–L32 · Modules 15–16 · think ~5 minutes · paper only. Cases ascend in difficulty within the tier. Worked solutions: instructor area only. These cases synthesize files, validation, records, and classes — the capstone tier.


PF-CS-081 · The Attendance Register File

<details><summary>Hints (progressive)</summary>

  1. Skip reasons: empty line, wrong field count, out-of-range count.
  2. Metadata lines are detected and consumed before the data loop.
  3. Every skip increments a counter and names its reason.

</details>


PF-CS-082 · Sensor Log to Summary Report

<details><summary>Hints (progressive)</summary>

  1. Cannot open input = fatal (print + exit); bad lines = count and continue.
  2. Zero valid records: the summary says so — never divide by zero.
  3. The output file is created only if the pipeline succeeded... or always? Decide.

</details>


PF-CS-083 · The Deduplicating Saver

<details><summary>Hints (progressive)</summary>

  1. A seen-list of kept emails, scanned linearly: fine at 500.
  2. Case policy must be explicit — pick one and state it in the report.
  3. Keep-first preserves order; the drop counter tells the rest.

</details>


PF-CS-084 · The Rolling Grade Book

<details><summary>Hints (progressive)</summary>

  1. Append mode creates-or-continues; truncation is the danger to avoid.
  2. REPORT aggregates at read time; the file stays raw.
  3. Multiple lines per student: accumulate per name as you read.

</details>


PF-CS-085 · Retry-Safe Config Loader

<details><summary>Hints (progressive)</summary>

  1. Three layers: file exists? key present? value valid?
  2. Corrupt-but-present is the sneaky case — validate, don't just read.
  3. New installation: every default fires; the log must say so explicitly.

</details>


PF-CS-086 · The Error-Message Designer

<details><summary>Hints (progressive)</summary>

  1. Message = what failed + where + what was found.
  2. Recoverable data errors warn and continue; structural ones stop.
  3. Exit codes let scripts react — but only if the discipline is consistent.

</details>


PF-CS-087 · Transaction Log Replay

<details><summary>Hints (progressive)</summary>

  1. Replay is sequential: each line's verdict depends on all before it.
  2. Skip-and-note for malformed; halt or guard for overdrafts — pick a policy and defend it.
  3. The trail is the evidence; the verdict is the conclusion.

</details>


PF-CS-088 · Multi-File Merger with Cross-Checks

<details><summary>Hints (progressive)</summary>

  1. Index one file by id as you read the other.
  2. Every record lands in exactly one bucket: kept-A, kept-B, conflict, new.
  3. Identical inputs → all records "kept", zero conflicts — verify that.

</details>


PF-CS-089 · The CLI Calculator Object

<details><summary>Hints (progressive)</summary>

  1. One data member: the accumulator; methods are the only writers.
  2. apply returns bool (or reason): rejected ops change nothing.
  3. Private + accessors means no external code can bypass the /0 guard.

</details>


PF-CS-090 · Bank Account Invariants

<details><summary>Hints (progressive)</summary>

  1. All writes flow through two methods: small attack surface.
  2. Negative amounts are rejected: deposit(−5) returns false, changes nothing.
  3. The invariant holds after every method — that is the contract tests verify.

</details>


PF-CS-091 · Playlist with History

<details><summary>Hints (progressive)</summary>

  1. State: tracks + index; everything else derives.
  2. Only next() mutates the index — single-writer rule.
  3. Empty playlist: current() reports it explicitly, never indexes.

</details>


PF-CS-092 · The Thermometer Class Ladder

<details><summary>Hints (progressive)</summary>

  1. Convert F/K to C at the boundary; store one truth.
  2. Validation lives in setters — the only doors in.
  3. F→C→F round trips are exact at full precision; decide the display policy for 1 dp.

</details>


PF-CS-093 · Composing a Garage (Has-A)

<details><summary>Hints (progressive)</summary>

  1. Has-a: Garage has Cars; it uses their public methods only.
  2. Empty slots contribute 0 km but must be skipped, not indexed.
  3. totalKm() sums via km() accessor — never reaches into data.

</details>


PF-CS-094 · The Registry Class (aggregation)

<details><summary>Hints (progressive)</summary>

  1. add() enforces uniqueness; nothing else can insert.
  2. findById and averageAge are const: they promise no mutation.
  3. averageAge on empty registry: define the verdict, don't divide by zero.

</details>


PF-CS-095 · Files to Objects: Student Roster

<details><summary>Hints (progressive)</summary>

  1. Interface first: load(path) → bool/int code; report() const.
  2. Missing file and bad-data are different results — two channels.
  3. load uses the same validated intake as the manual path: one door.

</details>


PF-CS-096 · The Undo Stack Text Editor

<details><summary>Hints (progressive)</summary>

  1. Save the whole string before each edit: simple, correct, memory-heavy.
  2. Inverse operations (re-insert the deleted text) are the memory-cheap alternative — compare.
  3. Empty history: undo() reports and changes nothing.

</details>


PF-CS-097 · Vending Machine State Machine

<details><summary>Hints (progressive)</summary>

  1. insertCoin moves IDLE→PAID (and stays PAID on overpay); select moves PAID→DISPENSED.
  2. Wrong-state calls: rejected with a reason, state unchanged.
  3. The state member is the guard: every method checks it first.

</details>


PF-CS-098 · Grade Analyzer with Tiered Reports

<details><summary>Hints (progressive)</summary>

  1. load, bandCounts, extremes, histogram: name them, then build.
  2. Readers are const; only load mutates state.
  3. Second load: replace (fresh object per file) — document the choice in the header.

</details>


PF-CS-099 · The Persisted Inventory (files + class)

<details><summary>Hints (progressive)</summary>

  1. Format lives in save/load only: change it in one place.
  2. load validates every field; foreign/garbage lines are rejected with reasons.
  3. save() truncates deliberately — state that in its contract comment.

</details>


PF-CS-100 · The Checkout Queue Simulator

<details><summary>Hints (progressive)</summary>

  1. wait = service start − arrival; start = max(arrival, prev finish).
  2. One running "cashier free at" time suffices — no real queue needed.
  3. Assumptions to name: no balking, no service interruptions, FIFO fairness.

</details>


PF-CS-101 · The Audit-Safe Ledger Class

<details><summary>Hints (progressive)</summary>

  1. Balance and history must agree: both private, both touched by the same methods.
  2. Rejected ops: zero footprint — audit shows only real money.
  3. net() derives from history; balance() from cents: a consistency check between them.

</details>


PF-CS-102 · Weather Station Class + File Roundtrip

<details><summary>Hints (progressive)</summary>

  1. Summary before save == summary after load: the test.
  2. All-or-nothing load (validate first, then commit) is simplest to reason about.
  3. The file format is the class's private affair — like PF-CS-099.

</details>


PF-CS-103 · The Two-Class Report Pipeline

<details><summary>Hints (progressive)</summary>

  1. Parser knows files; Stats knows numbers: one job each.
  2. Hand-off: vector<Sale> — plain data, no I/O types cross the seam.
  3. Reusability test: can Stats run on data from anywhere else? Then the seam is right.

</details>


PF-CS-104 · The Integrity-Checked Config

<details><summary>Hints (progressive)</summary>

  1. Structural pass: exactly the 5 keys, in order, once each.
  2. Value validation runs only after structure passes.
  3. Strict suits machine-written files; fallback suits human-edited ones — say which this is.

</details>


PF-CS-105 · Student Records: The Composite Challenge

<details><summary>Hints (progressive)</summary>

  1. Student validates its own modules; the vector-of-students loader validates references.
  2. Two-pass load: students first, then modules — or reject orphan ids.
  3. Composite = three layers, each with a contract: struct, class, file.

</details>


PF-CS-106 · The Exam Seating Optimizer

<details><summary>Hints (progressive)</summary>

  1. Alternate sections row by row; snake direction to avoid vertical repeats.
  2. Impossibility = one section outnumbers the rest by more than the checker pattern allows.
  3. Leftovers are reported, never dropped silently.

</details>


PF-CS-107 · The Library Fine Calculator (full spec)

<details><summary>Hints (progressive)</summary>

  1. Compute per-day charges first, then caps, then waivers — pick and defend an order.
  2. Closures remove chargeable days: subtract, don't freeze.
  3. The receipt must show each rule's contribution — no silent arithmetic.

</details>


PF-CS-108 · The Capstone Mini-System

<details><summary>Hints (progressive)</summary>

  1. Menu knows items; Order knows quantities; Register knows money and files.
  2. Boundaries: Menu→Order (price lookup), Order→Register (charged amounts).
  3. The revisit candidate: whatever the user-testing transcript shows users fumbling — predict it.

</details>

Programming Fundamentals Using C++ · C++17 · 16 weeksBack to top ↑