SlideShare a Scribd company logo
OOPS THROUGH C++
Dr. Chandra Sekhar Sanaboina
Assistant Professor
Department of Computer Science and Engineering
University College of Engineering Kakinada
Jawaharlal Nehru Technological University Kakinada
Website: https://drcs.info
Youtube Link:
https://www.youtube.com/watch?v=nPjHraTbPeY&list=PLT1ngltOnlJiHbzVvjkU8VzQt9oam8ji4
UNIT – I
INTRODUCTION TO C++
AGENDA
• Difference between C and C++
• Evolution of C++
• Procedure Oriented Programming vs Object Oriented
Programming
• Key concepts of Object Oriented Programming
• Advantages and Disadvantages of OOP
3
PROCEDURE ORIENTED PROGRAMMING
• It means “a set of procedures” which is a “set of subroutines” or a “set of
functions“
• Functions are called repeatedly in a program to execute tasks performed by them
• Example: A program may involve collecting data from user (reading), performing
some kind of calculations on the collected data (calculation), and finally displaying the
result to the user when requested (printing). All the 3 tasks of reading, calculating and
printing can be written in a program with the help of 3 different functions which
performs these 3 different tasks.
4
A REAL WORLD EXAMPLE
• We are working for a vehicle parts manufacturer that needs to update it's online
inventory system. Boss tells us to program two similar but separate forms for a
website, one form that processes information about cars and one that does the
same for trucks
• For cars, we will need to record the following information:
• Color, Engine Size, Transmission Type, Number of doors
• For trucks, the information will be similar, but slightly different. We need:
• Color, Engine Size, Transmission Type, Cab Size, Towing Capacity
5
SCENARIO - 1
• Suppose that we suddenly need to add a bus form, that records the following
information:
• Color, Engine Size, Transmission Type, Number of passengers
• Procedural –
• We need to recreate the entire form, repeating the code for Color, Engine Size, and
Transmission Type.
• OOP -
• We simply extend the vehicle class with a bus class and add the method
numberOfPassengers
6
SCENARIO - 2
• Instead of storing color in a database like we previously did, for some strange
reason our client wants the color emailed to him
• Procedural –
• We change three different forms: cars, trucks, and buses to email the color to the client
rather than storing it in the database.
• OOP –
• We change the color method in the vehicle class and because the car, truck, and bus
classes all extend (or inherit from, to put it another way) the vehicle class, they are
automatically updated
7
SCENARIO - 3
• We want to move from a generic car to specific makes, for example: Nissan and
Creta
• Procedural –
• We create a new form for each make, repeating all of the code for generic car
information and adding the code specific to each make
• OOP –
• We extend the car class with a Nissan class and a Creta class and add methods for each
set of unique information for that car make
8
SCENARIO - 4
• We found a bug in the transmission type area of our form and need to fix it
• Procedural –
• We open and update each and every form
• OOP –
• We fix the transmission Type method in the vehicle class and the change
perpetuates in every class that inherits from it
9
WHY SWITCH TO C++
• Supports an OO approach to programming
• Classes
• Inheritance
• Polymorphism
• Exceptions
• Provides powerful features on top of a “fast” language
10
HOW TO SWITCH TO C++
1. Learn about differences
a. New tools (compilers, debuggers, etc.)
b. New libraries
c. New file naming conventions
d. New syntax
e. Available standards
2. Rethink programming approach
11
1A. NEW TOOLS FOR C++
• Compiler: g++ or CC (CC is only on the SGIs)
• Debugger: gdb, dbx (SGI), cvd (SGI), or printf(). ;-)
• Some text editors “understand” C++. (formatting, syntax
highlighting)
12
1B. NEW LIBRARIES FOR C++
• All of the C libraries still work
• Some C++ specific libraries
13
1C. NEW FILE NAMING CONVENTIONS FOR C++
• Some conventions for file names
• foo.h, foo.c – file names under C
• foo.hh, foo.cc – file names under C++
• Also foo.cpp, foo.cxx – file names under C++
14
1D. NEW SYNTAX
• Syntax virtually identical to C
• C++’s features add syntax
15
1E. AVAILABLE STANDARDS
• ISO/IEC 14882 in 1997
• Adopted ANSI in 1998
16
SOME QUESTIONS ABOUT C
• What is C?
• C is a low-level, procedural, systems programming language
• What problem did C solve?
• Designed as a system’s programming language for UNIX in the 1970s
• A fast, flexible, low-level language was needed.
17
SOME QUESTIONS ABOUT C++
• What is C++?
• C++ is an extension of C that provides support for object-oriented
programming
• What problem did it solve?
• Stroustrup states, “I built C++ as a bridge over which people would
pass from traditional programming to styles relying on data
abstraction and object-oriented programming.”
18
C VS C++
C VS C++
C C++
C is a Procedure Oriented Programming
Language
C++ is an Object Oriented Programming
Language
Top-Down Approach Bottom-Up Approach
C is less secure than C++ C++ is secure (Data Hiding)
C programming variable declaration is
possible only at top of the program
In C++, variable declaration can be
done anywhere in the program
In C, Namespace feature is not available In C++, Namespace feature is available
C is a middle level language C++ is a high level language
In C, programs are divided into modules
and Functions
In C++, programs are divided into
classes and Functions
Exception Handling not supported Supports Exception Handling
20
C VS C++
C C++
C Input and Output:
scanf(), printf()
C++ Input and Output:
Cin (>>), cout (<<)
In C, main() function can be called
through other functions
In C++, main() function cannot be
called through other functions
malloc(), calloc() functions are used
for dynamic memory allocation
new, delete operators are used for
allocating and deallocating memory
21
EVOLUTION OF C++
EVOLUTION OF C++
• It has a history going back to 1979
• Bjarne Stroustrup – Developed the C++
• He started work for his Ph.D. thesis
• He began work on "C with Classes", which as the name implies was
meant to be a superset of the C language
• His goal was to add object-oriented programming into the C
language which was and still is a language well-respected for its
portability without sacrificing speed or low-level functionality
• It included classes, basic inheritance, inlining, default
function arguments, and strong type checking in addition to
all the features of the C language
23
EVOLUTION OF C++ CONTD…
• In 1983 –
• the name of the language was changed from “C with Classes” to
C++
• The ++ operator in the C language is an operator for incrementing
a variable, which gives some insight into how Stroustrup regarded
the language
• Many new features were added around this time, the most notable
of which are virtual functions, function overloading, references with
the & symbol, the const keyword, and single-line comments using
two forward slashes
• In 1985 –
• C++ was implemented as a commercial product
• The language was not officially standardized yet
• In 1989 –
• The language was to include protected and static members, as well
as an inheritance from several classes.
24
EVOLUTION OF C++ CONTD…
• In 1990 –
• Turbo C++ was released as a commercial product
• Turbo C++ added a lot of additional libraries which have had a considerable impact on
C++'s development.
• In 1998 –
• the C++ standards committee published the first international standard for C++ ISO/IEC
14882:1998, which is informally known as C++98. The Standard Template Library, which
began its conceptual development in 1979, was also included.
• In 2003 –
• the committee responded to multiple problems that were reported with their 1998
standard and revised it accordingly. The changed language was named C++03.
• In mid-2011 –
• the new C++ standard (C++11) was finished
• The new features included Regex support, a randomization library, a new C++ time
library, atomics support, a standard threading library, a new for loop syntax providing
functionality similar to for each loops in certain other languages, the auto keyword, new
container classes, better support for unions and array-initialization lists and templates. 25
PROCEDURE ORIENTED PROGRAMMING
VS
OBJECT ORIENTED PROGRAMMING
PROCEDURAL ORIENTED PROGRAMMING
VS
OBJECT ORIENTED PROGRAMMING
Procedure Oriented Programming Object Oriented Programming
In procedural programming, program is divided into small
parts called functions.
In object oriented programming, program is divided into
small parts called objects.
Procedural programming follows top down approach.
Object oriented programming follows bottom up
approach.
There is no access specifier in procedural programming.
Object oriented programming have access specifiers like
private, public, protected etc.
Adding new data and function is not easy. Adding new data and function is easy.
Procedural programming does not have any proper way for
hiding data so it is less secure.
Object oriented programming provides data hiding so it
is more secure.
In procedural programming, overloading is not possible. Overloading is possible in object oriented programming.
In procedural programming, function is more important
than data.
In object oriented programming, data is more important
than function.
Procedural programming is based on unreal world. Object oriented programming is based on real world.
Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.
27
KEY CONCEPTS
OF
OBJECT ORIENTED PROGRAMMING
KEY CONCEPTS OF OOP
Major principles of Object Oriented Programming system are
• Class
• Object
• Inheritance
• Polymorphism
• Data Abstraction
• Encapsulation
29
CLASS
• Class -
• Classes are a blueprint or a set of instructions to build
a specific type of object
• It is a basic concept of Object-Oriented Programming
which revolve around the real-life entities
• Class determines how an object will behave and what
the object will contain
• class <class_name>
{
fields;
methods;
};
30
OBJECT
• Object
• is an instance of a class
• An object in OOPS is nothing but a self-contained
component which consists of methods and properties
to make a particular type of data useful
• For example color name, table, bag, barking
• When you send a message to an object, you are
asking the object to invoke or execute one of its
methods as defined in the class
• Syntax:
• Classname variable_name = new Classname();
31
CLASS VS OBJECTS
• A Class
• In object oriented programming class is a blueprint or prototype that defines the
variables and the methods (functions) common to all Objects of a certain kind
• An object
• In OOPS object is a specimen of a class
• Software objects are often used to model real-world objects you find in everyday
life
32
INHERITANCE
• Inheritance –
• Inheritance can be defined as the process where one class
acquires the properties, methods and fields of another
• With the use of inheritance the information is made
manageable in a hierarchical order
• The class which inherits the properties of the other is
known as subclass, derivedclass, childclass and the
class whose properties are inherited are known as
superclass, baseclass, parentclass
33
POLYMORPHISM
• Polymorphism –
• Allows us to use the same word to mean different things in different
contexts
• The capability of a method to do different things and take on many forms
based on the object that it is acting upon
• In other words, polymorphism allows you define one interface (or class)
and have multiple implementations
34
ABSTRACTION
• Abstraction-
• Allows for simple things to represent complexity
• Such as objects, classes, and variables representing more complex
underlying code and data
• We all know how to turn the TV on, but we don’t need to know how it
works in order to enjoy it
• For example in our code we could create a TV object then ask it to turn
on. We don’t need to worry about how the TV object works as long as
we know it has a on method within
• Consider the scanner import – we don’t worry about how it works we
just create a scanner object and use it when we want user input
• This is important because it lets avoid repeating the same work
multiple times.
35
ENCAPSULATION
• Encapsulation –
• Encapsulation is a mechanism of wrapping the data variables
and code acting on the data methods together as a single unit
• The variables of a class will be hidden from other classes, and
can be accessed only through the methods of their current class,
therefore it is also known as data hiding
• To achieve encapsulation, we declare the variables of a class as
private
• Provide public setter and getter methods to modify and view the
variables values
• We can re-use objects like code components or variables without
allowing open access to the data system-wide
36
ADVANTAGES
AND
DISADVANTAGES
ADVANTAGES
• Code Reusability
• Represents generic application concepts closely and are more
near to real world models
• Ease of programming
• Ease of Maintenance
• Ease in extension
• Ease in redesign
• Portability
• Scalability
• Compatibility with C
• Memory Management
38
DISADVANTAGES
• Designing OOP program is more tricky
• Planning in more important
• Good skills (Designing skills, Programming Skills and Thinking Skills) need to
acquired by the programmer
• Absence of Garbage Collector
• No Built-in threads
• Use of Pointers
39
THE END

