SlideShare a Scribd company logo
C++ Introduction
Unit-1
Presented by
Er. Jasleen Kaur
Assistant Professor
Applied Science(CSE)
Chandigarh University
Gharuan (Mohali).
1
C vs C++
• C- Structured programming became very popular and
was the main technique of the1980.
• Structured programming enable programmers to write
moderately complex programs fairly easily. However as
the programs grew larger, even the structured approach
failed to show the desired results in terms of bug-free,
easy-to-maintain and reusable programs.
C vs C++
• -Object-Oriented Programming (OOP) is an approach
to program organization and development that
attempts to eliminate some of the pitfalls of
conventional programming methods by incorporating
the best of structured programming features with
several powerful new concepts.
Procedure-Oriented Programming
• Conventional programming using high level language
such as COBOL, FORTRAN and C is commonly known
as Procedure oriented programming.
• In the Procedure oriented approach the problem is
viewed as a sequence of things to be done such as
reading, calculating and printing.
• The primary focus is on functions.
5
• 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.
• For example, a program may involve-
1. collecting data from user (reading),
2. performing some kind of calculations on the
collected data (calculation), and
3. 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.
Structure of Procedure-oriented
Procedure-Oriented Programming
• Procedure-Oriented Programming
• Procedure oriented programming basically consists
of writing a list of instructions for the computer to
follow and organizing these instructions into groups
known as functions.
• We normally use a flow chart to organize these
actions and represent the flow of control from one
action to another.
• More importance to functions very little attention to
data that are being used by the functions.
Structure of Procedure-oriented
(Problem)
Procedure-Oriented Programming
• In multi-function program many important data
items are placed as global so that they may be
accessed by all the functions. Each function may
have its own local data.
• In large program it is very difficult to identify what
data is used by which function. In case we need to
revise an external data structure we also need to
revise all function that access it.
Object-Oriented Programming
• OOP treats data as a critical element in the program
development and does not allow it to flow freely
around the system.
• protects data from accidental modification from
outside functions
• OOP allows decomposition of a problem into a
number of entities called objects
Organization of data & function OOP
Striking features of OOP
• Emphasis is on data rather than procedure.
• Programs are divided into what are known as
objects
• Functions that operate on the data of an object are
tied together in the data structure.
• Data is hidden and can not be accessed by external
functions
• Objects may communicate with each other through
functions
Difference between Procedure oriented Programming and
Object Oriented Programming
Procedure-Oriented
Programming
Object Oriented Programming
Divided Into In POP, program is divided into
small parts called functions.
In OOP, program is divided into
parts called objects.
Importance In POP,Importance is not given
to data but to functions as well
as sequence of actions to be
done.
In OOP, Importance is given to
the data rather than
procedures or functions
because it works as a real
world.
Approach POP follows Top Down approach. OOP follows Bottom Up
approach.
Access
Specifiers
POP does not have any access
specifier.
OOP has access specifiers
named Public, Private,
Protected, etc.
Data Moving In POP, Data can move
freely from function to
function in the system.
In OOP, objects can move
and communicate with
each other through
member functions.
Expansion To add new data and
function in POP is not so
easy.
OOP provides an easy way
to add new data and
function.
Data Access In POP, Most function
uses Global data for
sharing that can be
accessed freely from
function to function in
the system.
In OOP, data can not move
easily from function to
function. it can be kept
public or private so we can
control the access of data.
Data Hiding POP does not have any
proper way for hiding
data so it is less secure.
OOP provides Data
Hiding so provides more
security.
Overloading In POP, Overloading is
not possible.
In OOP, overloading is
possible in the form of
Function Overloading
and Operator
Overloading.
Examples Example of POP are : C,
VB, FORTRAN, Pascal.
Example of OOP are :
C++, JAVA, VB.NET,
C#.NET.
• Let's say that you are working for a vehicle parts
manufacturer that needs to update it's online inventory
system.
• Your boss tells you 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
Real World example for difference
Scenario 1
(addition of bus form)
• 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.
Scenario 2
(sending email instead of storing
database)
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.
Scenario 3 (moving from generic car
to specific cars)
• We want to move from a generic car to specific makes,
for example: Nissan and Mazda.
• 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
Mazda class and add methods for each set of unique
information for that car make.
Scenario 4
(bug removal)
• We found a bug in the ‘transmission type area’ of our
form and need to fix it.
• Procedural: We open and update each form.
• OOP: We fix the transmission Type method in the
vehicle class and the change perpetuates in every class
that inherits from it.
Basic Object oriented concepts:
• Class –The entire set of data and code of an object
can be made a user-defined data type with the help
of a class.
• Objects are variable of type class.
• Once a class has been defined we can create any
number of objects belonging to that class.
• A class is thus a collection of objects of similar type.
• Classes are user-defined data types and behave like
the built-in types of a programming language.
Class v/s Structure
• Class usually used for
large programs.
• Can be inherited.
• Can be null or empty.
• Declared methods in
class are automatically
locked (private by
default).
• Class can have
constructor as well as
destructor.
• Structures usually used
for small programs.
• Cannot be inherited.
• Cannot be NULL.
• Methods can’t be
locked (public by
default).
• Structure couldn’t have
constructor and
destructor. 22
Object
• Objects are the basic run-time entities in an object-
oriented system. Object- is an instance(Property) of a
class. Each object has a class which defines its data
and behaviour.
• They may represent a person, a place, a bank
account ,a table of data or any item that the program
must handle.
• Program objects should be chosen such that they
match closely with the real-world objects.
• Objects take up space in the memory and have an
associated address like structure in C.
• When a program is executed the objects interact by
sending messages to one another.
24
Object has a life cycle. They can be created and destroyed
25
• Hence, every object has 3 important features
– 1. Identity (e.g. Name)
– 2. State (e.g. drive bus, fly plane etc.) – these are
assigned on the basis of the object’s characteristics – A
manager object would have different responsibilities
than a developer, since their job descriptions (a
characteristic) would be different:
– 3. Behaviour (Relationships with other objects)– in order
to send requests/messages to each other, objects need
to have some relationship/connection. E.g. A bus driver
needs to have access/connection to a bus in order to
drive it.
26
Structure of a Class in C++
class name {
declarations
constructor definition(s)
method definitions
}
attributes and
symbolic constants
how to create and
initialize objects
how to manipulate
the state of objects
These parts of a class can
actually be in any order
Sample class
#include<iostream.h>
class Pencil
{
public String color = “red”;
public int length;
public float diameter;
setcolor(string);
public void setColor (String newColor)
{
color = yellow;
}
}
Concepts of OOP
• Objects
• Classes
• Abstraction and Encapsulation(Information
Hiding)
• Polymorphism
• Inheritance
• Dynamic Binding
• Message Passing
28
• Data Abstraction-Data Abstraction refers to the act of
re- presenting essential features without including
the back-ground details. It is concerned with
separating the behaviour of a data object from its re-
presentation.
• E.g. Executable file of a program.
• Encapsulation- The process of binding data members
and functions in a class is known as, encapsulation.
Encapsulation is the powerful feature (concept) of
object-oriented programming.
With the help of this concept, data is not accessible to
the outside world and only those functions which are
declared in the class, can access it.
 Displayed code is known using "public" modifier
