尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Object Oriented Programming
(OOP)
Lecture
3
Object Oriented Programming
(OOP)
 OOP uses the concept of Objects
(Object Oriented), Objects (of classes)
may contain data members and member
functions
 A program is divided into classes in OOP
 Classes contain data members and
member functions (data members and
member functions are combined in
classes)
 Objects (like variables) are declared (and
used) for classes
Classes …
 A class is an extensible program-
code-template for creating objects,
providing initial values for state
(member variables) and
implementations of behavior (member
functions or methods).
 A collection of data and functions
(both defined within the class).
Functions work upon data with unique
relation of data items in the class
Classes …
 Classes enable the programmer to
Model objects that have attributes
(data members) and behaviors
(functions)
 Once a class is defined, its name can
be used as a type name (like int, char)
and its objects (variable) can be
created
OOP and Classes
 Program is divided into classes (for
making it OO)
 Why? easy to design and organize
program (like functions, but more
convenient in case of classes)
 C++ Supports OOP
Defining a Class
• Syntax of a class is similar to that of
structure (record)
• class keyword is used in defining class
(same like struct is used for defining
structure)
class cname
{
Body of the class (members)
};
• Naming the class is same as naming
variable
Defining a Class
• Body of the class consists of
1) Member Data items (Data Members)
2) Member Functions
 Data members may be of different
types name and numbers and may be
related to each others in one class
 Members functions are usually user
defined functions that operates on
data members of the same class
Data Members of a Class
 Data Items used in the class
class abcd
{
int a, b, c, d;
float x, y;
Function ()
{ body of the function }
};
• a, b, c, d, x and y are the data members
of class abcd
Member functions of a Class
 Functions of the class for working with
data members of the class
 May be defined within or outside the
classclass abcd
{
private:
int a, b, c, d;
float x, y;
public:
void putndisp(void)
{
cout<<“enter values of
a,b,c and d”;
cin>>a>>b>>c;
Cout<<“a=“<<a<<endl;
cout<<“b=“<<b<<endl;
cout<<“c=“<<c;
}
};
Defining Function (Revision
…..)
 A set of instructions designed to perform a
specific task (complete independent program)
 Functions have two main uses
i. It divide large program to small units for
easy follow up
ii. It avoids the replication of code, a code
(piece of program) needed several times is
not written again and again and its function
is used (called) instead.
 Some functions are built-in while user can
define others also known as user defined
functions
User Defined Functions
 The set of instructions written by user
as a part of program for a specific task
is user defined function
 User defined function has mainly three
parts
1. Function Declaration (prototype)
2. Function Definition
3. Function Calling
Function Declaration
 It is also called prototype which mean
sample or model (provides the model of
function)
 Three information are provided to the
complier about function
1. Name of the function
2. The data type returned by the function
3. The number and types of arguments or
parameters used in the function
type function_name (arguments);
Function Definition
 The actual code of the function is called
function definition
 Can be written in separate file then included
as a directive
 Function declaration has mainly two parts
1. Declarator
2. Body of the function
type function_name (parameters) //declarator
{
set of statements //body
}
Calling Function
 Function is called for its execution
 Function is called by (referencing) its
name with parameters in the
parenthesis
 In OOP, the function of a class is
called through its object using dot (.)
operator
Member Access Specifiers of the
Class
 Data or function can or can’t be
accessed from outside the class
depends on access specifier
 Declaring data inaccessible from
outside the class is called data hiding
(an important property of OOP)
Member Access Specifiers
 Access Specifiers are:
 Private Specifiers
 Public Specifiers
 Protected Specifiers
Syntax:
class abcd
{
private:
int a, b, c, d;
float x, y;
public:
void putndisp (void)
{
Body of the function
}
};
Once a specifier used will declare
all the following members as
specified until declared in next
Private Specifier
 can be accessed from within the class
only
 can’t be accessed from outside the
class
 usually data members are declared
private (and function as not private)
 member functions if declared private
can’t be accessed from outside which is
usually needed to be accessed (called)
from outside
 private specifier is the default specifier
i.e. if no access specifier mentioned for a
Public Specifier
 Data and or function declared as
public can be accessed both from
inside and outside the class
 Usually member functions are
declared as public to be used in the
whole program where needed
 Data members can be also declared
