You are on page 1of 28

OOPS Through C++

UNIT-I

September 7, 2022

OOPS Through C++UNIT-I September 7, 2022 1 / 28


Outline

1 Why C++?
2 C++ for Competitive Programming
3 Difference between C and C++
4 Evolution of C++
5 Programming Paradigms
Monolithic Programming
Structured Programming
object oriented paradigm
6 OOPS Concepts
7 Advantages of OOP
8 Usage of OOP

OOPS Through C++UNIT-I September 7, 2022 2 / 28


Why C++?

Why C++?

Highly portable language and is a language of choice for


multi-device,multi-platform app development
Object Oriented Programming Language includes
classes,inheritance,polymorphism,data abstraction and encapsulation
Has a rich function library
Allows exception handling,function and operator overloading
C++ is a powerful,efficient and fast language.Wide range of
applications GUI applications,3D graphics for games and real-time
mathematical simulations

OOPS Through C++UNIT-I September 7, 2022 3 / 28


C++ for Competitive Programming

C++ for Competitive Programming

C++ is very fast and is evolving language and has many standards
such as C++ 11,14,17. C++ 20 has many new features which solves
problems easily
STL Standard Template Library a collection of C++ templates to
help programmers to handle data structures such as lists,stacks,arrays
etc.It has classes,algorithms helpful for Competitive Programming.
Ease of learning concise in Comparison to java(Python is more
concise and is also becoming popular)
C++ is not only fast but is also efficient.And with respect to java
python it is much faster.

OOPS Through C++UNIT-I September 7, 2022 4 / 28


C++ for Competitive Programming

fast

Source: https://benchmarksgame-
team.pages.debian.net/benchmarksgame/fastest/cpp.html

OOPS Through C++UNIT-I September 7, 2022 5 / 28


Difference between C and C++

Difference between C and C++ I

Table: Difference Between C and C++

C C++
C is a Procedure/function- C++ is driven by a proce-
oriented Language dure/object
Data is not protected in c Data is protected in C++
C uses a top down approach C++ uses a bottom-up ap-
proach
In C we cannot give same One can initialize a number
name to two functions in a of functions with same name
program but with different arguments

OOPS Through C++UNIT-I September 7, 2022 6 / 28


Difference between C and C++

Difference between C and C++ II

C uses printf() and scanf() C++ uses cout and cin ob-
functions to read and write jects for input and output
the data operations
C uses stdio.h for input and C++ uses iosteram.h
output
Constructors and Destruc- Presnt in C++
tors are absent in C
Inline functions are not sup- Inline functions are sup-
ported in C ported in C++

OOPS Through C++UNIT-I September 7, 2022 7 / 28


Difference between C and C++

Difference between C and C++ III

OOPS Through C++UNIT-I September 7, 2022 8 / 28


Evolution of C++

Evolution of C++ I

C++ development started in 1979


Bjarne Stroutstrup worked on Simula
It was the first language to
support OOP
He identified that OOP features
can be used in Software
development but Simula is slow.
After that he worked on C
Language and added OOP
features,initilally called C with
Classes
Features were added so as not
to affect features of C language.

OOPS Through C++UNIT-I September 7, 2022 9 / 28


Evolution of C++

Evolution of C++ II

OOPS Through C++UNIT-I September 7, 2022 10 / 28


Programming Paradigms

Programming Paradigms

Paradigm can also be termed as method to solve some problem or do


some task.
Programming paradigm is an approach to solve problem using some
programming language

OOPS Through C++UNIT-I September 7, 2022 11 / 28


Programming Paradigms Monolithic Programming

Monolithic Programming

The whole program is written in


a single block.
We use the goto statement to
jump from one statement to
another statement.
It uses all data as global data
An
which leads to data insecurity.
There are no flow control
statements like if, switch, for,
and while statement.
There is no concept of data
types.
example of this paradigm is Assembly language.

OOPS Through C++UNIT-I September 7, 2022 12 / 28


Programming Paradigms Structured Programming

Procedural/Structured Programming I

Sometimes known as modular programming


Programs written are more efficient and easier to understand and
modify.
It makes use of a top-down design model
Large size programs can be developed in structured programming
such as Pascal and C. Programs are divided in multiple sub-modules
The control of program can be transferred using unsafe goto
statement.
It also provides flow control statements that provide more control to
the user.

OOPS Through C++UNIT-I September 7, 2022 13 / 28


Programming Paradigms Structured Programming

Procedural/Structured Programming II

Different sub-programs
accessing the same global data.
Here also the programmer can
observe the lack of secrecy.
In this programming languages
permit data transfer through
messages by means of function.
Used for developing
medium-sized software
applications.
It is difficult to implement
simultaneous
processes/parallelization.

