Posts

Standard Template Library – Iterators

                You have a container with elements. How will you access it?? You need a hand to pick it up… Here, iterator is the thing which access the elements of a container. Features: It traverses the container and hides the internal structure. It supports find(),sort() and count() algorithms . It access the data as input,output. It can traverse in both forward and bidirectional. To access it, use container_type::iterator name. Let us create a c++ program to illustrate the iterators. #include <iostream> #include < vector > using namespace std; int main() {     vector<int> v1 = {100,120,330,440,550};     // let us traverse the vector using iterator     for (vector<int>::iterator i1 = v1.begin(); i1 != v1.end(); ++i1)         cout << *i1 << " ";     return 0; } Output: 100 12...

Standard Template Library- Containers

                 This is the built-in implementation of data structures named as containers. It is an object which holds the collection of other elements. Generally, it is implemented as template defined as class. Main advantage is flexibility. Types of containers can be classified as follows. 1.       Associative containers 2.       Unordered associative containers 3.       Container adapter 4.       Sequence containers The built-in functions connected with each container are explained below. 1.Associative containers:               From the name itself, we can know. Association means the data storage have some connectivity. It makes the access faster. So, the time is efficient here. It has the following containers. Map -    Here, the value and key...

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...