SlideShare a Scribd company logo
OOPs with C++
Ms. Sudhriti Sengupta
&
Dr. Lavanya Sharma
OOPS
Object-Oriented Programming or OOPs refers to
languages that uses objects in programming.
Object-oriented programming aims to
implement real-world entities like inheritance,
hiding, polymorphism etc in programming. The
main aim of OOP is to bind together the data
and the functions that operate on them so that
no other part of the code can access this data
except that function.
Principle of OOPS
• Object
This is the basic unit of object oriented
programming. That is both data and function that
operate on data are bundled as a unit called as
object.
• Class
When you define a class, you define a blueprint for
an object. This doesn't actually define any data, but
it does define what the class name means, that is,
what an object of the class will consist of and what
operations can be performed on such an object.
• Abstraction
Data abstraction refers to, providing only essential
information to the outside world and hiding their
background details, i.e., to represent the needed
information in program without presenting the details.
For example, a database system hides certain details of
how data is stored and created and maintained. Similar
way, C++ classes provides different methods to the
outside world without giving internal detail about those
methods and data.
Encapsulation
Encapsulation is placing the data and the
functions that work on that data in the same
place. While working with procedural languages,
it is not always clear which functions work on
which variables but object-oriented
programming provides you framework to place
the data and the relevant functions together in
the same object.
Inheritance
One of the most useful aspects of object-
oriented programming is code reusability. As the
name suggests Inheritance is the process of
forming a new class from an existing class that is
from the existing class called as base class, new
class is formed called as derived class.
This is a very important concept of object-
oriented programming since this feature helps
to reduce the code size.
Important terminology:Inheritance
•
Super Class: The class whose features are inherited is
known as superclass(or a base class or a parent class).
• Sub Class: The class that inherits the other class is known
as subclass(or a derived class, extended class, or child
class). The subclass can add its own fields and methods in
addition to the superclass fields and methods.
• 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.
Polymorphism
The ability to use an operator or function in
different ways in other words giving different
meaning or functions to the operators or
functions is called polymorphism. Poly refers to
many. That is a single function or an operator
functioning in many ways different upon the
usage is called polymorphism.
Introduction to C++
C++ is a middle-level programming language
developed by Bjarne Stroustrup starting in 1979
at Bell Labs. C++ runs on a variety of platforms,
such as Windows, Mac OS, and the various
versions of UNIX.
Use of C++
• C++ is used by hundreds of thousands of programmers
in essentially every application domain.
• C++ is being highly used to write device drivers and
other software that rely on direct manipulation of
hardware under realtime constraints.
• C++ is widely used for teaching and research because it
is clean enough for successful teaching of basic
concepts.
• Anyone who has used either an Apple Macintosh or a
PC running Windows has indirectly used C++ because
the primary user interfaces of these systems are
written in C++.
Points to NOTE
• C++ is a statically typed, compiled, general-
purpose, case-sensitive, free-form programming
language that supports procedural, object-
oriented, and generic programming.
• 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 superset of C, and that virtually any legal
C program is a legal C++ program.
Polymorhpism
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.
Real life example of polymorphism, a person at the
same time can have different characteristic. Like a lady at
the same time is a mother, a daughter, a teacher etc . So
the same person posses different behavior in different
situations. This is called polymorphism.
Polymorphism is considered as one of the important
features of Object Oriented Programming.
• Compile time polymorphism: The overloaded
functions are invoked by matching the type
and number of arguments. This information is
available at the compile time and, therefore,
compiler selects the appropriate function at
the compile time. It is achieved by function
overloading and operator overloading which is
also known as static binding or early binding.
Now, let's consider the case where function
name and prototype is same.
Compile time polymorphism: This type of
polymorphism is achieved by function
overloading or operator overloading.
Function Overloading: When there are multiple
functions with same name but different
parameters then these functions are said to
be overloaded. Functions can be overloaded
by change in number of
arguments or/and change in type of arguments.
Operator Overloading: C++ also provide option
to overload operators. For example, we can
make the operator (‘+’) for string class to
concatenate two strings. We know that this is
the addition operator whose task is to add two
operands. So a single operator ‘+’ when placed
between integer operands , adds them and
when placed between string operands,
concatenates them.
• Run time polymorphism: Run time
polymorphism is achieved when the object's
method is invoked at the run time instead of
compile time. It is achieved by method
overriding which is also known as dynamic
binding or late binding.
Runtime polymorphism: This type of
polymorphism is achieved by Function
Overriding.Function overriding on the other
hand occurs when a derived class has a
definition for one of the member functions of
the base class. That base function is said to
be overridden.
Compile time polymorphism Run time polymorphism
The function to be invoked is
known at the compile time.
The function to be invoked is
known at the run time.
It is also known as overloading,
early binding and static binding.
It is also known as overriding,
Dynamic binding and late binding.
Overloading is a compile time
polymorphism where more than
one method is having the same
name but with the different
number of parameters or the type
of the parameters.
Overriding is a run time
polymorphism where more than
one method is having the same
name, number of parameters and
the type of the parameters.
It is achieved by function
overloading and operator
overloading.
It is achieved by virtual functions
and pointers.
It provides fast execution as it is
known at the compile time.
It provides slow execution as it is
known at the run time.
It is less flexible as mainly all the
things execute at the compile
time.
It is more flexible as all the things
execute at the run time.
Simple program for function
overloading
• // Program to compute absolute value
• // Works both for integer and float
• #include <iostream>
• using namespace std;
• int absolute(int);
• float absolute(float);
• int main() {
• int a = -5;
• float b = 5.5;
•
• cout << "Absolute value of " << a << " = " << absolute(a) << endl;
• cout << "Absolute value of " << b << " = " << absolute(b);
• return 0;
• }
• int absolute(int var) {
• if (var < 0)
• var = -var;
• return var;
• }
• float absolute(float var){
• if (var < 0.0)
• var = -var;
• return var;
• }