More Related Content

What's hot (20)

Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Chapter 2 representation of algorithms
Chapter 2 representation of algorithmsChapter 2 representation of algorithms
Chapter 2 representation of algorithms
Li-Anne Serrano
 
Xml presentation
Xml presentationXml presentation
Xml presentation
Miguel Angel Teheran Garcia
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
niyamathShariff
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
Munawar Ahmed
 
JavaScript Interview Questions with Answers
JavaScript Interview Questions with AnswersJavaScript Interview Questions with Answers
JavaScript Interview Questions with Answers
AK Deep Knowledge
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
html-table
html-tablehtml-table
html-table
Dhirendra Chauhan
 
Libre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsLibre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding Functions
Smart Chicago Collaborative
 
basics dart.pdf
basics dart.pdfbasics dart.pdf
basics dart.pdf
ssuser0ca68e
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
Css properties
Css propertiesCss properties
Css properties
suresh_jathari
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
Ron Reiter
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
Rachel Andrew
 
Css animation
Css animationCss animation
Css animation
Aaron King
 
SQL
SQLSQL
SQL
Vineeta Garg
 
design and analysis of algorithm
design and analysis of algorithmdesign and analysis of algorithm
design and analysis of algorithm
Muhammad Arish
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Chapter 2 representation of algorithms
Chapter 2 representation of algorithmsChapter 2 representation of algorithms
Chapter 2 representation of algorithms
Li-Anne Serrano
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
niyamathShariff
 
