Skip to main content

End of the C++ Course

Summary and Final Challenge

Congratulations! You have completed all 10 modules and 26 lessons of the C++ course — from types, pointers, OOP, and virtual polymorphism to RAII smart pointers, templates, move semantics, STL/ranges, std::optional, exceptions, and std::jthread concurrency.

10 modules · 26 lessons · 130 checkpoints

C++ exercises are verified locally in the browser using Tree-sitter AST parsing (`tree-sitter-cpp.wasm`) plus structural and keyword checks; to compile and execute real C++20 code, click Open on Compiler Explorer (godbolt.org).

01 · Fundamentals of C++

The foundations: variables, primitive data types, arithmetic-logical operators and input/output management with std::cout and std::cin.

  • std::cout / std::cin
  • int / double / bool
  • auto & const
  • % / == / !=

02 · Flow Control

Conditional expressions for making decisions and iterative loops for repeating instructions.

  • if / else if
  • switch / break
  • for / while / do
  • for (auto x : v)

03 · Functions and References

Break down the code into reusable blocks and understand how C++ passes data into memory.

  • fn(int x)
  • int& / const T&
  • return
  • overload(a, b)

04 · Object Oriented Programming

Introduce classes, encapsulation, and automatic resource management.

  • class / struct
  • private / public
  • : count(0)
  • this->

05 · Data Structures and Pointers

Manage data collections and understand how physical memory works with pointers.

  • std::vector<T>
  • std::array<T, N>
  • &x / *p
  • nullptr & RAII

06 · Inheritance and Polymorphism

Extend existing classes and implement polymorphic behavior via virtual functions and inheritance.

  • : public Base
  • virtual / override
  • dynamic dispatch
  • virtual ~Base()

07 · Smart Pointers

Modern and secure dynamic memory management without leaks thanks to intelligent standard library pointers.

  • std::unique_ptr
  • std::make_unique
  • std::shared_ptr
  • std::weak_ptr

08 · Templates

Introduce generic programming by writing reusable functions and classes that are independent of data types.

  • template <typename T>
  • class Box<T>
  • CTAD
  • constexpr

09 · Move Semantics, Lambda and STL Modern

Zero out useless copies with rvalue references (&&), express inline logic with lambda and compose pipeline STL / C++20 ranges.

  • T&& / std::move
  • [=](int x){}
  • std::ranges
  • string_view / span

10 · Modern Error Handling and Competition

Model absence and errors at the type level (optional, variant, exceptions RAII) and write multithreaded code without data races.

  • std::optional / variant
  • try / catch / RAII
  • std::jthread
  • std::scoped_lock

The Final Challenge, in Five Steps

Bring Modern C++ idioms together across five progressive stages: isEven predicate, in-place mutation via int&, encapsulated Counter class, functional STL + lambda sumPositive, and move-only RAII wrapper SafeHandle.

1 · Boolean Predicate on int

Implement `bool isEven(int n)` applying arithmetic modulo `%` and a clean boolean return expression (Module 1 + Module 2).

Exercise#cpp.boss.e1
Attempts: 0Loading…

Define bool isEven(int n) returning true when n is even and false otherwise.

Loading editor…
Show hint

Write return n % 2 == 0; directly without redundant if/else branches.

Solution available after 3 attempts

2 · In-Place Mutation via int& Reference

Modify the caller variable directly through an lvalue reference `int&` without raw pointer syntax (Module 3).

Exercise#cpp.boss.e2
Attempts: 0Loading…

Define void squareByRef(int& n) that squares n in-place.

Loading editor…
Show hint

Write n = n * n; (or n *= n;) inside the body of squareByRef.

Solution available after 3 attempts

3 · Encapsulated Counter Class

Combine private member `int count`, member initializer list `Counter() : count(0) {}`, and public methods (Module 4).

Exercise#cpp.boss.e3
Attempts: 0Loading…

Complete class Counter with private int count, constructor Counter() : count(0) {}, void increment(), and int getCount().

Loading editor…
Show hint

Add Counter() : count(0) {}, void increment() { count++; }, and int getCount() { return count; }.

Solution available after 3 attempts

4 · STL <numeric> + Lambda Pipeline

Selectively sum positive integers from `const std::vector<int>&` by passing a lambda closure into `std::accumulate` (Module 5 + Module 9).

Exercise#cpp.boss.e4
Attempts: 0Loading…

Implement int sumPositive(const std::vector<int>& nums) using std::accumulate with a lambda [](int acc, int x) summing only values where x > 0.

Loading editor…
Show hint

Return std::accumulate(nums.begin(), nums.end(), 0, [](int acc, int x) { return x > 0 ? acc + x : acc; });.

Solution available after 3 attempts

5 · Move-Only RAII Wrapper SafeHandle

Unite exclusive ownership `std::unique_ptr<int>`, deleted copy, defaulted move, and safe `std::optional<int>` access (Module 7 + Module 9 + Module 10).

Exercise#cpp.boss.e5
Attempts: 0Loading…

Complete class SafeHandle with std::unique_ptr<int> ptr, explicit SafeHandle(int value) using std::make_unique<int>(value), deleted copy (= delete), defaulted move (= default), and std::optional<int> read() const returning std::nullopt when empty.

Loading editor…
Show hint

Check if (!ptr) return std::nullopt; return *ptr; inside read(), delete copy with SafeHandle(const SafeHandle&) = delete;, and keep SafeHandle(SafeHandle&&) = default;.

Solution available after 3 attempts

Printable C++ Cheatsheet (10 sections)

Complete quick reference covering basics, pointers, OOP, smart pointers, templates, move semantics, STL ranges, and std::jthread concurrency.

Open cheatsheet

What now?

Consolidate your C++20 skills locally with strict warnings (`-Wall -Wextra -std=c++20`) or experiment with pointer, move, and RAII scenarios inside the interactive Playground.