Unit 5
Unit 5
objects
– Abstraction
– Encapsulation
– Inheritance
– Polymorphism
Abstraction
• Showing only the essential features and hiding the
unnecessary features
• The access modifiers in C++ or any OOP language,
provides abstraction
• Functions also provide abstraction
• Poly – Many
• Morph – Form
Structured OOP
– General to Specific
• Bottom Up approach
– Lot of small modules will be grouped to form a single large
module
– Specific to General
FUNCTION 4 FUNCTION 5
• Using function
• Function & program is divided into modules
• Every module has its own data and function
which can be called by other modules.
OBJECT ORIENTED PROGRAMMING
Object 2
Object 1
Data Data
Function Function
Object 3
Data
Function
The11/20/24
object-list is optional. If present, it declares objects of the class. 14
access-specifier is one of these three C++ keywords:
public
private (default)
Protected
Class Scope
• Class data members and member functions belong to that
class's scope.
• Within a class's scope, class members are references by
name.
• Outside a class's scope, class members are referenced
• through
Use dotone of the handles
(.) notation on an
for object andobject.
references.
• Use arrow (->) for pointer to the object
• E.g.,
11/20/24 c.x , cpt -> x 15
Implementation of a Class
• Utility functions
– private functions that support the operation
of public functions
– Not intended to be used directly by clients
• Access functions
– public functions that read/display data or
check conditions
– For a data structure, it could call the
isEmpty function
Assignment - 5
1. Distinguish between a `struct' and a `class' in C++?
2. How does a class accomplish data hiding? Explain
with an example.
3. Explain the benefits of object oriented programming
over procedure oriented programming
4. What are the access privileges in C++? What is the
default access level?
5. What do you mean by Encapsulation and explain in
detail.
6. What is the difference between “C structure” and “C+
+ structure”.
7. Explain about the C++ classes in detail and design a
class for playing cards?
8. Discuss in detail about utility functions and access
functions.