is known as Abstraction.
 Hiding complex code using "private" modifier is
known as Encapsulation.
31
Encapsulation hides the complexity of code whereas abstraction is
thinking in terms of design way to increase efficiency.
• Information hiding/Data Hiding-
 Data Hiding is similar to encapsulation. Basically,
encapsulating data members and functions in a
class promotes data hiding.
 This concept will help us to provide the essential
features to the users and hide the details. In short,
encapsulating through private access modifier
(label) is known as data hiding.
• Inheritance-
 Inheritance is a process by which objects of new
class acquire the properties of objects of existing
(base) class. It is in hierarchical order.
 The concept of inheritance provides the idea of
reusability.
 This means that we can add additional features to
an existing class without modifying it
• Polymorphism
 Polymorphism is an important object-oriented
programming concept.
 This is a greek term, means the ability to take
more than one form.
 The process of making an operator/method to
show different behaviours in different instances is
known as operator-overloading.
 Using a single function name to perform different
types of tasks is known as function-overloading.
35
• Dynamic Binding
 means code is linked with associated procedural call
at run time (execution time). It is also called as Late
Binding.
 Binding refers to the process that is used to convert
identifiers (such as variable and function names)
into machine language addresses. Although binding
is used for both variables and functions.
 Late binding is slightly less efficient since it involves