JavaScript Interview Questions with Answers
JavaScript Interview Questions with AnswersJavaScript Interview Questions with Answers
JavaScript Interview Questions with Answers
AK Deep Knowledge
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Libre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsLibre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding Functions
Smart Chicago Collaborative
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
Ron Reiter
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
Rachel Andrew
 
design and analysis of algorithm
design and analysis of algorithmdesign and analysis of algorithm
design and analysis of algorithm
Muhammad Arish
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 

Similar to Object Oriented Programming using C++ - Part 1 (20)

@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf
TheertheshTheertha1
 
Object Oriented Design and Programming Unit-01
Object Oriented Design and Programming  Unit-01Object Oriented Design and Programming  Unit-01
Object Oriented Design and Programming Unit-01
Sivakumar M
 
C++ with student management system project
C++ with student management system projectC++ with student management system project
C++ with student management system project
Kratik Khandelwal
 
C++ Programming with examples for B.Tech
C++ Programming with examples for B.TechC++ Programming with examples for B.Tech
C++ Programming with examples for B.Tech
ashutoshgupta1102
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
IndraKhatri
 
c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
PadmaN24
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
Shanmuganathan C
 
object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentals
ChaithraCSHirematt
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
HeadoftheDepartment
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptx
shashiden1
 