OOPS Through C++UNIT-I September 7, 2022 14 / 28


Programming Paradigms object oriented paradigm

object oriented paradigm

In this paradigm, the whole program is created on the concept of


objects.
In this paradigm, programs are divided into what are known as
objects.
It follows the bottom-up flow of execution.
In this paradigm, data is hidden and cannot be accessed by an
external function.
This paradigm mainly focuses on data rather than functionality.
It introduces concepts like data abstraction, inheritance, and
overloading of functions and operators overloading.

OOPS Through C++UNIT-I September 7, 2022 15 / 28


OOPS Concepts

Key Concepts of Object Oriented Programming

1 Objects
2 Classes
3 Encapsulation
4 Data Abstraction
5 Inheritance
6 Polymorphism
7 Dynamic Binding
8 Message Passing
9 Reusability
10 Delagation
11 Genericity

OOPS Through C++UNIT-I September 7, 2022 16 / 28


OOPS Concepts

Objects & Classes I

Object is physical as well as logical entity where as


class is the only logical entity
Object is an identifiable identity with some characteristics
and behavior
Class is a blueprint representing a group of objects
that share common properties and relationship.

OOPS Through C++UNIT-I September 7, 2022 17 / 28


OOPS Concepts

Data Abstraction

Hiding of data is known as Data Abstraction


It refers to the act of representing essential features without
including the background details.
Example: If you are riding a bike then for you it is important to
know how to change the gear and how to handle it.
But what is happening inside and how the engine functions is not of any
importance.

OOPS Through C++UNIT-I September 7, 2022 18 / 28


OOPS Concepts

Encapsulation

It is the process of wrapping of data and methods in a single unit.


Encapsulation also lead to data abstraction or hiding.

The data is not directly accessible to outside world


it can be accessed only through member functions.
Encapsulation is the way to implement abstraction.

OOPS Through C++UNIT-I September 7, 2022 19 / 28


OOPS Concepts

Inheritance

It is the process of creating new


class
from existing class.
New classes inherit
some of the properties and
behavior of the
existing classes.
An existing class that
is ”parent” of a
new class
is called a base class

OOPS Through C++UNIT-I September 7, 2022 20 / 28


OOPS Concepts

Polymorphism

The word polymorphism means having many forms


Example: A real-life example of polymorphism is a person who at the
same time can have different characteristics. Like a man at the same time
is a father, a husband and an employee. So the same person exhibits
different behavior in different situations. This is called polymorphism.

OOPS Through C++UNIT-I September 7, 2022 21 / 28


OOPS Concepts

Dynamic Binding

The general meaning of binding is linking something to a thing.


Here linking of objects is done. In a programming sense, we can
describe binding as linking function definition with the function call.
Compiler match a function call with the correct function definition at
runtime; this is called dynamic binding.

OOPS Through C++UNIT-I September 7, 2022 22 / 28


OOPS Concepts

Message Passing

Objects communicate with one another by sending and receiving


information to each other.
Message passing involves specifying the name of the object, the name of
the function and the information to be sent.

OOPS Through C++UNIT-I September 7, 2022 23 / 28


OOPS Concepts

Reusability

Creating new classes by reusing the properties of the existing ones.

Figure: Reusability

OOPS Through C++UNIT-I September 7, 2022 24 / 28


OOPS Concepts

Delegation
Delegation means using the object of another class as a class member of
another class.

Figure: Delegation

OOPS Through C++UNIT-I September 7, 2022 25 / 28


OOPS Concepts

Genericity

Generic Programming enables the programmer to write a general


algorithm which will work with all data types. It eliminates the need to
create different algorithms if the data type is an integer, string or a
character.
Generics can be implemented in C++ using Templates.

OOPS Through C++UNIT-I September 7, 2022 26 / 28


Advantages of OOP

Advantages of OOP

Through inheritance we can eliminate code and extend the use of


existing classes
Re-usability
Easy to Understand
Models the real world well
The principal of data hiding helps the programmer to buils secure
programs
Software Complexity can be easily managed
It is easy to partition work in a project based on object
Object-oriented system can be easily upgraded from small to large
system.

OOPS Through C++UNIT-I September 7, 2022 27 / 28


Usage of OOP

Usage of OOP

Following are the areas for which OOP is considered


1 Simulation
2 Object Oriented DBMS
3 Office automation Software
4 Artificial Intelligence and Expert Systems
5 CAD/CAM Software
6 Network Programming and Internet Applications
7 System Software

OOPS Through C++UNIT-I September 7, 2022 28 / 28

You might also like