an extra level of indirection.
 With early binding, the compiler can tell the CPU to
jump directly to the function’s address.
36
• Message Passing
Message Passing is nothing but sending and receiving
of information by the objects same as people
exchange information. So this helps in building
systems that simulate real life. Following are the basic
steps in message passing.
• Creating classes that define objects and its behavior.
• Creating objects from class definitions
• Establishing communication among objects
• In OOPs, Message Passing involves specifying the
name of objects, the name of the function, and the
information to be sent.
37
For example,
 if “customer” and “account” are to object in a
program, then the customer object may send
a message to the account object requesting
for the bank balance.
 Each object contain data, and code to
manipulate data.
 Objects can interact without having to know
details of each other’s data or code.
 It is sufficient to know the type of message
accepted, and the type of response returned
by the objects. 38
Benefits of OOP
• Through inheritance we can elimate the redundant
code and extend the use of existing code
• Data hiding helps the programmer to build secure
programs that can not be invaded by code in other
parts of the program
• It is possible to have multiple instances of an objects to
co-exist with out any interference (using arrays).
example you want to shoot multiple bullets at same
time in a game.
• It is possible to map objects in the problem domain to
those objects in the program.
• Easy to partition the work in a project based on objects
Data-centred design approach enables us to
capture more details of a model in
implementable form
• Object-oriented systems can be easily
upgraded from small to large systems
• Software complexity can be easily managed.

More Related Content

PPTX
Object oriented programming
PPT
Abstract class in java
PPS
Introduction to class in java
PDF
Constructors and Destructors
PPTX
Classes objects in java
PPTX
array of object pointer in c++
PPTX
Error managing and exception handling in java
Object oriented programming
Abstract class in java
Introduction to class in java
Constructors and Destructors
Classes objects in java
array of object pointer in c++
Error managing and exception handling in java

What's hot (20)

PPT
Java adapter
PPTX
classes and objects in C++
PPTX
Object oriented programming
PPTX
constructors in java ppt
PPTX
07. Virtual Functions
PDF
Class and Objects in Java
PPTX
Java constructors
PPTX
Characteristics of OOPS
PPTX
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PDF
Object oriented approach in python programming
PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
PDF
C++ chapter 1
PPTX
Constructor and Types of Constructors
PPTX
Constructor in java
PPTX
PPTX
Inheritance in java
PPTX
Encapsulation C++
PPT
Inheritance in java
PDF
Identifying classes and objects ooad
Java adapter
classes and objects in C++
Object oriented programming
constructors in java ppt
07. Virtual Functions
Class and Objects in Java
Java constructors
Characteristics of OOPS
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
Object oriented approach in python programming
[OOP - Lec 08] Encapsulation (Information Hiding)
C++ chapter 1
Constructor and Types of Constructors
Constructor in java
Inheritance in java
Encapsulation C++
Inheritance in java
Identifying classes and objects ooad
Ad

Similar to Chapter 1 (20)

