Chapter 08 · Week 8

Midterm Review

"For the LORD gives wisdom; from his mouth come knowledge and understanding." — Proverbs 2:6
8

Find your gaps before the exam does

Below is a self-assessment of the six patterns the midterm tests. Read each one; mark whether you can write it cold. The students who pass are the ones who know where their gaps are.

Midterm Pattern Checklist

Six composition patterns that combine concepts from Chapters 1–7. Read each one, then mark whether you can write it cold. Status saved per browser — refresh and your checks come back.

YOUR READINESS
0 / 6
How to use this: read each pattern, picture writing it cold. If your hands can do it, mark "Got it." If you'd hesitate, mark "Needs work" and re-do the relevant rep. The students who pass the midterm are the ones who knew where their gaps were.

The Seven Chapters, Compressed

A one-paragraph reminder of each. If any of these don't ring a bell, re-read the relevant chapter before the exam.

  • Ch 1 — The Sport. cout, cin, the three pillars. The skill lives in your hands; reps are how it gets there.
  • Ch 2 — Types. Five types. The integer-division trap. boolalpha.
  • Ch 3 — Conditionals. if/else if/else. == not =. Always brace.
  • Ch 4 — Loops. for/while/do…while. Off-by-one. Sentinels and break.
  • Ch 5 — Functions. Return type, parameters, return value. Pass-by-reference (&). Composition.
  • Ch 6 — Arrays/Strings. Fixed-size + count. Indices 0 to size-1. Linear search returns index or -1.
  • Ch 7 — Structs. Bundle related fields. Trailing semicolon on the declaration. Pass const T& by default.

The Bug List

Tape this to your wall the morning of the exam:

  1. Integer division — cast at least one operand to double.
  2. Off-by-one — < vs <=.
  3. = instead of == in an if.
  4. Missing break; in switch.
  5. Function modifies its parameter but the change "doesn't stick" — pass by value vs &.
  6. Missing #include at the top.
  7. Comparing doubles with ==.
  8. Uninitialized variable.
  9. Missing trailing semicolon on a struct declaration.
  10. Off-by-one starting a sum at 0 vs 1.

Exam Rules

60 minutes. Closed-book, closed-internet, closed-AI. The textbook itself (printed or non-interactive PDF) and your own past project files are permitted. The exam project is P8 — Mission Trip Simulator. Read the full spec on the project page.

Coach's Note — This is the first test where you cannot reach for AI. You will probably feel the absence acutely in the first ten minutes. That's normal. Hold the discomfort. The discomfort is the test working. If you've prepared honestly — typed the reps, written the projects, debugged your own bugs — the discomfort will pass. Your hands will start working.

How to Spend Your Last Week

  1. Days 1–2: Re-do 2–3 hardest reps from each Chapter 1–7.
  2. Days 3–4: Work through the combination drills in the Chapter 8 reps.
  3. Day 5: Do one full timed sample midterm. Open code/sample_midterm.cpp, read the prompt, close the file, solve from blank in 60 minutes.
  4. Day 6: Read your own past project code aloud. Re-do anything that surprises you.
  5. Day 7 (exam day): Light review only. Re-read the bug list above. Eat. Show up early.

What's on the Exam (general shape)

  • Define one or more structs.
  • Initialize an array of structs with a count variable.
  • Run a loop updating state across iterations (often phases of a day).
  • Apply conditional logic per element.
  • Compute aggregate stats at the end.
  • Print structured output.

That's the Mission Trip Sim. The actual prompt is sealed until exam time, but the shape is no secret.

Check Your Reps

Pre-Midterm Self-Check

Question 1 of 4
What does this print?
int total = 0;
for (int i = 1; i <= 5; i++) {
    if (i % 2 == 0) total += i;
}
cout << total;
Why: The loop visits i = 1, 2, 3, 4, 5. The if accepts only even values: 2 and 4. So total = 2 + 4 = 6. This combines Pattern 3 (accumulator) and Pattern 6 (per-element decision) — two of the patterns the midterm tests.
Question 2 of 4
Which version correctly remove-shifts an element from an array of Citizen structs?
// Remove citizens[i], where 0 <= i < count
//
// (A)
for (int j = i; j < count - 1; j++) {
    citizens[j] = citizens[j + 1];
}
count--;

// (B)
for (int j = i; j < count; j++) {
    citizens[j] = citizens[j + 1];
}
count--;

// (C)
citizens[i] = citizens[count - 1];
count--;
Why: (A) is the correct shift-down: loop from i to count-2, copy from j+1 to j, then decrement count. (B) goes one too far — j+1 = count is past the in-use area. (C) is a valid alternative only if order doesn't matter — it moves the last element into the hole, but the original ordering is lost.
Question 3 of 4
On exam day, you have 5 minutes left and your "exhausted" check has a bug. What's the best move?
Why: Ship a clean Normal that compiles and runs over a buggier Medium that doesn't. The rubric rewards completion of lower tiers over partial completion of higher ones. A working file gets you the 70%. A non-compiling file gets you very little.
Question 4 of 4
You can't use AI on the midterm. Which of these is also disallowed?
Why: Closed-internet, closed-AI. Your own textbook and your own past code are allowed (the textbook explicitly says so). The compiler and editor are obviously allowed. Internet — including help docs or Stack Overflow — is not.
YOU FINISHED. NICE WORK.

← WEEK 7: STRUCTS   ·   WEEK 9: CLASSES →