Posts

Showing posts from November, 2025

Standard Template Library – Algorithm

                 Algorithms are predefined function to perform a specific functionality. In STL , the built-in header files are <algorithm> and <numeric>. Algorithms can be classified into 4 types based on its functionality. 1.       Sorting algorithms 2.       Searching algorithms . 3.       Manipulation algorithm 4.       Counting and comparing algorithm   Let us discuss about the algorithm in each category. 1.    Sorting algorithms: This is the algorithm which arranges the element in particular order. The functions are given below.     “sort()” : it arranges the elements in particular order.     “nth_element()” : it rearranges the element based on the ‘n’ value.     “is_sorted()”: it checks the given array is sorted or not.     “is...

Standard Template library (STL) in C++

             It has a set of pre-built classes and functions. Data’s need to store in some type data structures like vectors, stacks and maps. If your programming language gives the standard template library, it is efficient to programmers. Features:           STL has lot of benefits as follows… ·       Reusability. ·       Efficiency. ·       Quick to execute. ·       Pre-defined algorithms. What are the components of STL?           It has three types classified as follows. ·       Algorithms ·       Containers ·       Iterators Algorithms:           It has a collection of functions which provides the common operations. ...

Inheritance in C++

            Inheritance is one of the object oriented concepts which deals with methods and attributes . It is the process of getting properties from base class to child class . It has the following features. Reusability of code . Promotes logical hierarchy . Parent child relationships . Key terms: Base class: it is foundation class which has methods and attributes definition. It is also known as “ Parent ” class. Derived class : it gets the details from base class. It is called “ Child ” class. Types of inheritance : The types of inheritance are given below. Single : it has a base class and derived class. Hierarchical : it deals with a base class with multiple derived class. Hybrid : it is a combination of all types. Multiple : a single inherited class with multiple base class. Multilevel : it is a chain of inheritance.(X->Y->Z). Let us create a c++ program to display message using inheritance: This code crea...

Polymorphism in C++ (part 2)

               In the previous blog post, the definition,types and function overloading concepts are included. Here, is the link. https://rajeeva84.blogspot.com/2025/11/polymorphism-in-c.html in this post, operator overloading and run time polymorphism using virtual functions are explained. Operator overloading:               This concept deals with operator. An operator can be overloaded with another definition. For example, “%” is used as two purposes. One is finding ‘ mod ’ functions and another one is ‘ percentage ’. Let us create a c++ program as follows. #include < iostream > using namespace std ; class ModIt {     int m_value; public:     ModIt(int v) : m_value(v) {}        // let us Overload % operator     ModIt operator%(const ModIt& x) const {    ...

Polymorphism in C++

  What is polymorphism?               Poly means ‘Many’. Polymorphism means having more than one form. This concept makes the function can be used in different situations. Let us categories the types. 1.       Compile time Polymorphism 2.       Run time Polymorphism 1.Compile time Polymorphism:               This is a static one, which can be done in the code itself. It occurs in compile time. This can be achieved by two ways. ·        Function overloading ·        Operator overloading Let us create the c++ programs as follows. · Function Overloading:               In short, same function name can be used for different functionalities and different number of...

Encapsulation in C++

                Encapsulation is one of the object oriented programming concepts which binds the data and functions together. It makes the whole thing into a single unit. Generally, this single unit is considered as a class . Encapsulation is achieved by using access specifiers as follows.. ‘ public ’: member variables can be accessible for anywhere in the class. ‘ private ’: this type of variable accessed by current class only. ‘ protected ’: it can be accessible by class and derived class. Let us create a c++ program to display the student details. C++ program: Here, ‘ Student ’ is the class. It has set() method to display the data. The get() method gets the data. Using the object, we call the set() and get() function. Code: #include <iostream> using namespace std; class Student { private: string s_name; string s_id; int s_age; public: // Constructor Student(string s_name,string s_id ,int s_age) { ...

Abstraction in C++

              It is one of the Object oriented programming concepts which is the basic one. It deals with data. Abstraction shows the essential information to the user and hides the internal details. For e.g., when you drive a motor bike, you know about bike moving, but the functionality of engine is not known. This is the abstraction. Types of abstraction:               Abstraction is classified into two types as follows… ·        Data abstraction : it shows only necessary data. ·        Control abstraction : it shows only necessary information. Let us create the c++ program to implement abstraction. Code: #include <iostream> using namespace std; // Abstract class class ShapeEg { public:     // It is a virtual function     virtual void find_area() = 0;  ...