PPTX
[OOP - Lec 02] Why do we need OOP
PPTX
SE-IT JAVA LAB OOP CONCEPT
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
PPTX
OOP-1.pptx
PPTX
c++.pptxwjwjsijsnsksomammaoansnksooskskk
PPTX
Lecture 1.pptx
PPTX
Unit 2.pptx
PPTX
Unit 2.pptx
PPTX
OOP CHAPTER object oreinted programming using c++
PPTX
Oop in c++ lecture 1
PPT
Unit 1- Basic concept of object-oriented-programming.ppt
PPTX
CPP-Unit 1.pptx
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
PPT
Share Unit 1- Basic concept of object-oriented-programming.ppt
PDF
OOPS_Unit_1
PDF
C++ notes.pdf
PPTX
DOC-20210303-WA0017..pptx,coding stuff in c
PPTX
Programming using C++ - slides.pptx
PDF
2nd PUC computer science chapter 6 oop concept
PPTX
IET307 OOP - object oriented programming concepts.pptx
[OOP - Lec 02] Why do we need OOP
SE-IT JAVA LAB OOP CONCEPT
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
OOP-1.pptx
c++.pptxwjwjsijsnsksomammaoansnksooskskk
Lecture 1.pptx
Unit 2.pptx
Unit 2.pptx
OOP CHAPTER object oreinted programming using c++
Oop in c++ lecture 1
Unit 1- Basic concept of object-oriented-programming.ppt
CPP-Unit 1.pptx
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
Share Unit 1- Basic concept of object-oriented-programming.ppt
OOPS_Unit_1
C++ notes.pdf
DOC-20210303-WA0017..pptx,coding stuff in c
Programming using C++ - slides.pptx
2nd PUC computer science chapter 6 oop concept
IET307 OOP - object oriented programming concepts.pptx
Ad

More from Jasleen Kaur (Chandigarh University) (19)

PPTX
Graphs data structures
PPTX
B+ trees and height balance tree
PDF
Operating system notes pdf
PPTX
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
PDF
03 function overloading
PPTX
Chapter 2.datatypes and operators
PDF
Remote desktop connection
PPTX
Operators in C Programming
PPTX
Pointers in C Programming
PPTX
Calculating garbage value in case of overflow
PPTX
License Plate recognition
PPTX
Afforestation environmental issue
PPTX
Data aggregation in wireless sensor networks
Graphs data structures
B+ trees and height balance tree
Operating system notes pdf
Priority Based Congestion Avoidance Hybrid Scheme published in IEEE
03 function overloading
Chapter 2.datatypes and operators
Remote desktop connection
Operators in C Programming
Pointers in C Programming
Calculating garbage value in case of overflow
License Plate recognition
Afforestation environmental issue
Data aggregation in wireless sensor networks

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Nekopoi APK 2025 free lastest update
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administration Chapter 2
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Transform Your Business with a Software ERP System
PDF
AI in Product Development-omnex systems
PPT
Introduction Database Management System for Course Database
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
ManageIQ - Sprint 268 Review - Slide Deck
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Nekopoi APK 2025 free lastest update
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administration Chapter 2
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
Transform Your Business with a Software ERP System
AI in Product Development-omnex systems
Introduction Database Management System for Course Database
Adobe Illustrator 28.6 Crack My Vision of Vector Design
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
How Creative Agencies Leverage Project Management Software.pdf

