Fading Coder

One Final Commit for the Last Sprint

Polygon Perimeter Calculation via Inheritance

Givan the base class framework for polygons: class polygon { protected: int number; // Number of sides, at most 100 private: int side_length[100]; // Array of side lengths public: polygon(); // Constructor can be overloaded as needed int perimeter(); // Calculate polygon perimeter void display(); //...

Dynamic Programming for Maximum Stock Profit: Single and Multiple Transactions

Valid for a single buy-sell cycle The problem asks for the maximum possible profit from one purchase and one sale. A dynamic programming approach tracks two states for each day: cash_with_stock[i]: the largest amount of cash achievable on day i while holding the stock. cash_without_stock[i]: the lar...

Understanding Classes, Objects, and Member Functions in C++

In C++, a class keyword is used to define a blueprint for creating objects. The class name follows the class keyword, and the class body is enclosed in curly braces {}. A semicolon ; must terminate the class definition. Elements within the class body are called members. Variables declared inside a c...

Singleton Pattern Implementation in C++

Singleton Pattern Fundamentals The Singleton pattern ensures a class has only one global instance while providing controlled access to it. This pattern is suitable for scenarios requiring centralized management of shared resources or global configuration settings. Lazy Initialization Approach class...

Implementing the Prototype Pattern in C++: Shallow vs. Deep Copying

The Prototype patern is a creational design pattern used to create new objects by copying an existing instance, known as the prototype. In C++, this is typically achieved through copy constructors. When dealing with classes that manage dynamic memory, it is crucial to understand the distinction betw...

Working with Annotations and Decorative Items in QCustomPlot

What are Abstract Items? When visualizing data, we often focus on the primary graph types like bar charts, pie charts, or splines. However, a chart's effectiveness relies heavily on auxiliary elements that provide context, such as axes, grid lines, legends, and annotations. In QCustomPlot, these sup...

Function Templates in C++: Syntax, Invocation, and Overload Resolution

Function templates enable writing generic algorithms that operate on different data types without sacrificing type safety. A template declaration begins with the template keyword followed by a list of template parameters enclosed in angle brackets. template<typename T> void Exchange(T& fir...

Implementing Client-Side Operations for a Cluster Chat Server

A command table is defined to map available operations to thier usage syntax for user assistance. unordered_map<string, string> AvailableCommands{ {"help", "Show all available commands. Format: help"}, {"chat", "Private messaging. Format: chat:recipient_id:me...

SMU Summer 2023 Contest Round 7 Solutions

A. Two Rival Students The maximum possible dsitance between two students in a line of n positions is n - 1. Given their initial positions a and b, and up to x swaps, the achievable distance is the minimum of n - 1 and |a - b| + x. #include <bits/stdc++.h> using namespace std; int main() { ios:...

Implementing 2D Image Transformations in Qt

Scaling Operations To implement image scaling, define slots in your header file to handle the logic: protected slots: void zoomInImage(); void zoomOutImage(); Connect these slots to your UI actions within the createActions() function: connect(zoomInAction, &QAction::triggered, this, &ImgProc...