BCA I Year, II Semester
Online Notes for the Subject – Programming in C++
TOPIC NAME – INTRO TO C++ & OOPS CONCEPT
C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray
Hill, New Jersey, as an enhancement to the C language and originally named C
with Classes but later it was renamed C++ in 1983.
C++ is a case-sensitive that supports object-oriented and generic programming.
It was develop for adding a feature of OOP (Object Oriented Programming) in
C without significantly changing the C component.
C++ is regarded as a middle-level language, as it comprises a combination of both
high-level and low-level language features.
C++ is a cross-platform language that can be used to create high-performance
applications.
C++ gives programmers a high level of control over system resources and memory.
Why Use C++ ?
C++ is one of the world's most popular programming languages.
C++ can be found in today's operating systems, Graphical User Interfaces, and
embedded systems.
C++ is an object-oriented programming language which gives a clear structure to
programs and allows code to be reused, lowering development costs.
C++ is portable and can be used to develop applications that can be adapted to
multiple platforms.
C++ is fun and easy to learn!
As C++ is close to C# and Java, it makes it easy for programmers to switch to
C++ or vice versa.
OOPs Concept
The major purpose of C++ programming is to introduce the concept of object
orientation to the C programming language.
Object Oriented Programming is a paradigm that provides many concepts such
as inheritance, data binding, polymorphism etc.
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
Object:
An Object is an identifiable entity with some characteristics and behaviour.
An Object is an instance of a Class.
When a class is defined, no memory is allocated but when it is instantiated (i.e. an
object is created) memory is allocated.
When a program is executed the objects interact by sending messages to one
another.
Each object contains data and code to manipulate the data.
Objects can interact without having to know details of each other’s data or code, it
is sufficient to know the type of message accepted and type of response returned
by the objects.
Class:
The building block of C++ that leads to Object-Oriented programming is a Class.
It is a user-defined data type, which holds its own data members and member
functions, which can be accessed and used by creating an instance of that class.
A Class is a user-defined data-type which has data members and member
functions.
Data members are the data variables and member functions are the functions
used to manipulate these variables and together these data members and
member functions define the properties and behaviour of the objects in a
Class.
Encapsulation:
In normal terms, Encapsulation is defined as wrapping up of data and information
under a single unit.
In Object-Oriented Programming, Encapsulation is defined as binding together the
data and the functions that manipulate them.
Abstraction:
Data abstraction is one of the most essential and important features of object-
oriented programming in C++.
Abstraction means displaying only essential information and hiding the details.
Data abstraction refers to providing only essential information about the data to
the outside world, hiding the background details or implementation.
Polymorphism:
The word polymorphism means having many forms. In simple words, we can
define polymorphism as the ability of a message to be displayed in more than one
form.
A person at the same time can have different characteristic. Like a man at the
same time is a father, a husband, an employee.
So the same person posses different behaviour in different situations. This is
called polymorphism.
An operation may exhibit different behaviours in different instances. The
behaviour depends upon the types of data used in the operation.
C++ supports operator overloading and function overloading.
Operator Overloading:
The process of making an operator to exhibit different behaviour in different
instances is known as operator overloading.
Function Overloading:
Function overloading is using a single function name to perform different
types of tasks.
Polymorphism is extensively used in implementing inheritance.
Inheritance:
The capability of a class to derive properties and characteristics from another class
is called Inheritance.
Inheritance is one of the most important features of Object-Oriented
Programming.
Sub Class: The class that inherits properties from another class is called
Sub class or Derived Class.
Super Class:The class whose properties are inherited by sub class is called
Base Class or Super class.
Reusability: Inheritance supports the concept of “reusability”, i.e. when
we want to create a new class and there is already a class that includes some
of the code that we want, we can derive our new class from the existing
class.
By doing this, we are reusing the fields and methods of the existing class.