C vs c++
C vs c++C vs c++
C vs c++
ZTE Nepal
 
C++ l 1
C++ l 1C++ l 1
C++ l 1
vineet_singh
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
MZGINBarwary
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
FarazKhan89093
 
Part 1
Part 1Part 1
Part 1
Moatez Amairi
 
lecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoyelecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoye
quetsqrj
 
Introduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plusIntroduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plus
University of Sindh
 
Object oriented programming. (1).pptx
Object oriented programming.      (1).pptxObject oriented programming.      (1).pptx
Object oriented programming. (1).pptx
baadshahyash
 
@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf
TheertheshTheertha1
 
Object Oriented Design and Programming Unit-01
Object Oriented Design and Programming  Unit-01Object Oriented Design and Programming  Unit-01
Object Oriented Design and Programming Unit-01
Sivakumar M
 
C++ with student management system project
C++ with student management system projectC++ with student management system project
C++ with student management system project
Kratik Khandelwal
 
C++ Programming with examples for B.Tech
C++ Programming with examples for B.TechC++ Programming with examples for B.Tech
C++ Programming with examples for B.Tech
ashutoshgupta1102
 
c++session 1.pptx
c++session 1.pptxc++session 1.pptx
c++session 1.pptx
PadmaN24
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
Shanmuganathan C
 
object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentals
ChaithraCSHirematt
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
HeadoftheDepartment
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptx
shashiden1
 
lecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoyelecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoye
quetsqrj
 
Introduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plusIntroduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plus
University of Sindh
 
Object oriented programming. (1).pptx
Object oriented programming.      (1).pptxObject oriented programming.      (1).pptx
Object oriented programming. (1).pptx
baadshahyash
 
Ad

More from University College of Engineering Kakinada, JNTUK - Kakinada, India (9)