More Related Content

What's hot

C++vs java
C++vs javaC++vs java
C++vs java
Pradeep wolf king
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
Ranel Padon
 
C++ to java
C++ to javaC++ to java
C++ to java
Ajmal Ak
 
Python programming
Python programmingPython programming
Python programming
Prof. Dr. K. Adisesha
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
KurdGul
 
Object Oriented Programming lecture 1
Object Oriented Programming lecture 1Object Oriented Programming lecture 1
Object Oriented Programming lecture 1Anwar Ul Haq
 
Python Programming - I. Introduction
Python Programming - I. IntroductionPython Programming - I. Introduction
Python Programming - I. Introduction
Ranel Padon
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
Umesh Nikam
 
Programming
ProgrammingProgramming
Programming
monishagoyal4
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
Abdul Hannan
 
What is Python? An overview of Python for science.
What is Python? An overview of Python for science.What is Python? An overview of Python for science.
What is Python? An overview of Python for science.
Nicholas Pringle
 
Object oriented concepts ppt
Object oriented concepts pptObject oriented concepts ppt
Object oriented concepts ppt
Prof. Dr. K. Adisesha
 
Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming Paradigms
Directi Group
 
Type hints in python & mypy
Type hints in python & mypyType hints in python & mypy
Type hints in python & mypy
Anirudh
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
MOHIT DADU
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
Haim Michael
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
Sagar Pednekar
 

What's hot (19)

C++vs java
C++vs javaC++vs java
C++vs java
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
 
C++ to java
C++ to javaC++ to java
C++ to java
 
Python programming
Python programmingPython programming
Python programming
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Object Oriented Programming lecture 1
Object Oriented Programming lecture 1Object Oriented Programming lecture 1
Object Oriented Programming lecture 1
 
Python Programming - I. Introduction
Python Programming - I. IntroductionPython Programming - I. Introduction
Python Programming - I. Introduction
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Programming
ProgrammingProgramming
Programming
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
What is Python? An overview of Python for science.
What is Python? An overview of Python for science.What is Python? An overview of Python for science.
What is Python? An overview of Python for science.
 
Object oriented concepts ppt
Object oriented concepts pptObject oriented concepts ppt
Object oriented concepts ppt
 
Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming Paradigms
 
Type hints in python & mypy
Type hints in python & mypyType hints in python & mypy
Type hints in python & mypy
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 

Similar to C++ first s lide

The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Object oriented programing
Object oriented programingObject oriented programing
Object oriented programing
Jamaluddin Malakzai
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
Amresh Raj
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
Amar Jukuntla
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
Shipra Swati
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
KAUSHAL KUMAR JHA
 
c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
PadmaN24
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroduction
Rai University
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals
umesh patil
 
Mca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroductionMca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroduction
Rai University
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Languagedheva B
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
SamuelAnsong6
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
Mohamed Essam
 

Similar to C++ first s lide (20)

The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
Object oriented programing
Object oriented programingObject oriented programing
Object oriented programing
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
M.c.a (sem iii) paper - i - object oriented programming
M.c.a (sem   iii) paper - i - object oriented programmingM.c.a (sem   iii) paper - i - object oriented programming
M.c.a (sem iii) paper - i - object oriented programming
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroduction
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals
 
