SlideShare a Scribd company logo
OBJECT ORIENTED
PROGRAMMING
Object and Classes
CLASSES
CLASSES
 A class is a blueprint or a template that defines
the structure and behavior of objects. It is a
blueprint that encapsulates data and methods
(functions) into a single unit.
 A class is an entity that determines how an
object will behave and what the object will
contain.
 Think of a class as a blueprint for a house, which
defines the structure and characteristics of the
house.
CLASSES
 When you define a class you define a blueprint
for data type.
 This doesn’t actually define any data but it does
define what the class name means, what an
object of the class will consist of and what
operations can be performed on such an object.
SYNTAX OF CLASS
 A class is defined in C++ using
keyword class followed by the name of the class.
 The body of the class is defined inside the curly
brackets and terminated by a semicolon at the
end.
CLASS STRUCTURE
 A Class is a 3-Compartment Box encapsulating
Data and Functions
1. Classname (or identifier): identifies the class.
2. Data Members or Variables (or attributes,
states, fields): contains the static attributes of
the class.
3. Member Functions (or methods, behaviors,
operations): contains the dynamic operations of
the class
CLASS STRUCTURE
 In other words, a class encapsulates the static
attributes (data) and dynamic behaviors
(operations t hat operate on the data) in a box.
 Class Members
 The data members and member functions are
collectively called class members.
CLASS STRUCTURE
 Data Members (Variables)
 A data member (variable) has a name (or identifier) and a type;
and holds a value of that particular type (as descried in the
earlier chapter). A data member can also be an instance of a
certain class
Member Functions
A member function
 receives parameters from the caller
 performs the operations defined in the function body
 returns a piece of result (or void) to the caller
CLASS STRUCTURE
Class UML diagram
CLASS STRUCTURE
Instance UML diagram
EXAMPLE
Data members
Class
Member functions
OBJECTS
OBJECT
 An object is an instance of a class. It is a concrete
representation of a class that is created at
runtime.
 Basic unit of Object Oriented Programming that
is both data and function that operate on data
are bundled as unit called as object.
 Think of an object as an actual house built from
a blueprint. It has its own unique identity and
can have its own data and behavior.
OBJECT
 When a class is defined, only the specification for
the object is defined; no memory or storage is
allocated.
 To use the data and access functions defined in
the class, we need to create objects.
SYNTAX OF OBJECTS
EXAMPLE
objects room3 and room4 are
created in main()
SAMPLE CODE
SAMPLE CODE
 We can think of a class as the technical design
(prototype) of a car.
 It contains all the details about the brand, model,
mileage, etc.
 We can then build different cars based on these
descriptions.
 Here, each distinct car is an object.
SAMPLE CODE
SAMPLE CODE
• used the class keyword to
create a class named Car.
• brand and model are class
attributes used to store data
• drive() is a class function
used to perform some
operation
• The public keyword
represents an access
modifier.
SAMPLE CODE
 For example, the Car class defines the model,
brand, and mileage. Now, based on the definition,
 suv, sedan, and van are objects of the Car class
SAMPLE CODE
SAMPLE CODE
OUTPUT
LAB EXERCISE
LAB EXERCISE 1
 Write a C++ program that defines a class
representing a simple bank account. The class
should have data members such as account
number, account holder name, and balance. It
should also have member functions such as
deposit, withdrawal, and display account details.
Create objects of the class and perform various
operations on them, such as depositing money,
withdrawing money, and displaying account
details.
LAB EXERCISE 2
 Write a C++ program that defines a class
representing a student. The class should have
data members such as name, roll number, and
marks in different subjects. It should also have
member functions to accept and display student
information. Create objects of the class for
multiple students and input their details. Use
member functions to display the information of
the students.
LAB EXERCISE 3
 Write a C++ program that defines classes
representing a circle and a rectangle. The circle
class should have data members such as radius
and member functions to calculate and display
the area and circumference of the circle. The
rectangle class should have data members such
as length and breadth, and member functions to
calculate and display the area and perimeter of
the rectangle. Create objects of the circle and
rectangle classes and perform various operations
on them, such as calculating area, circumference,
perimeter, and displaying the details of the
shapes.

More Related Content

Similar to week 2 - classes and objects of object ori9ented programming .pptx (20)

PDF
C++ Notes
MOHAMED RIYAZUDEEN
 
PPT
Classes in C++ computer language presentation.ppt
AjayLobo1
 
PPTX
Lecture 4. mte 407
rumanatasnim415
 
PPT
Data structure and problem solving ch01.ppt
Ping261512
 
PPTX
Lecture 2 (1)
zahid khan
 
PPT
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
PPT
Classes, objects and methods
farhan amjad
 
PPTX
Oop objects_classes
sidra tauseef
 
PPTX
Class and object
prabhat kumar
 
PPTX
python.pptx
GayathriP95
 
PPT
Classes & objects new
lykado0dles
 
