Complete, from-skeleton solutions to all seven assignments of CS106L — Standard C++ Programming (Stanford University), part of a csdiy.wiki full-catalog build. Every assignment is implemented to spec and passes the course's own autograder.
CS106L is Stanford's companion course to CS106B that explores modern C++ in
depth: streams, references and initialization, STL containers and iterators,
classes and const-correctness, templates, lambdas, operator overloading,
special member functions, move semantics, std::optional, and RAII with smart
pointers. This repository contains an independent implementation of the seven
weekly assignments from the official course assignments
repo (Spring 2026 offering),
built from the official starter skeleton and verified against the provided
autograders on Windows with MSYS2 g++ 14.2 (-std=c++20/-std=c++23).
Every assignment passes its official autograder. Raw captured output for each is
in results/.
| Assignment | Topic | What it implements | Result (measured) |
|---|---|---|---|
| A0 Setup | Environment | Toolchain check | autograder 3/3 (compiler, git, python) |
| A1 SimpleEnroll | Streams, references | CSV parse + filtered writes (parse_csv, write_courses_offered/not_offered) |
autograder 2/2 |
| A2 Marriage Pact | Containers, pointers | std::set of applicants, std::queue<const std::string*> of initials-matches |
autograder 2/2 |
| A3 Make a Class | Classes, const-correctness | BankAccount (2 ctors, private field + method, const getter, setter) |
CastXML autograder 6/6 |
| A4 Ispell | STL algorithms, ranges, templates | tokenize (STL, no loops) + spellcheck (ranges views, Damerau-Levenshtein) |
autograder 4/4, 7/7 gold texts |
| A5 Treebook | SMFs, operator overloading | User destructor, copy ctor/assign, deleted moves, operator<< += < |
autograder 8/8 (incl. leak checks) |
| A6 ExploreCourses | std::optional, monads |
find_course → std::optional<Course>, transform/value_or (no conditionals) |
autograder 2/2 |
| A7 Unique Pointer | RAII, move semantics, templates | move-only cs106l::unique_ptr<T> + recursive create_list |
autograder 6/6 |
Total: 30/30 graded checks across the assignments (plus the 3/3 setup check).
A few concrete measured samples:
- A4 Ispell loads a 464,811-word dictionary and correctly flags/suggests:
mispelled → {dispelled, misspelled},vilage → {milage, pilage, silage, viage, village, vinage, visage, volage}. With--profileonexamples/(marquez).txt(84 tokens): tokenizing input0.14 ms, dictionary tokenization~795 msfor 466,550 tokens, spellcheck brute-forcing the full dictionary per token. (Seeresults/assignment4_sample_run.txt.) - A7 unique_ptr builds a linked list, prints it, and the RAII destructor
chain frees every node in order — verified leak-free by the autograder's
custom
operator new/deleteaccounting. (Seeresults/assignment7_linked_list_run.txt.)
- A0 — Assignment Setup — environment/toolchain sanity check.
- A1 — SimpleEnroll — parse ExploreCourses CSV with streams; write the offered vs. not-offered courses, removing offered ones from the working vector.
- A2 — Marriage Pact — read applicants into a
std::set; find everyone sharing your initials into astd::queueof pointers (no copies); pick a match. - A3 — Make a Class — a
BankAccountclass meeting all six requirements (parameterized + default constructors, private field, private method, const getter, setter); const-correct. - A4 — Ispell —
tokenizeusing only STL algorithms (std::transformwith overlapping ranges,std::inserter,std::erase_if; no for/while loops) andspellcheckusing the C++20 ranges/views library. - A5 — Treebook — extend a
Userclass with afriend operator<<, a destructor, copy constructor and copy assignment (deep-copying the raw_friendsarray), deleted move operations, and memberoperator+=/operator<. - A6 — ExploreCourses — change
find_courseto returnstd::optional<Course>and build the output with monadic operations (transform+value_or) with noifstatements. - A7 — Unique Pointer — implement a move-only
cs106l::unique_ptr<T>(raw pointer member,operator* -> bool, RAII destructor, deleted copy, move ctor/assignment with self-assignment guard) pluscreate_list.
cs106l/
├── assignment-setup/ # A0 environment check (starter, no code needed)
├── assignment1/ # SimpleEnroll → main.cpp
├── assignment2/ # Marriage Pact → main.cpp, short_answer.txt
├── assignment3/ # Make a Class → class.h, class.cpp, sandbox.cpp, short_answer.txt
├── assignment4/ # Ispell → spellcheck.cpp
├── assignment5/ # Treebook → user.h, user.cpp
├── assignment6/ # ExploreCourses → main.cpp
├── assignment7/ # Unique Pointer → unique_ptr.h, main.cpp, short_answer.txt
├── results/ # captured autograder output + sample runs (evidence)
├── run_autograder.sh # convenience runner (see Verification)
├── LICENSE # MIT (covers this repo's own code only)
└── README.md
Each assignment*/autograder/ holds the course's Python autograder; it creates
its own virtualenv at runtime (git-ignored).
Toolchain: MSYS2 g++ 14.2 on PATH (C++17/20/23) and Python 3.8+.
Compile and run any assignment (Windows note: the executable is main.exe):
cd assignment1
g++ -static-libstdc++ -std=c++20 main.cpp -o main # A6 uses -std=c++23; A3/A4/A5 add class.cpp/spellcheck.cpp/user.cpp
./main # runs the code, then the autograderPer-assignment compile commands:
# A1 g++ -static-libstdc++ -std=c++20 main.cpp -o main
# A2 g++ -static-libstdc++ -std=c++20 main.cpp -o main
# A3 g++ -static-libstdc++ -std=c++20 main.cpp class.cpp -o main
# A4 g++ -static-libstdc++ -std=c++20 main.cpp spellcheck.cpp -o main
# A5 g++ -static-libstdc++ -std=c++20 main.cpp user.cpp -o main
# A6 g++ -static-libstdc++ -std=c++23 main.cpp -o main
# A7 g++ -static-libstdc++ -std=c++20 main.cpp -o mainOr use the helper (handles venv, UTF-8 console, and compile command):
./run_autograder.sh assignment4Try the A4 spellchecker directly:
cd assignment4 && g++ -static-libstdc++ -std=c++20 main.cpp spellcheck.cpp -o main
./main --unstyled "This string is mispelled"
Get-Content "examples/(marquez).txt" | ./main --stdin --unstyled --profile # PowerShellEach assignment ships with the course's own autograder (a C++ main that runs
the assignment, then invokes a Python grader under autograder/). All were run
on this machine and their output captured to results/:
- A1, A2, A6 — compare generated output files / program output against the course's reference answers.
- A4 — statically checks that
tokenize/spellcheckuse the required STL/ranges functions and contain no loops, then diffs the spellcheck output against 7 gold-standard literary texts (Kafka, Márquez, Morrison, Melville, Orwell, Tolstoy, plus a gibberish file). - A3 — uses CastXML + pygccxml to inspect the class's AST and confirm all six structural requirements.
- A5, A7 — override global
operator new/deleteto detect memory leaks while exercising the special member functions and operators.
Getting the course autograders to run under MSYS2 GCC 14.2 on a Chinese (GBK) Windows console required three environment adjustments. None of them modify course or autograder source code — they only adjust how the tools are invoked:
- UTF-8 console. The autograder prints emoji; on a GBK console its C++→Python
system()call dies withUnicodeEncodeError. Running the Python grader directly withPYTHONUTF8=1/PYTHONIOENCODING=utf-8fixes it. - A3 CastXML vs. GCC 14.2 headers. CastXML's bundled Clang cannot parse GCC
14.2's
<bits/c++config.h>(typedef __decltype(0.0bf16) __bfloat16_t;guarded by__BFLT16_DIG__). A venvsitecustomize.pymonkeypatches pygccxml to pass-U__BFLT16_DIG__to CastXML's Clang so that block is skipped. - A3 pygccxml relinking. pygccxml 2.5.0's
_relink_declarated_typescannot relink some standard-library template typedefs namedtype(from<type_traits>, pulled in by<string>). The samesitecustomize.pyextends pygccxml's existing skip-list to tolerate them — pure std-library noise, never the student's class, which is located separately.
run_autograder.sh documents and applies (1); (2)/(3) are a one-time
sitecustomize.py in assignment3/autograder/Lib/site-packages/ (git-ignored
with the rest of the venv).
- C++20 / C++23 (MSYS2 GCC 14.2): STL containers, iterators, algorithms,
the ranges/views library, templates, lambdas, operator overloading, special
member functions, move semantics,
std::optional, RAII / smart pointers. - Python 3 — the course autograders (colorama; CastXML + pygccxml for A3).
- Modeling records with plain structs and driving I/O entirely through
std::stringstream/std::ifstream/std::ofstream(A1). - Storing non-owning
const T*in containers to avoid copies, and reasoning about the resulting lifetime constraints (A2). - Writing const-correct classes and understanding what the compiler enforces (A3).
- Expressing loops as declarative STL/ranges pipelines —
std::transformover overlapping iterator ranges,filter/transformviews, materializing lazy views into containers without C++23'sstd::ranges::to(A4). - The full set of special member functions and the rule-of-five: deep copies, deleted moves, self-assignment guards, and leak-free ownership (A5, A7).
std::optionaland its monadic interface (transform/and_then/or_else/value_or) as a branch-free way to handle "maybe a value" (A6).- RAII and move-only ownership by building
unique_ptrfrom scratch, and why a moved-from pointer must be nulled to avoid double-free (A7).
Based on the assignments of CS106L — Standard C++ Programming by Stanford University (assignments by Fabio Ibanez, Haven Whitney, and Jacob Roberts-Baca). Original starter code and specifications belong to their authors; the official assignment repository is at https://github.com/cs106l/cs106l-assignments. This repository is an independent educational reimplementation. Original code here is released under the MIT License.