UNIT 1
LECTURE 2LECTURE 2
Title : Object Oriented Programming
Subject Code : 3XT03
Semester : Third
Department : Electronics & Telecommunication Engineering
Prof. Avinash S. Kapse
Contents
Introduction to classes and object.
Declaration of class and objects.
Structure of C++ class.
Prof. Avinash S. Kapse
Last Lecture Review
In last lecture, we have seen following points:
Structure of
C++ program
Variable
s in C++
Input and Output
Statements
Prof. Avinash S. Kapse
Objectives
After completing this lecture, you will
come to know and understand the
following points:
After completing this lecture, you will
come to know and understand the
following points:
Classes and ObjectClasses and Object
Structure of
C++ class
Structure of
C++ class
Access Specifier
Scope Resolution
Operator
Prof. Avinash S. Kapse
Classes and Object
A class is an expanded concept of a data structure: instead
of holding only data, it can hold both data and functions.
An object is an instantiation of a class. In terms of
variables, a class would be the type, and an object would be the
variable.
Classes are generally declared using the keyword class,
with the format which is given on next slide:
Prof. Avinash S. Kapse
Cont…
class class_name
{
access_specifier_1:
member1;
access_specifier_2:
member2;
...
} object_names;
class_name:- This is a valid identifier for the class.
object_names:- This is an optional list of names for objects of this
class.
Prof. Avinash S. Kapse
Cont…
The body of the declaration can contain members, that can
be either data or function declarations, and optionally access
specifiers.
Access specifiers modify the access rights that the members
following them acquire:
• private
• protected
• public
Prof. Avinash S. Kapse
Cont…
private members of a class are accessible only from within
other members of the same class or from their friends.
protected members are accessible from members of their
same class and from their friends, but also from members of their
derived classes.
public members are accessible from anywhere where the
object is visible.
Prof. Avinash S. Kapse
Cont…
By default, all members of a class declared with the class
keyword have private access for all its members. Therefore, any
member that is declared before one other class specifier
automatically has private access. For example:
class CRectangle
{
int x, y;
public:
void set_values (int,int);
int area (void);
} rect;
Prof. Avinash S. Kapse
Cont…
Declares a class (i.e., a type) called CRectangle and an
object (i.e., a variable) of this class called rect. This class contains
four members: two data members of type int (member x and
member y) with private access (because private is the default
access level) and two member functions with public access:
set_values() and area(), of which for now we have only included
their declaration, not their definition.
Prof. Avinash S. Kapse
Objects
1. An object is an instance of class. An object is a thing like
vehicle, employee or anything.
2. An object consist of data and operations that manipulate those
data i.e. methods.
3. Syntax:
class_name object1, object2……..objectN;
where class_name is name of the class to which object belong and
object1, object2…..objectN are objects.
Prof. Avinash S. Kapse
Example
// classes example
#include <iostream.h>
class Crectangle
{
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
Header File
Class Declaration
Access Specifier
Function declaration
Prof. Avinash S. Kapse
Example 1
void Crectangle :: set_values (int a, int b)
{
x = a;
y = b;
}
main () {
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
}
Function definition
with two parameters a
and b
Object rect has been
created of class
CRectangle
Prof. Avinash S. Kapse
Explanation
The most important new thing in this code is the operator of
scope (::, two colons) included in the definition of set_values(). It is used
to define a member of a class from outside the class definition itself.
You may notice that the definition of the member function area()
has been included directly within the definition of the CRectangle class.
Note:- When we want to declare a function inside a class and definition
outside the class then use :: (Scope Resolution Operator).
Prof. Avinash S. Kapse
Cont…
1. Members x and y have private access.
2. By declaring them private we deny access to them from
anywhere outside the class.
3. CRectangle rect; This statement is used to create object rect of
class Crectangle.
4. rect.set_values (3,4); This statement is used to call a function
i.e. set_values(3,4). 3 is assigned to a and 4 is assigned to b
where a and b are parameters of function set_values().
Prof. Avinash S. Kapse
Example 2
#include <iostream.h>
class MyClass
{
int a,b;
void getData(int x, int y)
{
a=x;
b=y;
}
Function definition
with two parameters x
and y
Prof. Avinash S. Kapse
Cont…
void putData( )
{
cout<<“ a = ” <<a<<endl;
cout<<“ b = ” <<b<<endl;
}
};
void main () {
MyClass m1,m2;
m1.getData(5,10);
This function will
display the value of a
and b
Two objects have been
created i.e. m1 and m2
getData( ) function is
called with object m1.
Prof. Avinash S. Kapse
Cont…
m1.putData();
m2.getData(15,100);
m2.putData();
}
Output of the above program:
a = 5
b = 10
a = 15
b= 100
putData( ) function is
called with object m1.
getData( ) and
putData( ) function is
called with object m2.
Prof. Avinash S. Kapse
Example 3
WAP to accept and print student Roll Number and Name of a Student.
#include <iostream.h>
class MyStudent
{
int rollno;
char name[25];
void getData()
{
cout<<“Enter Roll Number and Name of a Student”<<endl;
cin>>rollno>>name;
}
Prof. Avinash S. Kapse
Cont…
void putData()
{
cout<<“ Roll Number : ” <<rollno<<endl;
cout<<“ Name of Student : ” <<name<<endl;
}
};
void main () {
MyStudent s1;
s1.getData();
s1.putData();
}
Prof. Avinash S. Kapse
Cont…
Output of the above program:
Enter Roll Number and Name of a Student
36 Bajirao Singham
Roll Number : 36
Name of Student: Bajirao Singham
Prof. Avinash S. Kapse
Exercise
1. WAP to read five numbers from user and calculate average.
2. WAP to calculate simple interest.
3. WAP to calculate percentage of a student by reading marks of
five subjects and maximum marks for each subject is 100.
Prof. Avinash S. Kapse
Home Work
1. What is object oriented programming?
2. What is polymorphism OOP?
3. What is Encapsulation OOP?
4. What is Inheritance OOP? Explain their types.
Prof. Avinash S. Kapse

More Related Content

PPTX
Java Foundations: Objects and Classes
PPTX
Unit ii
PPTX
Java Foundations: Data Types and Type Conversion
PPTX
Data structures using C
PPTX
11. Objects and Classes
PPT
C++ classes tutorials
PDF
Constructors destructors
PPTX
Constructor in java
Java Foundations: Objects and Classes
Unit ii
Java Foundations: Data Types and Type Conversion
Data structures using C
11. Objects and Classes
C++ classes tutorials
Constructors destructors
Constructor in java

What's hot (19)

PPT
Class & Object - Intro
PDF
Inheritance
PPTX
constructor with default arguments and dynamic initialization of objects
PPTX
classes and objects in C++
PDF
Constructor and Destructor
PDF
Constructors and destructors
PPTX
Java Foundations: Basic Syntax, Conditions, Loops
PDF
Constructors and Destructors
PPTX
Functions, classes & objects in c++
PPTX
Chapter 13 introduction to classes
PPTX
Chapter 6.6
PPTX
PPT
Class & Object - User Defined Method
PPTX
14 Defining Classes
PPTX
constructor & destructor in cpp
DOCX
Java assignment 1
PPTX
SPF Getting Started - Console Program
PPT
C++ tutorials
PPTX
Class & Object - Intro
Inheritance
constructor with default arguments and dynamic initialization of objects
classes and objects in C++
Constructor and Destructor
Constructors and destructors
Java Foundations: Basic Syntax, Conditions, Loops
Constructors and Destructors
Functions, classes & objects in c++
Chapter 13 introduction to classes
Chapter 6.6
Class & Object - User Defined Method
14 Defining Classes
constructor & destructor in cpp
Java assignment 1
SPF Getting Started - Console Program
C++ tutorials

Similar to Lecture 2 (20)

PDF
Lab 4 (1).pdf
PPTX
oopusingc.pptx
PPTX
Introduction to Class a deep analysisadfas
PPT
classes data type for Btech students.ppt
PPTX
C++ppt. Classs and object, class and object
PPTX
Classes and objects
PDF
Object Oriented Programming using C++ - Part 2
PPTX
Concept of Object-Oriented in C++
PDF
Object Oriented Programming Constructors & Destructors
PDF
Implementation of oop concept in c++
PPSX
Arre tari mano bhosko ka pikina tari ma no piko
PPTX
Classes and objects
PDF
Class and object
PPTX
Oop objects_classes
PPTX
object oriented programming-classes and objects.pptx
PDF
Introduction to C++ Class & Objects. Book Notes
PDF
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
PPTX
class c++
PPTX
Classes and objects1
Lab 4 (1).pdf
oopusingc.pptx
Introduction to Class a deep analysisadfas
classes data type for Btech students.ppt
C++ppt. Classs and object, class and object
Classes and objects
Object Oriented Programming using C++ - Part 2
Concept of Object-Oriented in C++
Object Oriented Programming Constructors & Destructors
Implementation of oop concept in c++
Arre tari mano bhosko ka pikina tari ma no piko
Classes and objects
Class and object
Oop objects_classes
object oriented programming-classes and objects.pptx
Introduction to C++ Class & Objects. Book Notes
classandobjectunit2-150824133722-lva1-app6891.ppt
class c++
Classes and objects1

More from Avinash Kapse (9)

PDF
Presentation1
PDF
Presentation1
PPTX
SS UII Lecture 1
PPTX
SS UI Lecture 5
PPTX
SS UI Lecture 6
PPTX
SS UI Lecture 4
PPTX
SS UI Lecture 1
PPTX
Ss ui lecture 2
PPTX
Ss ui lecture 1
Presentation1
Presentation1
SS UII Lecture 1
SS UI Lecture 5
SS UI Lecture 6
SS UI Lecture 4
SS UI Lecture 1
Ss ui lecture 2
Ss ui lecture 1

Recently uploaded (20)

PDF
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
PPTX
Juvenile delinquency-Crim Research day 3x
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PPTX
Entrepreneurship Management and Finance - Module 1 - PPT
PDF
Jana Ojana 2025 Prelims - School Quiz by Pragya - UEMK Quiz Club
PPTX
macro complete discussion with given activities
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PPTX
Approach to a child with acute kidney injury
PDF
The 10 Most Inspiring Education Leaders to Follow in 2025.pdf
PPSX
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
PDF
Teacher's Day Quiz 2025
PDF
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
PDF
V02-Session-4-Leadership-Through-Assessment-MLB.pdf
PPTX
climate change of delhi impacts on climate and there effects
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
PPTX
Ppt obs emergecy.pptxydirnbduejguxjjdjidjdbuc
PDF
FAMILY PLANNING (preventative and social medicine pdf)
PPTX
Single Visit Endodontics.pptx treatment in one visit
PDF
Physical pharmaceutics two in b pharmacy
PDF
New_Round_Up_6_SB.pdf download for free, easy to learn
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
Juvenile delinquency-Crim Research day 3x
MMW-CHAPTER-1-final.pptx major Elementary Education
Entrepreneurship Management and Finance - Module 1 - PPT
Jana Ojana 2025 Prelims - School Quiz by Pragya - UEMK Quiz Club
macro complete discussion with given activities
hsl powerpoint resource goyloveh feb 07.ppt
Approach to a child with acute kidney injury
The 10 Most Inspiring Education Leaders to Follow in 2025.pdf
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
Teacher's Day Quiz 2025
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
V02-Session-4-Leadership-Through-Assessment-MLB.pdf
climate change of delhi impacts on climate and there effects
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
Ppt obs emergecy.pptxydirnbduejguxjjdjidjdbuc
FAMILY PLANNING (preventative and social medicine pdf)
Single Visit Endodontics.pptx treatment in one visit
Physical pharmaceutics two in b pharmacy
New_Round_Up_6_SB.pdf download for free, easy to learn

Lecture 2