as public but usually declared as
private
#include<iostream.h>
#include<conio.h>
class cdate
{
private:
long y, d, m;
public:
void gdate (void)
{
cout <<"year? "; cin>>y;
cout <<"month? ";
cin>>m;
cout <<"day? "; cin >>d;
}
void pdate (void)
{
cout<<"your given
date is.. "<< d<<"/“
<<m <<"/"<<y;
}
};
main ()
{
clrscr ();
cdate crea;
crea.gdate ();
crea.pdate ();
getch ();
return 0;
}
Objects
 Class as a data type (template for
variable)
 Variable is declared using data type
 Variable is the instance or case of data type
 Data types (int, float, long etc.) do not occupy space but its
variable occupies space in the memory after declaration
 Same like data type class (as template)
is used to declare variable or instances
 The instances, case and variable (or
object) of class is called “object”
 (Like data type,) class encapsulate data
members and member functions
(encapsulation: an important aspect of
Declaring Objects
 Objects are declared as variables are
declared
 Memory reserved after object
declaration for a class
Class_name Object1, Object2, ..., objectn;
class class1
{
private:
long y, d, m;
public:
void function1 (void)
{
Body of the function
}
void function2 (void)
{
Body of the function
}
};
main ()
{
cdate object1;
object1.function1 ();
object1.function2 ();
}
Calling member function
 Dot operator (.) is used for calling
member function of a class (for
execution)
 Syntax:
Object_name.member(arguments(if any))
e.g.
object1.function1 ();
object1.function2 ();
OOP, Classes, Objects
 Lab Task
 Write a Program that uses two
functions inside classes for adding
and displaying a set of numbers

More Related Content

What's hot

Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Harsh Patel
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Shailendra Veeru
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
Jeff TUYISHIME
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
Hoang Nguyen
 
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
UniSoftCorner Pvt Ltd India.
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
rajveer_Pannu
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
ahmed hmed
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
Fajar Baskoro
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
NainaKhan28
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++
fasalsial1fasalsial1
 
class c++
class c++class c++
class c++
vinay chauhan
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
Sohanur63
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 

What's hot (20)

Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Object and class
Object and classObject and class
Object and class
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
C++ classes
C++ classesC++ classes
C++ classes
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++
 
class c++
class c++class c++
class c++
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 

Similar to oop lecture 3

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
zahid khan
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
study material
 
My c++
My c++My c++
My c++
snathick
 
C++ Notes
C++ NotesC++ Notes
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
Rai University
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
Rai University
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
SURBHI SAROHA
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classes
rsnyder3601
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
trixiacruz
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
Shweta Shah
 

Similar to oop lecture 3 (20)

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
My c++
My c++My c++
My c++
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
Class and object
Class and objectClass and object
Class and object
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classes
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
Class and object
Class and objectClass and object
Class and object
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
 

Recently uploaded

Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
Celine George
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
Nguyen Thanh Tu Collection
 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
khabri85
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
Kalna College
 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Catherine Dela Cruz
 
Diversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT KanpurDiversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
Infosec
 
What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17
Celine George
 
Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
Ben Aldrich
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
Quizzito The Quiz Society of Gargi College
 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
Celine George
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
(T.L.E.) Agriculture: "Ornamental Plants"
(T.L.E.) Agriculture: "Ornamental Plants"(T.L.E.) Agriculture: "Ornamental Plants"
(T.L.E.) Agriculture: "Ornamental Plants"
MJDuyan
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
RuchiRathor2
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...
chaudharyreet2244
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
PJ Caposey
 

Recently uploaded (20)

Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
 
Diversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT KanpurDiversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT Kanpur
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
 
What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17
 
Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
(T.L.E.) Agriculture: "Ornamental Plants"
(T.L.E.) Agriculture: "Ornamental Plants"(T.L.E.) Agriculture: "Ornamental Plants"
(T.L.E.) Agriculture: "Ornamental Plants"
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
 

oop lecture 3

  • 2. Object Oriented Programming (OOP)  OOP uses the concept of Objects (Object Oriented), Objects (of classes) may contain data members and member functions  A program is divided into classes in OOP  Classes contain data members and member functions (data members and member functions are combined in classes)  Objects (like variables) are declared (and used) for classes
  • 3. Classes …  A class is an extensible program- code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).  A collection of data and functions (both defined within the class). Functions work upon data with unique relation of data items in the class
  • 4. Classes …  Classes enable the programmer to Model objects that have attributes (data members) and behaviors (functions)  Once a class is defined, its name can be used as a type name (like int, char) and its objects (variable) can be created
  • 5. OOP and Classes  Program is divided into classes (for making it OO)  Why? easy to design and organize program (like functions, but more convenient in case of classes)  C++ Supports OOP
  • 6. Defining a Class • Syntax of a class is similar to that of structure (record) • class keyword is used in defining class (same like struct is used for defining structure) class cname { Body of the class (members) }; • Naming the class is same as naming variable
  • 7. Defining a Class • Body of the class consists of 1) Member Data items (Data Members) 2) Member Functions  Data members may be of different types name and numbers and may be related to each others in one class  Members functions are usually user defined functions that operates on data members of the same class
  • 8. Data Members of a Class  Data Items used in the class class abcd { int a, b, c, d; float x, y; Function () { body of the function } }; • a, b, c, d, x and y are the data members of class abcd
  • 9. Member functions of a Class  Functions of the class for working with data members of the class  May be defined within or outside the classclass abcd { private: int a, b, c, d; float x, y; public: void putndisp(void) { cout<<“enter values of a,b,c and d”; cin>>a>>b>>c; Cout<<“a=“<<a<<endl; cout<<“b=“<<b<<endl; cout<<“c=“<<c; } };
  • 10. Defining Function (Revision …..)  A set of instructions designed to perform a specific task (complete independent program)  Functions have two main uses i. It divide large program to small units for easy follow up ii. It avoids the replication of code, a code (piece of program) needed several times is not written again and again and its function is used (called) instead.  Some functions are built-in while user can define others also known as user defined functions
  • 11. User Defined Functions  The set of instructions written by user as a part of program for a specific task is user defined function  User defined function has mainly three parts 1. Function Declaration (prototype) 2. Function Definition 3. Function Calling
  • 12. Function Declaration  It is also called prototype which mean sample or model (provides the model of function)  Three information are provided to the complier about function 1. Name of the function 2. The data type returned by the function 3. The number and types of arguments or parameters used in the function type function_name (arguments);
  • 13. Function Definition  The actual code of the function is called function definition  Can be written in separate file then included as a directive  Function declaration has mainly two parts 1. Declarator 2. Body of the function type function_name (parameters) //declarator { set of statements //body }
  • 14. Calling Function  Function is called for its execution  Function is called by (referencing) its name with parameters in the parenthesis  In OOP, the function of a class is called through its object using dot (.) operator
  • 15. Member Access Specifiers of the Class  Data or function can or can’t be accessed from outside the class depends on access specifier  Declaring data inaccessible from outside the class is called data hiding (an important property of OOP)
  • 16. Member Access Specifiers  Access Specifiers are:  Private Specifiers  Public Specifiers  Protected Specifiers Syntax: class abcd { private: int a, b, c, d; float x, y; public: void putndisp (void) { Body of the function } }; Once a specifier used will declare all the following members as specified until declared in next
  • 17. Private Specifier  can be accessed from within the class only  can’t be accessed from outside the class  usually data members are declared private (and function as not private)  member functions if declared private can’t be accessed from outside which is usually needed to be accessed (called) from outside  private specifier is the default specifier i.e. if no access specifier mentioned for a
  • 18. Public Specifier  Data and or function declared as public can be accessed both from inside and outside the class  Usually member functions are declared as public to be used in the whole program where needed  Data members can be also declared as public but usually declared as private
  • 19. #include<iostream.h> #include<conio.h> class cdate { private: long y, d, m; public: void gdate (void) { cout <<"year? "; cin>>y; cout <<"month? "; cin>>m; cout <<"day? "; cin >>d; } void pdate (void) { cout<<"your given date is.. "<< d<<"/“ <<m <<"/"<<y; } }; main () { clrscr (); cdate crea; crea.gdate (); crea.pdate (); getch (); return 0; }
  • 20. Objects  Class as a data type (template for variable)  Variable is declared using data type  Variable is the instance or case of data type  Data types (int, float, long etc.) do not occupy space but its variable occupies space in the memory after declaration  Same like data type class (as template) is used to declare variable or instances  The instances, case and variable (or object) of class is called “object”  (Like data type,) class encapsulate data members and member functions (encapsulation: an important aspect of
  • 21. Declaring Objects  Objects are declared as variables are declared  Memory reserved after object declaration for a class Class_name Object1, Object2, ..., objectn; class class1 { private: long y, d, m; public: void function1 (void) { Body of the function } void function2 (void) { Body of the function } }; main () { cdate object1; object1.function1 (); object1.function2 (); }
  • 22. Calling member function  Dot operator (.) is used for calling member function of a class (for execution)  Syntax: Object_name.member(arguments(if any)) e.g. object1.function1 (); object1.function2 ();
  • 23. OOP, Classes, Objects  Lab Task  Write a Program that uses two functions inside classes for adding and displaying a set of numbers
  翻译: