116 compile-checked programs · C++17
Examples that follow the learning path.
Every filename begins with its lecture reference. Each example uses only concepts taught by that lecture; motivating previews show results without exposing later syntax.
116 examples
Select an example
Choose an example to load its source.
Programming & Problem Solving
Minimal program structure and observable output.
lecture-01-travel-time-estimator.cpp
main and observable outputThe entry point prints one visible result.lecture-01-main-and-output.cpp
Game evolution · first worldOutput draws one fixed Snake-and-Cleaner frame.lecture-01-game-first-world.cpp
Hello, WorldEntry point, output stream, and successful termination.lecture-01-hello-world.cpp
Types & Representation
Range, precision, constants, inference, and conversion.
lecture-02-sensor-packet-types.cpp
Game evolution · named stateNamed constants and variables give the world memory.lecture-02-game-named-state.cpp
Sensor packet typesFixed-width integers, floating point, bool, char, auto, and static_cast.lecture-02-types-and-conversions.cpp
Expressions, Scope & Program State
Names, visibility, storage duration, and linkage.
lecture-03-block-scope.cpp
NamespacesA qualified name keeps same-named declarations apart.lecture-03-namespaces.cpp
Operators and expressionsPrecedence, grouping, and a combined condition.lecture-03-operator-precedence.cpp
Game evolution · one transitionTemporary names compute the next position in a block.lecture-03-game-state-transition.cpp
Update game state without leaking temporary namesA block-local reward updates score and then disappears.lecture-03-game-score-scope.cpp
Pre-increment vs post-incrementPrefix and postfix forms in assignments, output, and conditions (Lecture 3.5).lecture-03-increment-operators.cpp
Expressions and scopeNamespaces, precedence, nested scope, and global state.lecture-03-expressions-and-scope.cpp
Static and externPersistent local state plus an externally defined value.lecture-03-storage-and-linkage.cpp
Shared definitionTranslation-unit definition used by the linkage example.lecture-03-shared-data.cpp
Decisions & Safe Branching
Ordered safety rules and explicit boundaries.
lecture-04-overcurrent-protection.cpp
Game evolution · legal moveA move is applied only when it is inside the board and not blocked.lecture-04-game-legal-move.cpp
Overcurrent controllerShort-circuit protection logic and ordered classification.lecture-04-overcurrent-controller.cpp
Iteration I · while & Input Validation
Condition-controlled repetition and progress.
lecture-05-production-quality-scan.cpp
Game evolution · command loopA do-while validates a command; a while advances turns until quit.lecture-05-game-command-loop.cpp
Production quality scanA while-loop invariant with a defect-based stopping condition.lecture-05-production-scan.cpp
Iteration II · for, Nested Loops & Invariants
Counted ranges and row–column combinations.
lecture-06-multiplication-table.cpp
Game evolution · render the boardNested loops turn state into a board.lecture-06-game-render-board.cpp
Counted and nested for loopsA single loop, an exact-range loop, and row-column pairs.lecture-06-for-loop-forms.cpp
Calibration gridTwo counted loops enumerate every row–column pair.lecture-06-nested-loops.cpp
Functions I · Contracts & Calls
Value parameters, return values, and decomposition.
lecture-07-travel-estimate-function.cpp
Declare once, define onceA prototype lets main call a function defined below it.lecture-07-declare-then-define.cpp
Game evolution · scoring functionA value parameter leaves the caller's score unchanged.lecture-07-game-score-function.cpp
Value parameters, named steps, and lambdasSmall functions and a lambda composed into one program.lecture-07-functions-and-lambdas.cpp
Function contractsValue parameters and return values for three single-purpose functions.lecture-07-function-contracts.cpp
Functions II · References & Decomposition
References, const access, and call structure.
lecture-08-order-pair.cpp
Game evolution · movement functionReference parameters let one function update the position.lecture-08-game-move-player.cpp
Copy, alias, or read-only accessReference, const reference, and overload forms from the slides.lecture-08-reference-parameters.cpp
Recursion needs a base caseA base case and a smaller next call.lecture-08-recursive-factorial.cpp
Order a pairReturn two related results through reference parameters.lecture-08-output-references.cpp
Arrays I · Fixed Sequences & Traversal
Fixed extents, indices, bounds, and traversal.
lecture-09-anomalous-temperature.cpp
Game evolution · linked segmentsParallel arrays hold the body; a loop checks for a collision.lecture-09-game-snake-collision.cpp
Arrays, indices, and traversalstd::array declaration, indexing, indexed and range-for traversal, array parameter.lecture-09-voltage-array.cpp
Weekly temperaturesA fixed array traversed with its actual size as the bound.lecture-09-weekly-temperatures.cpp
Two-Dimensional Arrays & std::vector
Matrices, nested traversal, and runtime-sized vectors.
lecture-10-score-matrix-summary.cpp
Game evolution · 2D worldA two-dimensional char array represents the world.lecture-10-game-world-grid.cpp
Two-dimensional arraysDeclare a 2D array and traverse it with nested loops.lecture-10-matrix-traversal.cpp
std::vector push_back and atA dynamically sized sequence with checked access.lecture-10-vector-readings.cpp
Score matrixNested vector traversal with checked row and column access.lecture-10-matrix-vector.cpp
Image gridA fixed two-dimensional array rendered through nested traversal.lecture-10-image-grid.cpp
Strings & Text Processing
Owned text, input, classification, and validation.
lecture-11-institute-email-check.cpp
Game evolution · replay stringA string stores commands; a loop validates each one.lecture-11-game-replay-string.cpp
Size, find, substr, and classificationPositions and lengths make text operations explicit.lecture-11-string-operations.cpp
Enrollment ID validatorPrefix, length, and digit predicates with safe cctype use.lecture-11-enrollment-id.cpp
Text as a sequenceA vector of strings rendered line by line.lecture-11-cat-text.cpp
Errors, Debugging & Testing
Pre-conditions with assert, test drivers, and the recursion, array, and string questions from the review sets.
lecture-12-divide-assert.cpp
Test divide with a test driverKnown-input tests pass; then a violated pre-condition aborts (intended).lecture-12-divide-test-driver.cpp
Average marks without dividing by zeroassert for a pre-condition, if for user input (reads marks ending in -1).lecture-12-average-marks.cpp
Set A · Array statistics through referencesMinimum, maximum, and mean through reference parameters.lecture-12-array-statistics.cpp
Set A · Recursive sum of the first n numbersA base case and a smaller call, then a decision on the result.lecture-12-recursive-sum.cpp
Set A · String validation and countingfind, npos, substr, and a digit count.lecture-12-string-validation.cpp
Set B · Search an array using a functionLinear search returning an index or -1.lecture-12-first-index-search.cpp
Set B · Recursive powerpower(base, exp) with a base case at exp == 0.lecture-12-recursive-power.cpp
Set B · Vector totals and a string lengthpush_back, indexed traversal, and size.lecture-12-vector-totals.cpp
Rainfall analyzerFunctions, vector traversal, accumulation, and maximum-index search.lecture-12-rainfall-integration.cpp
Boundary testsRepair average calculation and test empty and integer-division cases.lecture-12-boundary-tests.cpp
Structures & Pointers
Records, the address-of and dereference operators, null pointers, member access, and layout.
lecture-13-reading-struct.cpp
An array of structsMany records of one type stored together.lecture-13-array-of-structs.cpp
Address-of, dereference, and null pointerA pointer holds an address; nullptr points to no object.lecture-13-pointer-basics.cpp
Check before you dereferenceA pointer must point to an object before it is dereferenced.lecture-13-null-check-before-dereference.cpp
Return a pointer when "not found" is an answerLook up a sensor; nullptr means no match.lecture-13-find-sensor-pointer.cpp
Member access: dot and arrowDot through an object, arrow through a pointer.lecture-13-member-access.cpp
Passing a struct to a functionCopy a struct, pass by const reference and by reference.lecture-13-struct-parameters.cpp
A pointer parameter has a pre-conditionThe pointer must not be null; the last call aborts (intended).lecture-13-null-pointer-precondition.cpp
Alignment and paddingsizeof and offsetof show the padding; values are implementation-specific.lecture-13-struct-padding-layout.cpp
Pointer arithmeticPointers move by whole elements inside one array.lecture-13-pointer-arithmetic.cpp
Sensor recordsArray of structs plus null-safe pointer member access.lecture-13-sensor-records.cpp
Structure paddingCompare size, alignment, and field offsets for two layouts.lecture-13-structure-padding.cpp
Dynamic Memory & Linked Lists
Lifetimes, new and delete, unique_ptr, linked nodes, and allocation failure.
lecture-14-two-lifetimes.cpp
new and deleteOne object or an array of objects, released with matching delete forms.lecture-14-new-and-delete.cpp
unique_ptr: exclusive ownershipOwnership moves and is released automatically.lecture-14-unique-ptr.cpp
A linked list of nodesNodes connected by next pointers.lecture-14-linked-nodes.cpp
Build and summarize a linked listInsert at the head, traverse, sum, and release.lecture-14-list-build-and-sum.cpp
A list function has a pre-conditionfront requires a non-empty list; the last call aborts (intended).lecture-14-list-front-precondition.cpp
C allocation: malloc and freeBytes, not objects; free pairs with malloc.lecture-14-malloc-and-free.cpp
Allocation failurenew throws bad_alloc; nothrow new returns nullptr.lecture-14-allocation-failure.cpp
Memory and linked listsRaw allocation, smart pointers, failures, and list operations.lecture-14-dynamic-memory-and-lists.cpp
C allocation APImalloc, calloc, realloc, free, and address tracing.lecture-14-c-allocation.cpp
Stacks, Queues & Abstract Data Types
Last-in first-out and first-in first-out containers behind one interface.
lecture-15-insertion-is-a-stack.cpp
Bracket matching with std::stackThe last bracket opened closes first.lecture-15-bracket-matching.cpp
A print queue with std::queueJobs are served in arrival order.lecture-15-print-queue.cpp
One interface, three implementationsstd::stack over deque, vector, and list.lecture-15-stack-containers.cpp
Cost decides the representationDequeue from a vector versus a deque; timings are implementation-specific.lecture-15-queue-cost.cpp
Reading or removing from an empty containerTest empty() before top(); the last pop violates its pre-condition (aborts, intended).lecture-15-empty-container-errors.cpp
Linear searchFirst and all matching indices in an unsorted array.lecture-15-linear-search.cpp
Array stackLIFO operations as free functions over a plain state record.lecture-15-array-stack.cpp
Linked queueFIFO free functions over dynamically linked nodes.lecture-15-linked-queue.cpp
Record queueStudent records in a circular-array queue without class prerequisites.lecture-15-record-queue.cpp
Elementary sortsBubble, selection, and insertion sort traces.lecture-15-elementary-sorts.cpp
Recursion & the Call Stack
Base cases, shrinking measures, backtracking, and memoization.
lecture-16-print-list-backward.cpp
Print in binaryA measure that halves to the base case, with an assert pre-condition.lecture-16-print-binary.cpp
Recursive list reversalReverse the rest, then attach the head.lecture-16-recursive-reverse.cpp
Folder sizesRecursion over a nested structure of folders.lecture-16-folder-sizes.cpp
Permutations by backtrackingChoose, explore, undo over the letters of "abc".lecture-16-permutations.cpp
Grid routes with memoizationNaive and memoized call counts on a 12×12 grid.lecture-16-grid-paths-memo.cpp
Recursive list reversalMove unique ownership while reversing a linked chain.lecture-16-recursive-list.cpp
Classes & Constructors
Class invariants, access control, constructors, and const member functions.
lecture-17-binary-search-sorted.cpp
A struct cannot protect its ruleOne push_back breaks sortedness; the search goes wrong.lecture-17-struct-breaks-rule.cpp
A class keeps its invariantPrivate data, a constructor that sorts, members that keep the order.lecture-17-sorted-scores-class.cpp
Overloaded constructorsThe arguments choose the constructor; each starts the object valid.lecture-17-constructors.cpp
Binary searchIterative, recursive, first, and last occurrence variants.lecture-17-binary-search.cpp
Binary search treeInsertion, search, deletion, traversals, and cleanup.lecture-17-binary-search-tree.cpp
Heap and heap sortHeapify, insertion, extraction, and phased sorting.lecture-17-heap-and-heapsort.cpp
Merge sortRecursive and bottom-up merge sort plus inversion counting.lecture-17-merge-sort.cpp
Destructors, Copying & RAII
Object lifetime, shallow and deep copy, and the Big Three.
lecture-18-lifetime-trace.cpp
Shallow copy of a pointerTwo owners of one array, then a double deletion.lecture-18-shallow-copy.cpp
Copy constructor and copy assignmentEach object owns its own array; a = a is safe.lecture-18-deep-copy.cpp
None of the Big Three to writestring and vector members copy and release themselves.lecture-18-vector-members.cpp
Complex number valueConstructor, const operator+, value copying, and display.lecture-18-complex-value.cpp
Inheritance: Base & Derived Classes
A SearchTree derived from a BinaryTree: construction order, access, substitution, and composition.
lecture-19-base-derived.cpp
Order of constructionBase first, then data members, then the derived body; destruction in reverse.lecture-19-construction-order.cpp
protected and friendWho may name root and count: a derived class, main, and a friend function.lecture-19-access.cpp
When substitution failsA base operation, addLeftmost, breaks the search tree invariant.lecture-19-substitution.cpp
CompositionA Library has a SearchTree data member instead of inheriting from it.lecture-19-composition.cpp
Calibrated energy meterFriend calibration and a simple public derived class.lecture-19-friend-and-inheritance.cpp
Virtual Functions & Polymorphism
Late binding, abstract classes, virtual destructors, and a factory function.
lecture-20-virtual-add.cpp
Early and late bindingA hidden function and an overridden virtual function called through a base reference.lecture-20-late-binding.cpp
Abstract classShape declares pure virtual functions; Square and Circle override them.lecture-20-abstract-shape.cpp
A new derived classTriangle is added and report() is not edited.lecture-20-new-shape.cpp
Virtual destructorA unique_ptr<Shape> releases a Square: derived destructor first, base last.lecture-20-virtual-destructor.cpp
Factory functionmakeShape() chooses the derived class and returns a unique_ptr<Shape>.lecture-20-factory.cpp
Multiple inheritanceA virtual base class gives Copier one shared Device part.lecture-20-multiple-inheritance.cpp
Employee polymorphismVirtual work behavior through base-class pointers.lecture-20-employee-polymorphism.cpp
Polymorphic Data Structures
Heterogeneous ownership behind a common interface.
Applied Object Systems
Domain models, collection algorithms, graphs, and patterns.
Recursive & Polymorphic Capstones
Buckets, matrices, trees, and hierarchy applications.
lecture-23-radix-sort.cpp
Invert a treeRecursive subtree transformation with unique ownership.lecture-23-invert-tree.cpp
Linked Snake gamePlayable turn-based Snake with an explicit segment chain, collision invariants, and ASCII rendering.lecture-23-snake-linked-game.cpp
Grid cleaning robotRobot simulation that visualizes vector-queue BFS routes to the nearest dirt.lecture-23-grid-cleaning-robot.cpp
Multi-agent graph cleaningObject-oriented cleaners coordinate vector-stored BFS routes and distinct target reservations.lecture-23-multi-agent-graph-cleaning.cpp
No examples match that search.