  • 1. UNIT 1 LECTURE 2LECTURE 2 Title : Object Oriented Programming Subject Code : 3XT03 Semester : Third Department : Electronics & Telecommunication Engineering Prof. Avinash S. Kapse
  • 2. Contents Introduction to classes and object. Declaration of class and objects. Structure of C++ class. Prof. Avinash S. Kapse
  • 3. Last Lecture Review In last lecture, we have seen following points: Structure of C++ program Variable s in C++ Input and Output Statements Prof. Avinash S. Kapse
  • 4. Objectives After completing this lecture, you will come to know and understand the following points: After completing this lecture, you will come to know and understand the following points: Classes and ObjectClasses and Object Structure of C++ class Structure of C++ class Access Specifier Scope Resolution Operator Prof. Avinash S. Kapse
  • 5. Classes and Object A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable. Classes are generally declared using the keyword class, with the format which is given on next slide: Prof. Avinash S. Kapse
  • 6. Cont… class class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names; class_name:- This is a valid identifier for the class. object_names:- This is an optional list of names for objects of this class. Prof. Avinash S. Kapse
  • 7. Cont… The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers. Access specifiers modify the access rights that the members following them acquire: • private • protected • public Prof. Avinash S. Kapse
  • 8. Cont… private members of a class are accessible only from within other members of the same class or from their friends. protected members are accessible from members of their same class and from their friends, but also from members of their derived classes. public members are accessible from anywhere where the object is visible. Prof. Avinash S. Kapse
  • 9. Cont… By default, all members of a class declared with the class keyword have private access for all its members. Therefore, any member that is declared before one other class specifier automatically has private access. For example: class CRectangle { int x, y; public: void set_values (int,int); int area (void); } rect; Prof. Avinash S. Kapse
  • 10. Cont… Declares a class (i.e., a type) called CRectangle and an object (i.e., a variable) of this class called rect. This class contains four members: two data members of type int (member x and member y) with private access (because private is the default access level) and two member functions with public access: set_values() and area(), of which for now we have only included their declaration, not their definition. Prof. Avinash S. Kapse
  • 11. Objects 1. An object is an instance of class. An object is a thing like vehicle, employee or anything. 2. An object consist of data and operations that manipulate those data i.e. methods. 3. Syntax: class_name object1, object2……..objectN; where class_name is name of the class to which object belong and object1, object2…..objectN are objects. Prof. Avinash S. Kapse
  • 12. Example // classes example #include <iostream.h> class Crectangle { int x, y; public: void set_values (int,int); int area () {return (x*y);} }; Header File Class Declaration Access Specifier Function declaration Prof. Avinash S. Kapse
  • 13. Example 1 void Crectangle :: set_values (int a, int b) { x = a; y = b; } main () { CRectangle rect; rect.set_values (3,4); cout << "area: " << rect.area(); } Function definition with two parameters a and b Object rect has been created of class CRectangle Prof. Avinash S. Kapse
  • 14. Explanation The most important new thing in this code is the operator of scope (::, two colons) included in the definition of set_values(). It is used to define a member of a class from outside the class definition itself. You may notice that the definition of the member function area() has been included directly within the definition of the CRectangle class. Note:- When we want to declare a function inside a class and definition outside the class then use :: (Scope Resolution Operator). Prof. Avinash S. Kapse
  • 15. Cont… 1. Members x and y have private access. 2. By declaring them private we deny access to them from anywhere outside the class. 3. CRectangle rect; This statement is used to create object rect of class Crectangle. 4. rect.set_values (3,4); This statement is used to call a function i.e. set_values(3,4). 3 is assigned to a and 4 is assigned to b where a and b are parameters of function set_values(). Prof. Avinash S. Kapse
  • 16. Example 2 #include <iostream.h> class MyClass { int a,b; void getData(int x, int y) { a=x; b=y; } Function definition with two parameters x and y Prof. Avinash S. Kapse
  • 17. Cont… void putData( ) { cout<<“ a = ” <<a<<endl; cout<<“ b = ” <<b<<endl; } }; void main () { MyClass m1,m2; m1.getData(5,10); This function will display the value of a and b Two objects have been created i.e. m1 and m2 getData( ) function is called with object m1. Prof. Avinash S. Kapse
  • 18. Cont… m1.putData(); m2.getData(15,100); m2.putData(); } Output of the above program: a = 5 b = 10 a = 15 b= 100 putData( ) function is called with object m1. getData( ) and putData( ) function is called with object m2. Prof. Avinash S. Kapse
  • 19. Example 3 WAP to accept and print student Roll Number and Name of a Student. #include <iostream.h> class MyStudent { int rollno; char name[25]; void getData() { cout<<“Enter Roll Number and Name of a Student”<<endl; cin>>rollno>>name; } Prof. Avinash S. Kapse
  • 20. Cont… void putData() { cout<<“ Roll Number : ” <<rollno<<endl; cout<<“ Name of Student : ” <<name<<endl; } }; void main () { MyStudent s1; s1.getData(); s1.putData(); } Prof. Avinash S. Kapse
  • 21. Cont… Output of the above program: Enter Roll Number and Name of a Student 36 Bajirao Singham Roll Number : 36 Name of Student: Bajirao Singham Prof. Avinash S. Kapse
  • 22. Exercise 1. WAP to read five numbers from user and calculate average. 2. WAP to calculate simple interest. 3. WAP to calculate percentage of a student by reading marks of five subjects and maximum marks for each subject is 100. Prof. Avinash S. Kapse
  • 23. Home Work 1. What is object oriented programming? 2. What is polymorphism OOP? 3. What is Encapsulation OOP? 4. What is Inheritance OOP? Explain their types. Prof. Avinash S. Kapse