SlideShare a Scribd company logo
Using
C++
Object Oriented Programming
Contents
 Features of OOP
 Classes
 Objects & Creating the Objects
 Constructors & Destructors
 Friend Functions & Classes
 Static data members & functions
OOP
 It is programming technique in which programs are written on the
basis of objects
 It is a powerful technique to develop software.
 It is used to analyze and design the application in terms of objects.
 It deals with data and the procedures as a single unit
 Interacting objects handle their own house-keeping.
 Objects in a program interact by sending messages to each other.
 Each object is responsible to initialize and destroy itself.
 There is no need to explicitly call a creation or termination procedure
Features of object-oriented programming
 Data abstraction
the procedure to define a class from objects.
 Encapsulation
A technique for Information Hiding.
 Inheritance
It allows to define a class in terms of another class, which makes it easier
to create and maintain an application.
 Dynamic binding
It determining the method to invoke at runtime instead of at compile time
 Polymorphism
The word polymorphism means having many forms.
Typically, polymorphism occurs when there is a hierarchy of classes and
they are related by inheritance.
Effects of OO methodology on software design
 Maintenance
 Extensibility
 Reusability
Objects
 Object represents an entity in the real world
 Identified by its name
 It consists of two things:
Properties: Characteristics of an object
Functions Actions performed by the object
o Everything is an object
o Systems are composed of objects
 Everything is an object
 A student, a professor
 A desk, a chair, a classroom, a building
 A university, a city, a country
 The world, the universe
 A subject such as CS, IS, Math, History, …
 Systems are composed of objects
 An educational system
 An economic system
 An information system
 A computer system
Design Methodologies
Object-Orientation is a design methodology
 Objects are the building blocks of a program
(interface, editor, menu, file, etc.); data managing
object (db), etc.)
 Objects represent real-world abstractions within an
application.
Properties of Objects
 Characteristics of an object are known as Properties or
attributes of the object
 Each object has its own properties
Example:
 If “Person” is an object, it has following properties
 Name
 Age
 Weight
Object: Car
Properties: Model, Color, Price
Functions of an Object
 Tasks or actions performed by the object are known
as functions or methods.
Classes
 Collection of objects with same
properties and functions
 Use to define characteristics of the
object
 Used as a model for creating different
objects of same type
 Each object of a class is known as an
instance of the class
Declaring a class
 Keyword “class” is used to declare a class
 Declaration specifies:
 Member Variable / Data member
 Function / Member Function
These are common to all objects of that class
Syntax:
class identifier
{
Body of the class
};
Class: is the keyword
Identifier: name of the class to be declared
Access Specifiers
 It specifies the access level of the class members
 Two common access specifiers are:
 Private:
Restrict the use of the class members within the class. It is the default
access specifier. It is used to protect the data members from direct
access from outside the class. Data Member are normally declared with
private access specifier.
 Public
It allows the user to access members within the class as well as outside
the class. It can be accessed from anywhere in the program. Member
functions are normally declared with public access specifier.
Creating objects
 Class is simply a model or prototype for creating objects.
 It is like a new data type that contains both data and
functions.
 Object is created in the same way as other variables are
created.
 Object is also known as instance of a class.
 Process of creating an object is also called instantiation.
Syntax:
class_name object_name;
Class_name: name of the class whose type of object is to be created
Object_name: object to be created.
Executing Member Functions
 Member functions are used to manipulate data
members of a class.
 Member functions can be executed only after
creating objects
Syntax:
Object_name.function();
Object_name: name of object whose member function is to be executed
Function: It is the member function that is need to be executed.
Write a program that
declares a class with a
data member and two
member functions
OUTPUT:
enter number 10
the value of n= 10
Defining member functions outside class
 Function declaration is specified within the class
 Function definition is specified outside the class
 Scope resolution operator :: is used in function declaration if
the function is defined outside the class.
Syntax:
Return_type class_name :: function_name(parameters)
{
function body
}
Return_type type of value to be returned by function
class_name class name to which function belongs
:: scope resoltion operator
function_name name of funtio to be defined
Constructors
 Type of member function that is automatically executed when
