Coupon Accepted Successfully!




The object-oriented programming (OOP) is a different approach to programming. Object oriented technology supported by C++ is considered the latest technology in software development.

Basic Concepts


When a program is executed, the objects interact by sending messages to one another. For example, if ‘customer’ and ‘account’ are two objects in a program, then the customer object may send message to account object requesting for a bank balance. Each object contains data and code to manipulate data. Objects can interact without having to know details of each other’s data or code. It is sufficient to know the type of massage accepted and the type of response returned by the objects.


We have just mentioned that objects contain data and function or code to manipulate that data. The entire set of data and code of an object can be made a user-defined data type with the help of a class. In fact objects are variables of type class. Once a class has been defined, we can create any number of objects associated with that class. For example, mango, apple and orange are members of class fruit. If fruit has been defined as a class, then the statement fruit mango, will create an object mango belonging to the class fruit.

Data Abstraction

Abstraction refers to the act of representing essential features without including the background details. To understand this concept more clearly, take an example of ‘switch board’. You only press particular switches as per your requirement. You need not know the internal working of these switches. What is happening inside is hidden from you. This is abstraction, where you only know the essential things to operate on switch board without knowing the background details of switch board.

Data Encapsulation

Encapsulation is the most basic concept of OOP. It is the way of combining both data and the functions that operate on that data under a single unit. The only way to access the data is provided by the functions (that are combined along with the data). These functions are considered as member functions in C++. It is not possible to access the data directly. If you want to reach the data item in an object, you call a member function in the object. It will read the data item and return the value to you. The data is hidden, so it is considered as safe and far away from accidental alternation. Data and its functions are said to be encapsulated into a single entity.


The act of partitioning a program into individual components is called modularity. It gives the following benefits.

  • It reduces its complexity to some extent.
  • It creates a number of well-defined, documented boundaries within the program.


It is the capability to define a new class in terms of an existing class. An existing class is known as a base class and the new class is known as derived class.

C++ supports such hierarchical classification of classes. The main benefit from inheritance is that we can build a generic base class, i.e., obtain a new class by adding some new features to an existing class and so on. Every new class defined in that way consists of features of both the classes. Inheritance allows existing classes to be adapted to new application without the need for modification.


Polymorphism is a key to the power of OOP. It is the concept that supports the capability of data to be processed in more than one form. For example, an operation may exhibit different behaviour in different instances. The behaviour depends upon the types of data used in the operation.

The major benefits are :

  • Software complexity can be easily managed
  • Object-oriented systems can be easily upgraded
  • It is quite easy to partition the work in a project based on objects.

Linked Lists

The link is a pointer to the same type of structure

struct Node


int data ;

struct Node *next ;


This is called a self-referential pointer


Uses and Operations on Linked Lists

Linear linked list: last element is not connected to anything

Circular linked list: last element is connected to the first

Dynamic: Size of a linked list grows or shrinks during the execution of a program and is just right

Advantage: It provides flexibility in inserting and deleting elements by just re-arranging the links

Disadvantage: Accessing a particular element is not easy There are three major operations on linked lists

  1. Insertion
  2. Deletion
  3. Searching

Insertion at the beginning of the list

Create a new node (say q)

Make q->next point to head

Make head equal to q

list is empty, i.e., head is NULL

Make head equal to q


Insertion at end of list

Create a new node (say q)

Find the last element (say p)

Make p->next point to q

if list is empty, i.e., head is NULL

Make head equal to q

Deletion at the beginning of the list

Make p equal to head

Make head equal to head->next

Delete p (by using free)

If list is empty, i.e., head is NULL

Nothing to do

If list contains only one element

Delete head

head is now NULL


Deletion from the end of the list

Find the last element (say p)

While finding p, maintain q that points to p

q is the node just before p, i.e., q->next is p

Make q->next NULL

Delete p (by using free)

If list is empty, i.e., head is NULL

Nothing to do

If list contains only one element

Delete head

head is now NULL


Searching a node (insert after, delete after)

Make p equal to head

While p->data not equal to the data that is being searched,

make p equal to p->next

Using search, insert after and delete after operations can be


Insert after p

Create a new node q

Make q->next equal to p->next

Make p->next equal to q



Delete after p

Call the next node, i.e., p->next as q

Make p->next equal to q->next

Delete q

Test Your Skills Now!
Take a Quiz now
Reviewer Name