Posts

Showing posts from 2025

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

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

OOPS Concepts in C++

                OOP – Object Oriented Programming . It is a programming approach which deals with objects and classes . It creates reusable code to achieve modularity . Why OOPs concepts? It makes the code modular. The code can be reusable any times. It is scalable. It gives you security from unauthorized access. OOPs concepts: The concepts are listed below. Class Object Abstraction Encapsulation Polymorphism Inheritance Each one of the concepts are explained with code as follows… 1.Class:               It is a prototype from which the object are created. It has a collection of variables and methods.you can create multiple objects for single class. The class has following components. Class Components: Class name: Name of the class. Access specifiers: private, public and protected Methods: it defines the functionalities. Variables: it deals with val...

User defined data types in c++(Structure and Union)

                 Basically, the data types are categorised into two types. One is the primitive data types supported by programming language. Another one is user defined datatypes which is created by the user. Some the user defined datatypes in c++ are given below. ·        Structures ·        Unions Let us implement each one of this. Structures:               It is one of the user defined data types in c++, which has collection of members of different datatypes. Syntax: Creating a structure:   Structure structure_name {                 Data type data_member1;                 Data type data_member2;        ...