an object of that class is created is known as constructor
 It has no return type
 It has same name that of class name
 It work as normal function but cannot return any value
 It is used to initialize data memebrs
Syntax:
name()
{
Constructor body
}
Name: it indicate the name of the constructor
Passing parameters to constructor
 It is same as passing parameters to normal functions
 Only difference is
 Parameters are passed to the constructor when the object is
declared.
Syntax:
type object_name(parameters);
Type: it is the name of the class (type of the object to be declared)
Object_name: name of the object to be declared
Parameter: list of parameters passed to the constructor
Constructor overloading
 Declaring multiple constructors with the same name
but different parameters
 It must differ in one of the following ways
 Number of parameters
 Type of parameter
 Sequence of parameters
Output
the constructor of first=
num = 0
ch = x
the contents of second =
num = 100
ch = p
Default copy constructor
 It is available by default in all classes
 It is used to initialize an object with another object of the
same type.
 User does not need to write this constructor
 It accepts a single object of the same type as parameter.
Syntax:
Class_name object_name(parameter); OR
Class_name object_name = parameter;
Class_name: type of object to be created
Object_name: name of the object
Parameter: name of parameter passed to default constructor
Destructors
 Member function that is automatically executed when an
object of that class is destroyed in known as destructor
 Is has no return type
 Name is same as the class
 It also cannot accept any parameter
 Constructor name proceeded by tilde sign ~
Syntax:
~name()
{
destructor body
}
Objects as function Parameters or Return Type
As parameters:
 Objects can also be passed as parameters to member
functions
 Method is same as passing parameters to other functions
As return type:
 Returning an object from member function is same as
returning a simple variable
 Its return type should be the same as the return type of
the object to be returned.
Static data member
 The type of data member that is shared among all the
objects of the class is known as static data members.
 Defined with static keyword
 If defined static member; only one variable is created in
memory even if there are many objects of that class
 Used to share some data among all objects of a particular
class
 Visible only in the class in which it is defined
 Its lifetime:
 Starts when the program starts its execution
 Ends when the entire program is terminated
Object Oriented Programming Using C++
Difference between normal and static data members
A
B
N
A
B
A
B
A
B
N
1 2
10
100
10
1
200
20
1
1
200n
Object b1 Object b2 Object b2Object b1
Three normal data members
Two normal data members (a,b) and one
static member (n)
Friend Functions
 Function that is allowed to access the private and protected
members of a particular class from outside the class is
called friend functions
 Friend function of a class
 Not a member function
 Has direct access to private members
Just as member functions do
 Use keyword friend in front of
function declaration
 Specified IN class definition
 But they’re NOT member functions!
Friend Classes
 Entire classes can be friends
 Similar to function being friend to class
 Example:
class F is friend of class C
 All class F member functions are friends of C
 NOT reciprocated
 Friendship granted, not taken
Syntax:
friend class F
 Goes inside class definition of "authorizing" class
Static Function
 A function may be declared with the static keyword
 Static functions live at class level, not at object level
 Static functions may access static variables and
methods, but not dynamic ones
Syntax:
public static int getNumSold(){
return numTicketsSold;
}
class test
{
private:
static int n;
public:
static void show()
{
cout<<“n = “<<n;
}
};
int test::n = 10;
void main()
{
test::show();
getch();
}
Output
n = 10
1 . Write a program that creates three objects of a
class student. Each object of the class must be
assigned a unique roll number.
2. Compare OOP & structured programming
Assignment
Ad

More Related Content

What's hot (20)

C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
Bharat Kalia
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Files in c++
Files in c++Files in c++
Files in c++
Selvin Josy Bai Somu
 
structure and union
structure and unionstructure and union
structure and union
student
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
Bharat Kalia
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
structure and union
structure and unionstructure and union
structure and union
student
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 

Viewers also liked (20)

OOP in C++
OOP in C++OOP in C++
OOP in C++
ppd1961
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
nirajmandaliya
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
class c++
class c++class c++
class c++
vinay chauhan
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
Mohamed Loey
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
KurdGul
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
BG Java EE Course
 