Machine Learning - Implementation with Python - 4.pdf
Machine Learning - Implementation with Python - 4.pdfMachine Learning - Implementation with Python - 4.pdf
Machine Learning - Implementation with Python - 4.pdf
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Machine Learning - Implementation with Python - 3.pdf
Machine Learning - Implementation with Python - 3.pdfMachine Learning - Implementation with Python - 3.pdf
Machine Learning - Implementation with Python - 3.pdf
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Machine Learning - Implementation with Python - 2
Machine Learning - Implementation with Python - 2Machine Learning - Implementation with Python - 2
Machine Learning - Implementation with Python - 2
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Machine Learning - Implementation with Python - 1
Machine Learning - Implementation with Python - 1Machine Learning - Implementation with Python - 1
Machine Learning - Implementation with Python - 1
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Chandu cyber security career path
Chandu cyber security career pathChandu cyber security career path
Chandu cyber security career path
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Object Oriented Programming using C++ - Part 5
Object Oriented Programming using C++ - Part 5Object Oriented Programming using C++ - Part 5
Object Oriented Programming using C++ - Part 5
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Object Oriented Programming using C++ - Part 3
Object Oriented Programming using C++ - Part 3Object Oriented Programming using C++ - Part 3
Object Oriented Programming using C++ - Part 3
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Ad

Recently uploaded (20)

Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 

