The companion site · 20 chapters · 63 agent traps · 166 code files
AI Assisted C and C++ Programming
Learn the Machine, Direct the Agent
A first course in C and C++ for students who know Python, written for a world where a coding agent can produce the assignment in seconds. You learn the machine by hand, then earn the agent, direct it with a written spec, and prove its work with instruments that do not hallucinate.

Every chapter, every assignment
The working loop
Click a step to see what it asks of you.
- 1PredictYou, no AI
- 2WriteYou, no AI
- 3SpecifyYou
- 4DelegateThe agent
- 5AuditYou and the tools
- 6DefendYou, live
Step 1 of 6 · You, no AI
Predict
What you hand in: A written prediction: the output, the memory state, the operation count, and how sure you are.
Why this step: A prediction written before the run is the only way to learn whether your model of the machine is right. A miss is the most useful result there is, because it shows exactly where the model is wrong.
The first prediction is never delegated.
Ask yourself: What will this print, what will memory look like when it ends, and how many operations will it take?
For example, in Chapter 10: the bound and the slope for each sort on random, sorted, reverse and equal input, written before any timing; the comparison counts for Listings 10.1 and 10.3.
Predict in every chapter · Log the prediction in your work log · Chapter 10's Predict step
Step 2 of 6 · You, no AI
Write
What you hand in: One small piece written by hand, to build the mental model.
Why this step: You can only check what you could have built. Writing a small piece yourself gives you the model you will need to judge the agent's version later.
Ask yourself: Could I write this piece again tomorrow without notes?
For example, in Chapter 10: insertion sort for struct reading by hand, with its own tests and timings.
Write in every chapter · Browse the companion code · Chapter 10's Write step
Step 3 of 6 · You
Specify
What you hand in: The header or class interface, unit tests, a complexity budget and the ownership rules.
Why this step: The specification is the contract the code will be held to. Tests written first, a cost budget and ownership rules turn "looks right" into something you can check.
- Tutor You specify a question instead of code: what you want explained, quizzed or drilled.
The ownership and lifetime section of a specification is never delegated.
Ask yourself: Who allocates, who frees, what does it cost, and what input would break it?
For example, in Chapter 10: stn_sort.h with stability, ownership of the temporary, error returns and a complexity budget over named inputs; test_sort.c with edge, stability and hostile-input tests, compiled and failing against stubs.
Specify in every chapter · Prompt and specification templates · Chapter 10's Specify step
Step 4 of 6 · The agent
Delegate
What you hand in: The implementation from your specification, or an explanation in the Tutor phase, with the prompts and transcript saved.
Why this step: The agent does the typing; you keep the judgment. Saving the prompts and the transcript makes the delegation something you can audit afterward.
- Tutor The agent explains, quizzes and makes practice problems. It writes no code you submit.
- Pair The agent writes small units from your specification, and you audit every line.
- Team Several agent sessions work in separate roles (Writer, Reviewer, Tester). You direct them and make the final call.
Ask yourself: Did I hand over my specification and tests, and did I save what the agent said?
For example, in Chapter 10: the Pair implements stn_merge_sort_by_time and stn_quick_sort_by_time from the spec; the Adversary proposes inputs; prompts and transcripts saved.
Delegate in every chapter · Prompt templates · Chapter 10's Delegate step
Step 5 of 6 · You and the tools
Audit
What you hand in: The Audit Report: tests, sanitizer and Valgrind output, your own cost derivation against a timing plot, the defects found, and a keep-or-rewrite decision.
Why this step: What the agent says is testimony until an instrument confirms it. Tests, sanitizers, Valgrind and a timing plot are evidence.
- Tutor The audit checks the tutor's claims as well as your own code.
The final judgment that the code is correct is never delegated.
Ask yourself: What did the sanitizer report, does the timing plot match my derivation, and would I keep this code or rewrite it?
For example, in Chapter 10: line reading against the spec, sanitizer and Valgrind runs, your own recurrence for each function, the harness on four input kinds, and the slope compared with your derivation.
Audit in every chapter · The Audit Report template · Chapter 10's Audit step
Step 6 of 6 · You, live
Defend
What you hand in: A five-minute oral defense.
Why this step: If you can explain it live, you own it. The oral checks that the understanding is yours and not the agent's.
Ask yourself: Why this bound, what input breaks it, and where is this memory freed?
For example, in Chapter 10: why this bound, which input breaks a pivot rule, where the temporary is freed.
Defend in every chapter · How the loop works · Chapter 10's Defend step
The agent can write the code. Only you can own it. How the loop works →
What the agent may do grows as you do
Three phases
Chapters 1 to 9
Tutor
Explains concepts and compiler messages, quizzes you and makes practice problems. It writes no code you submit.
Chapters 10 to 15
Pair
Writes small units from a specification you wrote first. You audit every line.
Chapters 16 to 20
Team
Several agent sessions in separate roles. You direct them and make the final call.
In every phase, the hand-worked concept section, the prediction and the memory checkpoint stay AI-free.
The book
AI Assisted C and C++ Programming: Learn the Machine, Direct the Agent, by Dr. Jerry A. Smith. 792 pages in five parts, 20 chapters (Chapter 20 optional) and seven appendices, with a running project, a field-sensor station, carried through six programming assignments. Every listing in the book was compiled and run.