Mca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroductionMca 2 sem u-1 iintroduction
Mca 2 sem u-1 iintroduction
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
My c++
My c++My c++
My c++
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 

C++ first s lide

  • 1. OOPs with C++ Ms. Sudhriti Sengupta & Dr. Lavanya Sharma
  • 2. OOPS Object-Oriented Programming or OOPs refers to languages that uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
  • 3.
  • 4. Principle of OOPS • Object This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object. • Class When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.
  • 5. • Abstraction Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details. For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides different methods to the outside world without giving internal detail about those methods and data.
  • 6.
  • 7. Encapsulation Encapsulation is placing the data and the functions that work on that data in the same place. While working with procedural languages, it is not always clear which functions work on which variables but object-oriented programming provides you framework to place the data and the relevant functions together in the same object.
  • 8.
  • 9. Inheritance One of the most useful aspects of object- oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class. This is a very important concept of object- oriented programming since this feature helps to reduce the code size.
  • 10. Important terminology:Inheritance • Super Class: The class whose features are inherited is known as superclass(or a base class or a parent class). • Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods. • 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.
  • 11.
  • 12. Polymorphism The ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers to many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism.
  • 13.
  • 14. Introduction to C++ C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
  • 15. Use of C++ • C++ is used by hundreds of thousands of programmers in essentially every application domain. • C++ is being highly used to write device drivers and other software that rely on direct manipulation of hardware under realtime constraints. • C++ is widely used for teaching and research because it is clean enough for successful teaching of basic concepts. • Anyone who has used either an Apple Macintosh or a PC running Windows has indirectly used C++ because the primary user interfaces of these systems are written in C++.
  • 16. Points to NOTE • C++ is a statically typed, compiled, general- purpose, case-sensitive, free-form programming language that supports procedural, object- oriented, and generic programming. • 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 superset of C, and that virtually any legal C program is a legal C++ program.
  • 18. 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. Real life example of polymorphism, a person at the same time can have different characteristic. Like a lady at the same time is a mother, a daughter, a teacher etc . So the same person posses different behavior in different situations. This is called polymorphism. Polymorphism is considered as one of the important features of Object Oriented Programming.
  • 19.
  • 20. • Compile time polymorphism: The overloaded functions are invoked by matching the type and number of arguments. This information is available at the compile time and, therefore, compiler selects the appropriate function at the compile time. It is achieved by function overloading and operator overloading which is also known as static binding or early binding. Now, let's consider the case where function name and prototype is same.
  • 21. Compile time polymorphism: This type of polymorphism is achieved by function overloading or operator overloading. Function Overloading: When there are multiple functions with same name but different parameters then these functions are said to be overloaded. Functions can be overloaded by change in number of arguments or/and change in type of arguments.
  • 22. Operator Overloading: C++ also provide option to overload operators. For example, we can make the operator (‘+’) for string class to concatenate two strings. We know that this is the addition operator whose task is to add two operands. So a single operator ‘+’ when placed between integer operands , adds them and when placed between string operands, concatenates them.
  • 23. • Run time polymorphism: Run time polymorphism is achieved when the object's method is invoked at the run time instead of compile time. It is achieved by method overriding which is also known as dynamic binding or late binding.
  • 24. Runtime polymorphism: This type of polymorphism is achieved by Function Overriding.Function overriding on the other hand occurs when a derived class has a definition for one of the member functions of the base class. That base function is said to be overridden.
  • 25. Compile time polymorphism Run time polymorphism The function to be invoked is known at the compile time. The function to be invoked is known at the run time. It is also known as overloading, early binding and static binding. It is also known as overriding, Dynamic binding and late binding. Overloading is a compile time polymorphism where more than one method is having the same name but with the different number of parameters or the type of the parameters. Overriding is a run time polymorphism where more than one method is having the same name, number of parameters and the type of the parameters. It is achieved by function overloading and operator overloading. It is achieved by virtual functions and pointers. It provides fast execution as it is known at the compile time. It provides slow execution as it is known at the run time. It is less flexible as mainly all the things execute at the compile time. It is more flexible as all the things execute at the run time.
  • 26. Simple program for function overloading • // Program to compute absolute value • // Works both for integer and float • #include <iostream> • using namespace std; • int absolute(int); • float absolute(float); • int main() { • int a = -5; • float b = 5.5; • • cout << "Absolute value of " << a << " = " << absolute(a) << endl; • cout << "Absolute value of " << b << " = " << absolute(b); • return 0; • } • int absolute(int var) { • if (var < 0) • var = -var; • return var; • } • float absolute(float var){ • if (var < 0.0) • var = -var; • return var; • }