Oop l2
Oop l2Oop l2
Oop l2
রাকিন রাকিন
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
Skillwise Group
 
C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++
richards9696
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
Ameen Sha'arawi
 
OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)
Kai-Feng Chou
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part IIIntro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Blue Elephant Consulting
 
Dynamics allocation
Dynamics allocationDynamics allocation
Dynamics allocation
Kumar
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
Fridz Felisco
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
Nitin Jawla
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculation
sandeepkrish2712
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
ppd1961
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
nirajmandaliya
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
Mohamed Loey
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
KurdGul
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
Skillwise Group
 
C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++
richards9696
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
Ameen Sha'arawi
 
OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)OOP in C - Virtual Function (Chinese Version)
OOP in C - Virtual Function (Chinese Version)
Kai-Feng Chou
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part IIIntro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Intro To C++ - Class 06 - Introduction To Classes, Objects, & Strings, Part II
Blue Elephant Consulting
 
Dynamics allocation
Dynamics allocationDynamics allocation
Dynamics allocation
Kumar
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
Fridz Felisco
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
Nitin Jawla
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculation
sandeepkrish2712
 
Ad

Similar to Object Oriented Programming Using C++ (20)

Oops
OopsOops
Oops
Sankar Balasubramanian
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
My c++
My c++My c++
My c++
snathick
 
Oops
OopsOops
Oops
Jaya Kumari
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
basic concepts of object oriented programming
basic concepts of object oriented programmingbasic concepts of object oriented programming
basic concepts of object oriented programming
infotechsaasc
 
oopusingc.pptx
oopusingc.pptxoopusingc.pptx
oopusingc.pptx
MohammedAlobaidy16
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
Dr. SURBHI SAROHA
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.pptClasses in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Lab 4 (1).pdf
Lab 4 (1).pdfLab 4 (1).pdf
Lab 4 (1).pdf
MohammedAlobaidy16
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
rumanatasnim415
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
lykado0dles
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
Karudaiyar Ganapathy
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
basic concepts of object oriented programming
basic concepts of object oriented programmingbasic concepts of object oriented programming
basic concepts of object oriented programming
infotechsaasc
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.pptClasses in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
lykado0dles
 
Ad

More from Muhammad Waqas (9)

Image processing (Signal Processing)
Image processing (Signal Processing)Image processing (Signal Processing)
Image processing (Signal Processing)
Muhammad Waqas
 
Windows 98 vs Windows 200
Windows 98 vs Windows 200Windows 98 vs Windows 200
Windows 98 vs Windows 200
Muhammad Waqas
 
Introduction to CPU registers
Introduction to CPU registersIntroduction to CPU registers
Introduction to CPU registers
Muhammad Waqas
 
Six exercises to relieve back pain at your workplace
Six exercises to relieve back pain at your workplaceSix exercises to relieve back pain at your workplace
Six exercises to relieve back pain at your workplace
Muhammad Waqas
 
Engineering Numerical Analysis Lecture-1
Engineering Numerical Analysis Lecture-1Engineering Numerical Analysis Lecture-1
Engineering Numerical Analysis Lecture-1
Muhammad Waqas
 
Chapter7 Computer Networks
Chapter7 Computer NetworksChapter7 Computer Networks
Chapter7 Computer Networks
Muhammad Waqas
 
Chapter5 Storage
Chapter5 StorageChapter5 Storage
Chapter5 Storage
Muhammad Waqas
 
Chapter4 Data Processing
Chapter4 Data ProcessingChapter4 Data Processing
Chapter4 Data Processing
Muhammad Waqas
 
Chapter1 introduction to computer systems
Chapter1 introduction to computer systemsChapter1 introduction to computer systems
Chapter1 introduction to computer systems
Muhammad Waqas
 
Image processing (Signal Processing)
Image processing (Signal Processing)Image processing (Signal Processing)
Image processing (Signal Processing)
Muhammad Waqas
 
Windows 98 vs Windows 200
Windows 98 vs Windows 200Windows 98 vs Windows 200
Windows 98 vs Windows 200
Muhammad Waqas
 
