Fading Coder

One Final Commit for the Last Sprint

Understanding the static and const Keywords in C/C++

static The static keyword, when used to declare a varible, places that variable in the global (static) storage area. Initialized and uninitialized static variables are stored in separate regions within this area. If a static variable is not explicitly initialized, it is automatically initialized to...

Class Composition, Inheritance, Template Classes, and Standard Library in C++

Task 1 task1.cpp #include <iostream> using std::cout; using std::endl; class A { public: A(int x0, int y0); void display() const; private: int x, y; }; A::A(int x0, int y0) : x{x0}, y{y0} {} void A::display() const { cout << x << ", " << y << endl; } class B {...

Implementing Factory and Abstract Factory Patterns in C++

Introduction to Creational Patterns In application architecture, creational patterns address object initialization mechanisms. Two prominent variations are the Factory Method and Abstract Factory patterns. These approaches encapsulate instantiation logic, allowing systems to remain flexible and adhe...

Memory Management in C++: new and delete

Memory Management in C++: new and delete
Introduction In my blog about C language, there is also an article about dynamic memory management. If you are interested, you can check it out: C Language - Dynamic Memory Management. You should be familiar with this diagram: If you have read my previous blog on Linux process virtual address space,...

Understanding Polymorphism and Virtual Functions in C++

Polymorphism allows objects of differant classes to be treated as objects of a common base class, enabling a single interface to invoke different behaviors. In C++, polymorphism is categorized into compile-time and runtime types. Compile-time polymorphism, or static binding, includes function overlo...

LeetCode Weekly Contest 356 Solutions

Counting Employees Meeting Target Hours This problem requires counting employees whose work hours meet or exceed a target value. A simple linear scan suffices. class Solution { public: int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) { int count = 0; for (int h : hours) {...

Understanding Signals and Slots in Qt C++ Development

In Qt, each interaction between a user and a widget is considered an event, such as clicking a button or closing a window. These events emit signals, like a button-click signal or a window-close signal. Widgets in Qt can receive multiple signals and respond with specific actions, known as slots, whi...

C++ Reference, Const Qualifier, Memory Management, and Function Features

1 Reference Concepts 1.0 Fundamentals References must be initialized to a varible upon declaration. References can only bind to variables, not expressions or constants. 1.1 Variable References int a = 0; int& ref = a; // ref is of type int& ref becomes an alias for a; operations on ref direc...

C++ Const and Mutable Modifiers Explained

Understanding C++ Const and Mutable Modifiers In C++, the const keyword is used to declare constants or immutable values. It can be applied to variables, pointers, function parameters, member functions, and more. Using const enhances code safety and readability by preventing accidental modifications...

Dynamic Programming Essentials: Knapsack Variants and State Transitions

Understanding Problem Types in Dynamic Programming Dynamic programming problems often involve defining states and transitioning between them. Common types include: Knapsack Problems Linear DP Interval DP State Compression DP Tree DP Counting Problems Digit-based DP State Compression Memorized Search...