Chuyển đến nội dung chính

End of the C++ Course

Summary and final challenge

Congratulations: you have made it through the 4 modules of the C++ Course — from your very first variables and I/O streams to classes and private member encapsulation. Below is a map of everything you have mastered and a three-step final challenge.

Reminder: C++ exercises are verified statically (keywords). To actually run the code, each exercise provides a Compiler Explorer button that copies the code and opens godbolt.org.

01 · Fundamentals

  • variables
  • data types
  • operators
  • std::cout
  • std::cin

02 · Control flow

  • if / else if / else
  • for / while / do-while loops
  • switch

03 · Functions and References

  • declaration/definition
  • return type
  • pass-by-value
  • references &

04 · OOP

  • class
  • private / public
  • constructors
  • destructors

The final challenge, in three steps

Combine what you have learned about C++ by building three small logical components: a boolean checker, an in-place modification using pass-by-reference, and a class that encapsulates a count value.

1 · Even/odd check

Write a function that accepts an integer and returns true if it is even, false otherwise. Module 1 (operators) + Module 3 (functions).

tập thể dục#cpp.boss.e1
Nỗ lực: 0Đang tải…

Define the function isEven(int n) that returns a boolean value indicating if the passed number is even (n % 2 == 0).

Đang tải trình chỉnh sửa…
Hiển thị gợi ý

Use the bool return type and the modulo operator (%). Example: return n % 2 == 0;

Giải pháp khả dụng sau 3 lần thử

2 · Double and square by reference

Write a function that receives a reference to an integer and squares it directly in the original variable. Module 3 (pass-by-reference).

tập thể dục#cpp.boss.e2
Nỗ lực: 0Đang tải…

Define the function squareByRef(int& n) that accepts a reference to an integer and calculates its square in-place, modifying the passed variable.

Đang tải trình chỉnh sửa…
Hiển thị gợi ý

Use void as the return type and int& as the parameter type. Inside the function, write n = n * n;

Giải pháp khả dụng sau 3 lần thử

3 · Encapsulated Counter Class

Create a class that tracks an incrementable numerical value and provides safe methods to access and modify it. Module 4 (classes and constructors).

tập thể dục#cpp.boss.e3
Nỗ lực: 0Đang tải…

Add a constructor to the provided Counter class that initializes the private count variable to 0, a public void increment() method that increases count by 1, and a public int getCount() method that returns the current value of count.

Đang tải trình chỉnh sửa…
Hiển thị gợi ý

Declare the Counter() constructor and the increment() and getCount() methods inside the public section.

Giải pháp khả dụng sau 3 lần thử

Printable Cheatsheet

A single page with all the essential syntax of modern C++, ready to keep handy while you code.

Open the cheatsheet

What now?

Consistent practice is the best way to strengthen your skills. Open the C++ Playground to experiment freely with complex scenarios or to prepare your code snippets before testing them on a real compiler.