0% found this document useful (0 votes)
30 views12 pages

Presentation 1

Uploaded by

f03564719
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views12 pages

Presentation 1

Uploaded by

f03564719
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

object

oriented
programming
oop
develop software, making it easier to manage complexity and promote code
reusability.
• Key Concepts of OOP in C++
 Encapsulation:
• Bundling data (attributes) and methods (functions) that operate on that
data within a single unit (class).
• This protects data integrity by controlling access to it through well-
defined interfaces.
 Inheritance:
• Creating new classes (derived classes) from existing ones (base classes).
• Derived classes inherit the attributes and methods of their base classes,
promoting code reuse and creating hierarchical relationships between
classes.
 Polymorphism:
• The ability of objects of different classes to be treated as if they were
objects of a common base class.
• This allows for flexible and dynamic code, enabling different objects to
respond to the same message in their own unique ways.
 Abstraction:
Benefits of OOP include the following:
 Modularity. Encapsulation enables objects to
be self-contained, making troubleshooting and
collaborative development easier.
 Reusability. Code can be reused through
inheritance, meaning a team does not have to
write the same code multiple times.
 Productivity. Programmers can construct new
programs quickly through the use of multiple
libraries and reusable code.
 Easily upgradable and
 Security. Using encapsulation and
abstraction, complex code is hidden,
software maintenance is easier and
internet protocols are protected.
 Flexibility. Polymorphism enables a
single function to adapt to the class it
is placed in. Different objects can also
pass through the same interface.
 Code maintenance. Parts of a system
can be updated and maintained
Objects in Object-Oriented Programming (OOP)
In object-oriented programming (OOP), an object is a fundamental
building block that represents a real-world entity with specific
properties and behaviors. It encapsulates data (attributes) and
methods (functions) that operate on that data.
Key Concepts of Objects:
 Identity:
 Each object has a unique identity that distinguishes it from
other objects, even if they have the same properties and
behaviors.
 This identity is often represented by a memory address.
 State:
 An object's state is defined by its attributes or properties,
which hold specific values.
 These attributes can change over time as the object
Real-World Analogy:
Consider a "Car" object:
 Identity: A specific car, like a 2023 Toyota
Camry with a particular VIN number.
 State: Color (e.g., blue), mileage (e.g., 10,000
miles), fuel level (e.g., half a tank).
 Behavior: Accelerate, brake, turn, honk,
open/close doors, etc.
Creating Objects in OOP:
Objects are created from classes, which are
blueprints or templates that define the structure
and behavior of objects. When a class is
Importance of Objects in OOP:
•Modularity: Objects break down complex systems
into smaller, manageable units.
•Reusability: Well-designed classes can be reused in
different parts of a program or in other programs.
•Encapsulation: Objects hide their internal
implementation details, promoting code organization
and reducing complexity.
•Polymorphism: Objects of different classes can be
treated as if they were of the same type, enabling
flexible and extensible code.
•Inheritance: Objects can inherit properties and
behaviors from other objects, reducing code
What is a Class in C++?

A class is a user-defined data type, which holds its own data members and
member functions, which can be accessed and used by creating an
instance of that class. A C++ class is like a blueprint for an object.

For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage
range, etc. So here, the Car is the class, and wheels, speed limits, and
mileage are their properties.
Components of a Class
A class in programming is a blueprint for
constructing objects, encapsulating both data and
the methods for manipulating it. Understanding a
class's components is critical for designing
efficient and well-organized code.
•Attributes: also known as properties,
attributes are variables that contain class-
specific data. These can range from simple
numbers to complicated data structures.
•Methods: methods are the functions that define
• Inheritance: this feature allows a
class to inherit characteristics and
methods from another class,
promoting reuse and code hierarchy.
•Encapsulation: encapsulation limits
direct access to attributes, which
promotes data integrity. Public, private,
and protected access modifiers control
visibility and manipulation.
Creating a Class
Creating a class in C++ involves a few key steps. You
begin by declaring the class with the class keyword,
followed by the class name. Then, inside the curly
brackets, declare the member variables (attributes) that
indicate the object's state. Integers, strings, and more
complicated data structures can be used.
Following that, you define member functions that operate
on the class data. These functions can alter data, give
functionality, and interact with other objects. For example,
in your Animal class, you could include a function that
calculates an animal's species' remaining years till
retirement.
C++ classes offer access modifiers such as public, private,

You might also like