Programming Fundamentals Using C++

Case Studies · Tier 3 · Intermediate

Lectures L17–L24 · Modules 9–12 · think ~5 minutes · paper only. Cases ascend in difficulty within the tier. Worked solutions: instructor area only.


PF-CS-041 · The Missing Temperature

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

  1. A bool starts false and flips on the first violation.
  2. Report at the first violation and stop, or collect all — decide the contract.
  3. After the loop, the flag's value answers the none-found question.

</details>


PF-CS-042 · Reverse Without a Second Array

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

  1. Swap a[i] with a[n−1−i].
  2. i runs to n/2 exclusive — the middle never swaps itself.
  3. ⌊n/2⌋ swaps total; for odd n the center stays.

</details>


PF-CS-043 · The Two-Pass Versus One-Pass Average Gap

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

  1. The mean is unknown until all values are seen.
  2. Deviations need the final mean plus every original value.
  3. One pass requires keeping the values — the array is the memory.

</details>


PF-CS-044 · Rotating the Rota

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

  1. New position of a[i] is (i − k + n) mod n... or a second index walk.
  2. k mod n first: rotating by n is a no-op.
  3. One-buffer copy with the modular index is simplest; triple-reversal is the expert trick.

</details>


PF-CS-045 · The Balanced Seating Chart

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

  1. A "remaining" counter plus per-section counters.
  2. One pass = one round; skip empties; stop when remaining == 0.
  3. All-zero input must print nothing and stop — verify that first.

</details>


PF-CS-046 · Parallel Arrays Break a Report

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

  1. The invariant: names[i] and scores[i] describe the same student.
  2. Any swap in scores must mirror in names.
  3. Ties make "sorted by score" ambiguous — state the tie order policy.

</details>


PF-CS-047 · Frequency Table from Scratch

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

  1. int counts[6] = {} wastes slot 0 — or does it buy clarity?
  2. counts[r]++ after validating 1 ≤ r ≤ 5.
  3. A zero count still prints its label with no stars.

</details>


PF-CS-048 · The Flood Warning Diff

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

  1. Element 0 has no predecessor: start comparing at 1.
  2. The loop runs n−1 comparisons for n elements.
  3. An empty flag list must still print something — none.

</details>


PF-CS-049 · Seat Map Query Engine

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

  1. Row count = one loop over columns; column count mirrors it.
  2. First-free = nested loops with an early exit flag.
  3. full after both loops complete without finding — the fence-post of the search.

</details>


PF-CS-050 · The Sudoku Row Check

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

  1. seen[d] flips true when d appears; a repeat is an instant fail.
  2. Out-of-range check first: 1–9 or report immediately.
  3. Counting true values at the end proves all nine appeared.

</details>


PF-CS-051 · Heat Grid Hotspots

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

  1. Pass 1 finds max and its cell; pass 2 filters.
  2. One pass cannot list (it doesn't know the threshold yet).
  3. |t − max| ≤ 2.0 with ≤ — ties included by design.

</details>


PF-CS-052 · Matrix Border Sum

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

  1. Predicate: r==0 || r==n−1 || c==0 || c==m−1.
  2. One loop over all cells with the predicate is safe; row/column walks need corner care.
  3. n==1: every cell is border — the predicate handles it naturally.

</details>


PF-CS-053 · The Name Formatter

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

  1. Out-of-range/collapsing edits shrink the string — indices shift.
  2. A result string with append-only logic avoids index chaos.
  3. Word starts = position 0 or right after a space.

</details>


PF-CS-054 · Word Hunt with Word Boundaries

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

  1. A match is valid iff the chars before and after are non-letter boundaries.
  2. Find a candidate, check both boundaries, continue past it.
  3. Case policy must be explicit: exact match here (state it in the doc).

</details>


PF-CS-055 · Palindrome Judge with Punctuation

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

  1. Two pointers walk inward, skipping junk characters.
  2. Cleaning first simplifies the walk — decide build-then-scan vs scan-with-skips.
  3. Empty-after-cleaning: define it as a palindrome or reject — document the choice.

</details>


PF-CS-056 · CSV Column Statistics

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

  1. istringstream >> score fails on "abc" — the stream's bool tells you.
  2. Two error buckets need two counters (or one list with reasons).
  3. Mean over valid lines only; report the excluded ones.

</details>


PF-CS-057 · The Acronym Builder

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

  1. Words are maximal letter runs.
  2. Test the whole word (not its letters) against the stop list.
  3. toupper only on accepted words' first letters.

</details>


PF-CS-058 · Insertion Sort on Playing Cards

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

  1. After pass i, a[0..i] is sorted.
  2. Inner while shifts larger elements right until the hole is found.
  3. Sorted input: the while fails immediately every pass — O(n) total.

</details>


PF-CS-059 · Stable Ranking with Ties

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

  1. Stability: equal keys keep their relative order.
  2. Selection sort's long-range swaps can jump over equal keys.
  3. Insertion sort with strict > comparison never reorders equals — stable by construction.

</details>


PF-CS-060 · Search Benchmark Disclosure

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

  1. Binary pays a sorting price up front; linear pays per query.
  2. Absent keys show the gap best: log₂ n vs n.
  3. For tiny n or unsorted one-off queries, linear wins on simplicity and total cost.

</details>

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