Introduction to CPU registers
Introduction to CPU registersIntroduction to CPU registers
Introduction to CPU registers
Muhammad Waqas
 
Six exercises to relieve back pain at your workplace
Six exercises to relieve back pain at your workplaceSix exercises to relieve back pain at your workplace
Six exercises to relieve back pain at your workplace
Muhammad Waqas
 
Engineering Numerical Analysis Lecture-1
Engineering Numerical Analysis Lecture-1Engineering Numerical Analysis Lecture-1
Engineering Numerical Analysis Lecture-1
Muhammad Waqas
 
Chapter7 Computer Networks
Chapter7 Computer NetworksChapter7 Computer Networks
Chapter7 Computer Networks
Muhammad Waqas
 
Chapter4 Data Processing
Chapter4 Data ProcessingChapter4 Data Processing
Chapter4 Data Processing
Muhammad Waqas
 
Chapter1 introduction to computer systems
Chapter1 introduction to computer systemsChapter1 introduction to computer systems
Chapter1 introduction to computer systems
Muhammad Waqas
 

Recently uploaded (20)

World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 

Object Oriented Programming Using C++

  • 2. Contents  Features of OOP  Classes  Objects & Creating the Objects  Constructors & Destructors  Friend Functions & Classes  Static data members & functions
  • 3. OOP  It is programming technique in which programs are written on the basis of objects  It is a powerful technique to develop software.  It is used to analyze and design the application in terms of objects.  It deals with data and the procedures as a single unit  Interacting objects handle their own house-keeping.  Objects in a program interact by sending messages to each other.  Each object is responsible to initialize and destroy itself.  There is no need to explicitly call a creation or termination procedure
  • 4. Features of object-oriented programming  Data abstraction the procedure to define a class from objects.  Encapsulation A technique for Information Hiding.  Inheritance It allows to define a class in terms of another class, which makes it easier to create and maintain an application.  Dynamic binding It determining the method to invoke at runtime instead of at compile time  Polymorphism The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.
  • 5. Effects of OO methodology on software design  Maintenance  Extensibility  Reusability
  • 6. Objects  Object represents an entity in the real world  Identified by its name  It consists of two things: Properties: Characteristics of an object Functions Actions performed by the object o Everything is an object o Systems are composed of objects
  • 7.  Everything is an object  A student, a professor  A desk, a chair, a classroom, a building  A university, a city, a country  The world, the universe  A subject such as CS, IS, Math, History, …  Systems are composed of objects  An educational system  An economic system  An information system  A computer system
  • 8. Design Methodologies Object-Orientation is a design methodology  Objects are the building blocks of a program (interface, editor, menu, file, etc.); data managing object (db), etc.)  Objects represent real-world abstractions within an application.
  • 9. Properties of Objects  Characteristics of an object are known as Properties or attributes of the object  Each object has its own properties Example:  If “Person” is an object, it has following properties  Name  Age  Weight Object: Car Properties: Model, Color, Price
  • 10. Functions of an Object  Tasks or actions performed by the object are known as functions or methods.
  • 11. Classes  Collection of objects with same properties and functions  Use to define characteristics of the object  Used as a model for creating different objects of same type  Each object of a class is known as an instance of the class
  • 12. Declaring a class  Keyword “class” is used to declare a class  Declaration specifies:  Member Variable / Data member  Function / Member Function These are common to all objects of that class Syntax: class identifier { Body of the class }; Class: is the keyword Identifier: name of the class to be declared
  • 13. Access Specifiers  It specifies the access level of the class members  Two common access specifiers are:  Private: Restrict the use of the class members within the class. It is the default access specifier. It is used to protect the data members from direct access from outside the class. Data Member are normally declared with private access specifier.  Public It allows the user to access members within the class as well as outside the class. It can be accessed from anywhere in the program. Member functions are normally declared with public access specifier.
  • 14. Creating objects  Class is simply a model or prototype for creating objects.  It is like a new data type that contains both data and functions.  Object is created in the same way as other variables are created.  Object is also known as instance of a class.  Process of creating an object is also called instantiation. Syntax: class_name object_name; Class_name: name of the class whose type of object is to be created Object_name: object to be created.
  • 15. Executing Member Functions  Member functions are used to manipulate data members of a class.  Member functions can be executed only after creating objects Syntax: Object_name.function(); Object_name: name of object whose member function is to be executed Function: It is the member function that is need to be executed.
  • 16. Write a program that declares a class with a data member and two member functions OUTPUT: enter number 10 the value of n= 10
  • 17. Defining member functions outside class  Function declaration is specified within the class  Function definition is specified outside the class  Scope resolution operator :: is used in function declaration if the function is defined outside the class. Syntax: Return_type class_name :: function_name(parameters) { function body } Return_type type of value to be returned by function class_name class name to which function belongs :: scope resoltion operator function_name name of funtio to be defined
  • 18. Constructors  Type of member function that is automatically executed when an object of that class is created is known as constructor  It has no return type  It has same name that of class name  It work as normal function but cannot return any value  It is used to initialize data memebrs Syntax: name() { Constructor body } Name: it indicate the name of the constructor
  • 19. Passing parameters to constructor  It is same as passing parameters to normal functions  Only difference is  Parameters are passed to the constructor when the object is declared. Syntax: type object_name(parameters); Type: it is the name of the class (type of the object to be declared) Object_name: name of the object to be declared Parameter: list of parameters passed to the constructor
  • 20. Constructor overloading  Declaring multiple constructors with the same name but different parameters  It must differ in one of the following ways  Number of parameters  Type of parameter  Sequence of parameters
  • 21. Output the constructor of first= num = 0 ch = x the contents of second = num = 100 ch = p
  • 22. Default copy constructor  It is available by default in all classes  It is used to initialize an object with another object of the same type.  User does not need to write this constructor  It accepts a single object of the same type as parameter. Syntax: Class_name object_name(parameter); OR Class_name object_name = parameter; Class_name: type of object to be created Object_name: name of the object Parameter: name of parameter passed to default constructor
  • 23. Destructors  Member function that is automatically executed when an object of that class is destroyed in known as destructor  Is has no return type  Name is same as the class  It also cannot accept any parameter  Constructor name proceeded by tilde sign ~ Syntax: ~name() { destructor body }
  • 24. Objects as function Parameters or Return Type As parameters:  Objects can also be passed as parameters to member functions  Method is same as passing parameters to other functions As return type:  Returning an object from member function is same as returning a simple variable  Its return type should be the same as the return type of the object to be returned.
  • 25. Static data member  The type of data member that is shared among all the objects of the class is known as static data members.  Defined with static keyword  If defined static member; only one variable is created in memory even if there are many objects of that class  Used to share some data among all objects of a particular class  Visible only in the class in which it is defined  Its lifetime:  Starts when the program starts its execution  Ends when the entire program is terminated
  • 27. Difference between normal and static data members A B N A B A B A B N 1 2 10 100 10 1 200 20 1 1 200n Object b1 Object b2 Object b2Object b1 Three normal data members Two normal data members (a,b) and one static member (n)
  • 28. Friend Functions  Function that is allowed to access the private and protected members of a particular class from outside the class is called friend functions  Friend function of a class  Not a member function  Has direct access to private members Just as member functions do  Use keyword friend in front of function declaration  Specified IN class definition  But they’re NOT member functions!
  • 29. Friend Classes  Entire classes can be friends  Similar to function being friend to class  Example: class F is friend of class C  All class F member functions are friends of C  NOT reciprocated  Friendship granted, not taken Syntax: friend class F  Goes inside class definition of "authorizing" class
  • 30. Static Function  A function may be declared with the static keyword  Static functions live at class level, not at object level  Static functions may access static variables and methods, but not dynamic ones Syntax: public static int getNumSold(){ return numTicketsSold; }
  • 31. class test { private: static int n; public: static void show() { cout<<“n = “<<n; } }; int test::n = 10; void main() { test::show(); getch(); } Output n = 10
  • 32. 1 . Write a program that creates three objects of a class student. Each object of the class must be assigned a unique roll number. 2. Compare OOP & structured programming Assignment