Object Oriented Programming using C++ - Part 1

  • 1. OOPS THROUGH C++ Dr. Chandra Sekhar Sanaboina Assistant Professor Department of Computer Science and Engineering University College of Engineering Kakinada Jawaharlal Nehru Technological University Kakinada Website: https://drcs.info Youtube Link: https://www.youtube.com/watch?v=nPjHraTbPeY&list=PLT1ngltOnlJiHbzVvjkU8VzQt9oam8ji4
  • 3. AGENDA • Difference between C and C++ • Evolution of C++ • Procedure Oriented Programming vs Object Oriented Programming • Key concepts of Object Oriented Programming • Advantages and Disadvantages of OOP 3
  • 4. PROCEDURE ORIENTED PROGRAMMING • It means “a set of procedures” which is a “set of subroutines” or a “set of functions“ • Functions are called repeatedly in a program to execute tasks performed by them • Example: A program may involve collecting data from user (reading), performing some kind of calculations on the collected data (calculation), and finally displaying the result to the user when requested (printing). All the 3 tasks of reading, calculating and printing can be written in a program with the help of 3 different functions which performs these 3 different tasks. 4
  • 5. A REAL WORLD EXAMPLE • We are working for a vehicle parts manufacturer that needs to update it's online inventory system. Boss tells us to program two similar but separate forms for a website, one form that processes information about cars and one that does the same for trucks • For cars, we will need to record the following information: • Color, Engine Size, Transmission Type, Number of doors • For trucks, the information will be similar, but slightly different. We need: • Color, Engine Size, Transmission Type, Cab Size, Towing Capacity 5
  • 6. SCENARIO - 1 • Suppose that we suddenly need to add a bus form, that records the following information: • Color, Engine Size, Transmission Type, Number of passengers • Procedural – • We need to recreate the entire form, repeating the code for Color, Engine Size, and Transmission Type. • OOP - • We simply extend the vehicle class with a bus class and add the method numberOfPassengers 6
  • 7. SCENARIO - 2 • Instead of storing color in a database like we previously did, for some strange reason our client wants the color emailed to him • Procedural – • We change three different forms: cars, trucks, and buses to email the color to the client rather than storing it in the database. • OOP – • We change the color method in the vehicle class and because the car, truck, and bus classes all extend (or inherit from, to put it another way) the vehicle class, they are automatically updated 7
  • 8. SCENARIO - 3 • We want to move from a generic car to specific makes, for example: Nissan and Creta • Procedural – • We create a new form for each make, repeating all of the code for generic car information and adding the code specific to each make • OOP – • We extend the car class with a Nissan class and a Creta class and add methods for each set of unique information for that car make 8
  • 9. SCENARIO - 4 • We found a bug in the transmission type area of our form and need to fix it • Procedural – • We open and update each and every form • OOP – • We fix the transmission Type method in the vehicle class and the change perpetuates in every class that inherits from it 9
  • 10. WHY SWITCH TO C++ • Supports an OO approach to programming • Classes • Inheritance • Polymorphism • Exceptions • Provides powerful features on top of a “fast” language 10
  • 11. HOW TO SWITCH TO C++ 1. Learn about differences a. New tools (compilers, debuggers, etc.) b. New libraries c. New file naming conventions d. New syntax e. Available standards 2. Rethink programming approach 11
  • 12. 1A. NEW TOOLS FOR C++ • Compiler: g++ or CC (CC is only on the SGIs) • Debugger: gdb, dbx (SGI), cvd (SGI), or printf(). ;-) • Some text editors “understand” C++. (formatting, syntax highlighting) 12
  • 13. 1B. NEW LIBRARIES FOR C++ • All of the C libraries still work • Some C++ specific libraries 13
  • 14. 1C. NEW FILE NAMING CONVENTIONS FOR C++ • Some conventions for file names • foo.h, foo.c – file names under C • foo.hh, foo.cc – file names under C++ • Also foo.cpp, foo.cxx – file names under C++ 14
  • 15. 1D. NEW SYNTAX • Syntax virtually identical to C • C++’s features add syntax 15
  • 16. 1E. AVAILABLE STANDARDS • ISO/IEC 14882 in 1997 • Adopted ANSI in 1998 16
  • 17. SOME QUESTIONS ABOUT C • What is C? • C is a low-level, procedural, systems programming language • What problem did C solve? • Designed as a system’s programming language for UNIX in the 1970s • A fast, flexible, low-level language was needed. 17
  • 18. SOME QUESTIONS ABOUT C++ • What is C++? • C++ is an extension of C that provides support for object-oriented programming • What problem did it solve? • Stroustrup states, “I built C++ as a bridge over which people would pass from traditional programming to styles relying on data abstraction and object-oriented programming.” 18
  • 20. C VS C++ C C++ C is a Procedure Oriented Programming Language C++ is an Object Oriented Programming Language Top-Down Approach Bottom-Up Approach C is less secure than C++ C++ is secure (Data Hiding) C programming variable declaration is possible only at top of the program In C++, variable declaration can be done anywhere in the program In C, Namespace feature is not available In C++, Namespace feature is available C is a middle level language C++ is a high level language In C, programs are divided into modules and Functions In C++, programs are divided into classes and Functions Exception Handling not supported Supports Exception Handling 20
  • 21. C VS C++ C C++ C Input and Output: scanf(), printf() C++ Input and Output: Cin (>>), cout (<<) In C, main() function can be called through other functions In C++, main() function cannot be called through other functions malloc(), calloc() functions are used for dynamic memory allocation new, delete operators are used for allocating and deallocating memory 21
  • 23. EVOLUTION OF C++ • It has a history going back to 1979 • Bjarne Stroustrup – Developed the C++ • He started work for his Ph.D. thesis • He began work on "C with Classes", which as the name implies was meant to be a superset of the C language • His goal was to add object-oriented programming into the C language which was and still is a language well-respected for its portability without sacrificing speed or low-level functionality • It included classes, basic inheritance, inlining, default function arguments, and strong type checking in addition to all the features of the C language 23
  • 24. EVOLUTION OF C++ CONTD… • In 1983 – • the name of the language was changed from “C with Classes” to C++ • The ++ operator in the C language is an operator for incrementing a variable, which gives some insight into how Stroustrup regarded the language • Many new features were added around this time, the most notable of which are virtual functions, function overloading, references with the & symbol, the const keyword, and single-line comments using two forward slashes • In 1985 – • C++ was implemented as a commercial product • The language was not officially standardized yet • In 1989 – • The language was to include protected and static members, as well as an inheritance from several classes. 24
  • 25. EVOLUTION OF C++ CONTD… • In 1990 – • Turbo C++ was released as a commercial product • Turbo C++ added a lot of additional libraries which have had a considerable impact on C++'s development. • In 1998 – • the C++ standards committee published the first international standard for C++ ISO/IEC 14882:1998, which is informally known as C++98. The Standard Template Library, which began its conceptual development in 1979, was also included. • In 2003 – • the committee responded to multiple problems that were reported with their 1998 standard and revised it accordingly. The changed language was named C++03. • In mid-2011 – • the new C++ standard (C++11) was finished • The new features included Regex support, a randomization library, a new C++ time library, atomics support, a standard threading library, a new for loop syntax providing functionality similar to for each loops in certain other languages, the auto keyword, new container classes, better support for unions and array-initialization lists and templates. 25
  • 27. PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMMING Procedure Oriented Programming Object Oriented Programming In procedural programming, program is divided into small parts called functions. In object oriented programming, program is divided into small parts called objects. Procedural programming follows top down approach. Object oriented programming follows bottom up approach. There is no access specifier in procedural programming. Object oriented programming have access specifiers like private, public, protected etc. Adding new data and function is not easy. Adding new data and function is easy. Procedural programming does not have any proper way for hiding data so it is less secure. Object oriented programming provides data hiding so it is more secure. In procedural programming, overloading is not possible. Overloading is possible in object oriented programming. In procedural programming, function is more important than data. In object oriented programming, data is more important than function. Procedural programming is based on unreal world. Object oriented programming is based on real world. Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc. 27
  • 29. KEY CONCEPTS OF OOP Major principles of Object Oriented Programming system are • Class • Object • Inheritance • Polymorphism • Data Abstraction • Encapsulation 29
  • 30. CLASS • Class - • Classes are a blueprint or a set of instructions to build a specific type of object • It is a basic concept of Object-Oriented Programming which revolve around the real-life entities • Class determines how an object will behave and what the object will contain • class <class_name> { fields; methods; }; 30
  • 31. OBJECT • Object • is an instance of a class • An object in OOPS is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful • For example color name, table, bag, barking • When you send a message to an object, you are asking the object to invoke or execute one of its methods as defined in the class • Syntax: • Classname variable_name = new Classname(); 31
  • 32. CLASS VS OBJECTS • A Class • In object oriented programming class is a blueprint or prototype that defines the variables and the methods (functions) common to all Objects of a certain kind • An object • In OOPS object is a specimen of a class • Software objects are often used to model real-world objects you find in everyday life 32
  • 33. INHERITANCE • Inheritance – • Inheritance can be defined as the process where one class acquires the properties, methods and fields of another • With the use of inheritance the information is made manageable in a hierarchical order • The class which inherits the properties of the other is known as subclass, derivedclass, childclass and the class whose properties are inherited are known as superclass, baseclass, parentclass 33
  • 34. POLYMORPHISM • Polymorphism – • Allows us to use the same word to mean different things in different contexts • The capability of a method to do different things and take on many forms based on the object that it is acting upon • In other words, polymorphism allows you define one interface (or class) and have multiple implementations 34
  • 35. ABSTRACTION • Abstraction- • Allows for simple things to represent complexity • Such as objects, classes, and variables representing more complex underlying code and data • We all know how to turn the TV on, but we don’t need to know how it works in order to enjoy it • For example in our code we could create a TV object then ask it to turn on. We don’t need to worry about how the TV object works as long as we know it has a on method within • Consider the scanner import – we don’t worry about how it works we just create a scanner object and use it when we want user input • This is important because it lets avoid repeating the same work multiple times. 35
  • 36. ENCAPSULATION • Encapsulation – • Encapsulation is a mechanism of wrapping the data variables and code acting on the data methods together as a single unit • The variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class, therefore it is also known as data hiding • To achieve encapsulation, we declare the variables of a class as private • Provide public setter and getter methods to modify and view the variables values • We can re-use objects like code components or variables without allowing open access to the data system-wide 36
  • 38. ADVANTAGES • Code Reusability • Represents generic application concepts closely and are more near to real world models • Ease of programming • Ease of Maintenance • Ease in extension • Ease in redesign • Portability • Scalability • Compatibility with C • Memory Management 38
  • 39. DISADVANTAGES • Designing OOP program is more tricky • Planning in more important • Good skills (Designing skills, Programming Skills and Thinking Skills) need to acquired by the programmer • Absence of Garbage Collector • No Built-in threads • Use of Pointers 39