Chapter 1

  • 1. C++ Introduction Unit-1 Presented by Er. Jasleen Kaur Assistant Professor Applied Science(CSE) Chandigarh University Gharuan (Mohali). 1
  • 2. C vs C++ • C- Structured programming became very popular and was the main technique of the1980. • Structured programming enable programmers to write moderately complex programs fairly easily. However as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain and reusable programs.
  • 3. C vs C++ • -Object-Oriented Programming (OOP) is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts.
  • 4. Procedure-Oriented Programming • Conventional programming using high level language such as COBOL, FORTRAN and C is commonly known as Procedure oriented programming. • In the Procedure oriented approach the problem is viewed as a sequence of things to be done such as reading, calculating and printing. • The primary focus is on functions.
  • 5. 5 • 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. • For example, a program may involve- 1. collecting data from user (reading), 2. performing some kind of calculations on the collected data (calculation), and 3. 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.
  • 7. Procedure-Oriented Programming • Procedure-Oriented Programming • Procedure oriented programming basically consists of writing a list of instructions for the computer to follow and organizing these instructions into groups known as functions. • We normally use a flow chart to organize these actions and represent the flow of control from one action to another. • More importance to functions very little attention to data that are being used by the functions.
  • 9. Procedure-Oriented Programming • In multi-function program many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data. • In large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure we also need to revise all function that access it.
  • 10. Object-Oriented Programming • OOP treats data as a critical element in the program development and does not allow it to flow freely around the system. • protects data from accidental modification from outside functions • OOP allows decomposition of a problem into a number of entities called objects
  • 11. Organization of data & function OOP
  • 12. Striking features of OOP • Emphasis is on data rather than procedure. • Programs are divided into what are known as objects • Functions that operate on the data of an object are tied together in the data structure. • Data is hidden and can not be accessed by external functions • Objects may communicate with each other through functions
  • 13. Difference between Procedure oriented Programming and Object Oriented Programming Procedure-Oriented Programming Object Oriented Programming Divided Into In POP, program is divided into small parts called functions. In OOP, program is divided into parts called objects. Importance In POP,Importance is not given to data but to functions as well as sequence of actions to be done. In OOP, Importance is given to the data rather than procedures or functions because it works as a real world. Approach POP follows Top Down approach. OOP follows Bottom Up approach. Access Specifiers POP does not have any access specifier. OOP has access specifiers named Public, Private, Protected, etc.
  • 14. Data Moving In POP, Data can move freely from function to function in the system. In OOP, objects can move and communicate with each other through member functions. Expansion To add new data and function in POP is not so easy. OOP provides an easy way to add new data and function. Data Access In POP, Most function uses Global data for sharing that can be accessed freely from function to function in the system. In OOP, data can not move easily from function to function. it can be kept public or private so we can control the access of data.
  • 15. Data Hiding POP does not have any proper way for hiding data so it is less secure. OOP provides Data Hiding so provides more security. Overloading In POP, Overloading is not possible. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. Examples Example of POP are : C, VB, FORTRAN, Pascal. Example of OOP are : C++, JAVA, VB.NET, C#.NET.
  • 16. • Let's say that you are working for a vehicle parts manufacturer that needs to update it's online inventory system. • Your boss tells you 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 Real World example for difference
  • 17. Scenario 1 (addition of bus form) • 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.
  • 18. Scenario 2 (sending email instead of storing database) 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.
  • 19. Scenario 3 (moving from generic car to specific cars) • We want to move from a generic car to specific makes, for example: Nissan and Mazda. • 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 Mazda class and add methods for each set of unique information for that car make.
  • 20. Scenario 4 (bug removal) • We found a bug in the ‘transmission type area’ of our form and need to fix it. • Procedural: We open and update each form. • OOP: We fix the transmission Type method in the vehicle class and the change perpetuates in every class that inherits from it.
  • 21. Basic Object oriented concepts: • Class –The entire set of data and code of an object can be made a user-defined data type with the help of a class. • Objects are variable of type class. • Once a class has been defined we can create any number of objects belonging to that class. • A class is thus a collection of objects of similar type. • Classes are user-defined data types and behave like the built-in types of a programming language.
  • 22. Class v/s Structure • Class usually used for large programs. • Can be inherited. • Can be null or empty. • Declared methods in class are automatically locked (private by default). • Class can have constructor as well as destructor. • Structures usually used for small programs. • Cannot be inherited. • Cannot be NULL. • Methods can’t be locked (public by default). • Structure couldn’t have constructor and destructor. 22
  • 23. Object • Objects are the basic run-time entities in an object- oriented system. Object- is an instance(Property) of a class. Each object has a class which defines its data and behaviour. • They may represent a person, a place, a bank account ,a table of data or any item that the program must handle. • Program objects should be chosen such that they match closely with the real-world objects. • Objects take up space in the memory and have an associated address like structure in C. • When a program is executed the objects interact by sending messages to one another.
  • 24. 24 Object has a life cycle. They can be created and destroyed
  • 25. 25 • Hence, every object has 3 important features – 1. Identity (e.g. Name) – 2. State (e.g. drive bus, fly plane etc.) – these are assigned on the basis of the object’s characteristics – A manager object would have different responsibilities than a developer, since their job descriptions (a characteristic) would be different: – 3. Behaviour (Relationships with other objects)– in order to send requests/messages to each other, objects need to have some relationship/connection. E.g. A bus driver needs to have access/connection to a bus in order to drive it.
  • 26. 26 Structure of a Class in C++ class name { declarations constructor definition(s) method definitions } attributes and symbolic constants how to create and initialize objects how to manipulate the state of objects These parts of a class can actually be in any order
  • 27. Sample class #include<iostream.h> class Pencil { public String color = “red”; public int length; public float diameter; setcolor(string); public void setColor (String newColor) { color = yellow; } }
  • 28. Concepts of OOP • Objects • Classes • Abstraction and Encapsulation(Information Hiding) • Polymorphism • Inheritance • Dynamic Binding • Message Passing 28
  • 29. • Data Abstraction-Data Abstraction refers to the act of re- presenting essential features without including the back-ground details. It is concerned with separating the behaviour of a data object from its re- presentation. • E.g. Executable file of a program.
  • 30. • Encapsulation- The process of binding data members and functions in a class is known as, encapsulation. Encapsulation is the powerful feature (concept) of object-oriented programming. With the help of this concept, data is not accessible to the outside world and only those functions which are declared in the class, can access it.  Displayed code is known using "public" modifier is known as Abstraction.  Hiding complex code using "private" modifier is known as Encapsulation.
  • 31. 31 Encapsulation hides the complexity of code whereas abstraction is thinking in terms of design way to increase efficiency.
  • 32. • Information hiding/Data Hiding-  Data Hiding is similar to encapsulation. Basically, encapsulating data members and functions in a class promotes data hiding.  This concept will help us to provide the essential features to the users and hide the details. In short, encapsulating through private access modifier (label) is known as data hiding.
  • 33. • Inheritance-  Inheritance is a process by which objects of new class acquire the properties of objects of existing (base) class. It is in hierarchical order.  The concept of inheritance provides the idea of reusability.  This means that we can add additional features to an existing class without modifying it
  • 34. • Polymorphism  Polymorphism is an important object-oriented programming concept.  This is a greek term, means the ability to take more than one form.  The process of making an operator/method to show different behaviours in different instances is known as operator-overloading.  Using a single function name to perform different types of tasks is known as function-overloading.
  • 35. 35
  • 36. • Dynamic Binding  means code is linked with associated procedural call at run time (execution time). It is also called as Late Binding.  Binding refers to the process that is used to convert identifiers (such as variable and function names) into machine language addresses. Although binding is used for both variables and functions.  Late binding is slightly less efficient since it involves an extra level of indirection.  With early binding, the compiler can tell the CPU to jump directly to the function’s address. 36
  • 37. • Message Passing Message Passing is nothing but sending and receiving of information by the objects same as people exchange information. So this helps in building systems that simulate real life. Following are the basic steps in message passing. • Creating classes that define objects and its behavior. • Creating objects from class definitions • Establishing communication among objects • In OOPs, Message Passing involves specifying the name of objects, the name of the function, and the information to be sent. 37
  • 38. For example,  if “customer” and “account” are to object in a program, then the customer object may send a message to the account object requesting for the bank balance.  Each object contain data, and code to manipulate data.  Objects can interact without having to know details of each other’s data or code.  It is sufficient to know the type of message accepted, and the type of response returned by the objects. 38
  • 39. Benefits of OOP • Through inheritance we can elimate the redundant code and extend the use of existing code • Data hiding helps the programmer to build secure programs that can not be invaded by code in other parts of the program • It is possible to have multiple instances of an objects to co-exist with out any interference (using arrays). example you want to shoot multiple bullets at same time in a game. • It is possible to map objects in the problem domain to those objects in the program. • Easy to partition the work in a project based on objects
  • 40. Data-centred design approach enables us to capture more details of a model in implementable form • Object-oriented systems can be easily upgraded from small to large systems • Software complexity can be easily managed.