Chapter 08 · Reps

Midterm Review — Reps

← Back to Chapter 8

Chapter 8 — Combination Drills

These are not weekly reps. They are review drills — short problems that combine concepts from Chapters 1–7. Each one should take 15–40 minutes.

Do them in order. Each builds on the previous. The point is to feel concepts combining, not to learn anything new.

Ground rules:

  1. Type every line. No copy-paste.
  2. AI off.
  3. Compile and run after each. Read errors before reaching for help.
  4. If a drill takes you over 60 minutes, stop, re-read the relevant chapter, then come back.

Drill 1 — Reps Counter (Loops + Functions + Types)

Write a program that:

  1. Asks the user for the number of training sessions.
  2. For each session, asks for the number of reps.
  3. Computes total reps, average reps per session (as a double), best session, and worst session.
  4. Prints a formatted summary.

Concepts combined: cin/cout, types, integer-division safety, for loop, accumulator, max/min tracking, function decomposition.

Time budget: 25 minutes.


Drill 2 — Choose-Your-Own (Conditionals + Loops + Flags)

Write a 4-decision-point choose-your-own-adventure with at least 3 endings. Track two boolean flags that affect the final ending. No story longer than 200 words total — focus on the logic.

Concepts combined: if/else if/else, boolean flags, combined conditions with &&.

Time budget: 30 minutes.


Drill 3 — Manuscript Filter (Arrays + Strings + Functions)

Pre-populate an array of 8 manuscript names (real ones — from Project 6). Then:

  1. Print the full roster, numbered.
  2. Ask the user for a search prefix (e.g., “Codex”).
  3. Loop through the roster and print every manuscript whose name starts with that prefix.

Hint: name.substr(0, prefix.length()) == prefix.

Concepts combined: arrays, string operations, linear traversal, function decomposition.

Time budget: 25 minutes.


Drill 4 — Tiny Inventory (Structs + Array + Menu)

Define a Player struct with string name, int hp, int attack. Build a menu-driven program that supports:

  1. Add a player (up to 5).
  2. List all players.
  3. Damage a player by name (subtracts an amount from their HP, clamped at 0).
  4. Exit.

Each operation lives in its own function. main is just the menu loop.

Concepts combined: structs, struct arrays, count variable, menu dispatch, pass by reference, conditionals, functions.

Time budget: 40 minutes.


Drill 5 — Day Simulator (The Whole Stack)

This drill is the closest analog to the midterm. Allot 60 minutes.

Define a Citizen struct: string name, string job, int energy. Build a program that:

  1. Initializes 5 citizens by hand at the top of main (no prompting).
  2. Runs one day in 4 phases:
    • Morning (+5 energy)
    • Work (job-dependent: “guard” -10, “merchant” -6, “scribe” -4, anything else -8)
    • Meal (+8 energy)
    • Evening (-3 energy)
  3. After each phase, prints every citizen’s name and current energy.
  4. After the day, prints the citizen with the lowest energy at end-of-day with the label “needs rest”.

Use functions for each phase (e.g., void morning(Citizen team[], int count)). Don’t do all the math in main.

Concepts combined: everything from Chapters 1–7. This is the dress rehearsal.

Time budget: 60 minutes. Time yourself. The real midterm gives you 75, so finishing this in 60 means you walk in with margin.


Drill 6 — Sample Midterm Prompt

Open code/sample_midterm.cpp. Read the prompt at the top (a multi-line comment). Then close the file.

Open a fresh blank file. Implement the prompt from scratch.

When you’re done, open the original and compare. The sample includes a reference implementation below the prompt — use it as a study tool, not as a thing to copy.

Time budget: 60 minutes, sealed.


After the Drills

If you got through Drill 5 in close to an hour, with a working program at the end, you are ready.

If you got through Drill 5 in two hours and the program had bugs you couldn’t find — that’s also fine, just do another drill. Make a new variant: change the phases, change the struct, change the rules. The variety builds fluency.

The students who do 3 full-stack drills the week before the midterm score noticeably higher than the students who only do one. The cost is six hours of your week. The cost of not doing them is sometimes a full letter grade.

See you in the exam room.