PPTX
OOP Unit 2 - Classes and Object
dkpawar
 
PPTX
object oriented programing lecture 1
Geophery sanga
 
PPT
Class diagram java
ravinlaheri2
 
PPTX
Oops
Jaya Kumari
 
PPT
Class methods
NainaKhan29
 
PPT
creating objects and Class methods
NainaKhan28
 
PPTX
Class Diagram
Rana_brothers
 
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Classes in C++ computer language presentation.ppt
AjayLobo1
 
Lecture 4. mte 407
rumanatasnim415
 
Data structure and problem solving ch01.ppt
Ping261512
 
Lecture 2 (1)
zahid khan
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Classes, objects and methods
farhan amjad
 
Oop objects_classes
sidra tauseef
 
Class and object
prabhat kumar
 
python.pptx
GayathriP95
 
Classes & objects new
lykado0dles
 
OOP Unit 2 - Classes and Object
dkpawar
 
object oriented programing lecture 1
Geophery sanga
 
Class diagram java
ravinlaheri2
 
Class methods
NainaKhan29
 
creating objects and Class methods
NainaKhan28
 
Class Diagram
Rana_brothers
 
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 

Recently uploaded (20)

PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Ad

week 2 - classes and objects of object ori9ented programming .pptx

  • 3. CLASSES  A class is a blueprint or a template that defines the structure and behavior of objects. It is a blueprint that encapsulates data and methods (functions) into a single unit.  A class is an entity that determines how an object will behave and what the object will contain.  Think of a class as a blueprint for a house, which defines the structure and characteristics of the house.
  • 4. CLASSES  When you define a class you define a blueprint for data type.  This doesn’t actually define any data but it does define what the class name means, what an object of the class will consist of and what operations can be performed on such an object.
  • 5. SYNTAX OF CLASS  A class is defined in C++ using keyword class followed by the name of the class.  The body of the class is defined inside the curly brackets and terminated by a semicolon at the end.
  • 6. CLASS STRUCTURE  A Class is a 3-Compartment Box encapsulating Data and Functions 1. Classname (or identifier): identifies the class. 2. Data Members or Variables (or attributes, states, fields): contains the static attributes of the class. 3. Member Functions (or methods, behaviors, operations): contains the dynamic operations of the class
  • 7. CLASS STRUCTURE  In other words, a class encapsulates the static attributes (data) and dynamic behaviors (operations t hat operate on the data) in a box.  Class Members  The data members and member functions are collectively called class members.
  • 8. CLASS STRUCTURE  Data Members (Variables)  A data member (variable) has a name (or identifier) and a type; and holds a value of that particular type (as descried in the earlier chapter). A data member can also be an instance of a certain class Member Functions A member function  receives parameters from the caller  performs the operations defined in the function body  returns a piece of result (or void) to the caller
  • 13. OBJECT  An object is an instance of a class. It is a concrete representation of a class that is created at runtime.  Basic unit of Object Oriented Programming that is both data and function that operate on data are bundled as unit called as object.  Think of an object as an actual house built from a blueprint. It has its own unique identity and can have its own data and behavior.
  • 14. OBJECT  When a class is defined, only the specification for the object is defined; no memory or storage is allocated.  To use the data and access functions defined in the class, we need to create objects.
  • 16. EXAMPLE objects room3 and room4 are created in main()
  • 18. SAMPLE CODE  We can think of a class as the technical design (prototype) of a car.  It contains all the details about the brand, model, mileage, etc.  We can then build different cars based on these descriptions.  Here, each distinct car is an object.
  • 20. SAMPLE CODE • used the class keyword to create a class named Car. • brand and model are class attributes used to store data • drive() is a class function used to perform some operation • The public keyword represents an access modifier.
  • 21. SAMPLE CODE  For example, the Car class defines the model, brand, and mileage. Now, based on the definition,  suv, sedan, and van are objects of the Car class
  • 26. LAB EXERCISE 1  Write a C++ program that defines a class representing a simple bank account. The class should have data members such as account number, account holder name, and balance. It should also have member functions such as deposit, withdrawal, and display account details. Create objects of the class and perform various operations on them, such as depositing money, withdrawing money, and displaying account details.
  • 27. LAB EXERCISE 2  Write a C++ program that defines a class representing a student. The class should have data members such as name, roll number, and marks in different subjects. It should also have member functions to accept and display student information. Create objects of the class for multiple students and input their details. Use member functions to display the information of the students.
  • 28. LAB EXERCISE 3  Write a C++ program that defines classes representing a circle and a rectangle. The circle class should have data members such as radius and member functions to calculate and display the area and circumference of the circle. The rectangle class should have data members such as length and breadth, and member functions to calculate and display the area and perimeter of the rectangle. Create objects of the circle and rectangle classes and perform various operations on them, such as calculating area, circumference, perimeter, and displaying the details of the shapes.