Skip to content

Exercises

Every module has practice exercises in three tiers, plus optional stretch work. They exist because programming cannot be learned by reading: the act of writing something that does not work yet, and fixing it, is the learning.


The Exercise Bank — 160 extra exercises

Beyond the per-module sets, the course carries a large standalone Exercise Bank: 160 exercises covering the whole course, organised by topic and labelled by difficulty from Level 1 (Basic) to Level 6 (Advanced). Each states its level and its kind (conceptual question, code tracing, debugging, completion, modification, output prediction, design, refactoring, and the subject areas), and 66 of them are scenario-based — set in a small realistic situation rather than an abstract puzzle.

The bank keeps its answers out of the way, in three separate places:

File What it holds
The fourteen topic pages The exercises, and nothing else
Hints One nudge per exercise — a pointer, never the answer
Solutions and answers A model answer per exercise

The bank's exercises are independent of the tiers above and of each other; use it for revision, for exam practice, or whenever you want more of one idea.


The three tiers

Tier Size Purpose If it takes you longer than…
Warm-up ~5 lines, one idea Confirm you can use the syntax at all …15 minutes, reread the concepts section
Core One program, two or three concepts combined The standard the module expects of you …an hour, look at the worked examples again
Challenge Open-ended, design-flavoured Transfer to a case the module did not spell out no limit — these are meant to be hard

Plus stretch prompts where they exist: small "what changes if…" refactors for students who finish early. They are usually the most interesting part of the exercise set and are never required.


How to use them

Attempt before looking. Every module's own Exercises page ends with a Solutions section that says where the answer to each exercise lives — usually the reference program under examples/module-NN/ that models it, sometimes the discussion that is the answer. A few exercises deliberately have no published answer, and the module says which and why. Read a solution only after your own version builds — otherwise you will learn to recognise, not to write.

Write the expected behaviour first. For anything beyond a warm-up, write down in one or two sentences what the program should do, including what it should do when given bad input. Then write the code. This is the single habit that most improves exercise outcomes.

Run it. Then break it. After it works, change an input, remove a const, try an empty collection. Learning what your code does when it is not being used politely is worth more than getting it right the first time.

Keep going when you are wrong. The exercises are staged so that being wrong is expected. A challenge exercise you cannot solve but attempt honestly teaches more than three core exercises you found easy.

Do not skip the challenge tier. Core exercises practise what you were just shown. Challenge exercises are where you find out whether you can use the idea in a situation the module did not hand you — and that is what exams and real work ask for.


What the tiers look like

Illustrative examples, so you can tell them apart. The actual exercises for each module are on that module's page.

Warm-up (Module 3 — constructors)

Write a Point class with a constructor taking x and y, a const member function distanceFromOrigin(), and nothing else. Create three points and print their distances.

Core (Module 7 — polymorphism)

A base class Shape with a virtual area(); derived Circle and Rectangle. Store several shapes by std::unique_ptr in a std::vector, then print each area through a base reference. Then explain, in a comment, what would have happened if area() were not virtual.

Challenge (Module 9 — composition)

The catalogue currently lets a caller retrieve the internal collection by reference. Redesign the interface so that callers can query availability, find items and get a count — but can never add, remove or reorder items directly. Then write one paragraph explaining the invariant your new interface makes impossible to violate.

Stretch (Module 4 — encapsulation)

You added a getTitle() accessor. Change the class so that a caller can ask whether two items have the same title, but never obtains the title itself. Which callers break, and is that an improvement? Justify either answer.


Where the solutions are

The course publishes its answers, but not all in one place, because the kind of answer differs:

Where What you get
The module's own Exercises page A Solutions section mapping each exercise to the reference program that models it, or to the discussion that is the answer
Solutions and answers A model answer for each of the 160 bank exercises, with Hints for a nudge before it
examples/labs/lab-01/solution/ … lab-04/solution/ Complete reference solutions for the first four sequential labs
examples/module-NN/ The compiled, runnable programs that every module page refers to

The later sequential labs publish no solution file on purpose — each is an increment on the program you already wrote, so the decisions are the exercise. The lab page says what to compare instead.

Every example and every solution compiles with the course's one command — the same command used throughout the course:

g++ -std=c++17 -Wall -Wextra your_file.cpp -o your_file

Among the module exercises, a few have no published answer on purpose: the module's Solutions section names them and says why. Usually the exercise is the design decision, and an answer would replace the decision with recognition.


If you are stuck

  1. Reread the module's worked examples and run them yourself, changing one thing at a time.
  2. Reduce the problem. Comment out code until it builds; put it back a piece at a time. The piece that breaks the build is the piece to study.
  3. Check the error properly. Reading Compiler Errors resolves most beginner mistakes in minutes.
  4. Look up the term. The glossary defines every term the course uses.
  5. Then look at the solution — and immediately rewrite your own version from your own understanding rather than copying.

Related: The Exercise Bank · Labs · Quizzes · Module index · Cheat Sheets