0% found this document useful (0 votes)
3 views

Object-oriented-WPS Office

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Object-oriented-WPS Office

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Object-oriented programming (OOP) is a function--- is a self-contained block of In C++, an object is an instance of a

computer programming model that code that performs a specific task or class. A class is a blueprint for creating
organizes software design around data, operation. Functions allow you to objects, defining their properties (data
or objects, rather than functions and organize code into manageable pieces, members) and behaviors (member
logic. improve code reusability, and promote functions). When you instantiate a class,
modular programming. you create an object of that class type.
OOP advantages: Objects represent real-world entities or
concepts and encapsulate both data and
1. **Modularity**: OOP allows you to functions to operate on that data.
break down your code into smaller, return statement--- is used inside
manageable modules or classes. 2. functions to terminate the function's object--- is an instance of a class. A class
**Reusability**: OOP promotes execution and optionally return a value is a blueprint for creating objects,
reusability through inheritance and back to the caller. defining their properties (data
polymorphism. You can create a base members) and behaviors (member
class with common functionality and functions). When you instantiate a class,
then derive other classes from it, you create an object of that class type.
inheriting those features. 4. Types of function---Standard Functions: Objects represent real-world entities or
**Encapsulation**: OOP encapsulates These are built-in functions provided by concepts and encapsulate both data and
data and methods within objects, the C++ standard library. Examples functions to operate on that data.
restricting access to them from outside include printf(), scanf()etc.
the class. This protects the integrity of differences between classes and
the data and prevents unauthorized Inline Functions: Inline functions are structures:1. **Default Member
access, enhancing security and reducing functions that are expanded in-line at Access**:
errors.5. **Abstraction**: OOP enables the point of call, rather than being
you to model real-world entities using executed through a function call - In a class, members are private by
abstract data types and operations. By mechanism. default, meaning they can only be
hiding the implementation details and accessed within the class.
Recursive Functions: Recursive functions
focusing on essential features, you can
are functions that call themselves either - In a structure, members are public by
create more intuitive and maintainable
directly or indirectly. default, meaning they can be accessed
code.6. **Polymorphism**: OOP
supports polymorphism, allowing from outside the structure without
user-defined function:in C++ is a custom restrictions.
objects of different classes to be treated
function created by the programmer to
as objects of a common superclass. This
perform a specific task. 2. **Inheritance**:
promotes code flexibility and facilitates
dynamic behavior based on the actual Overloaded function - Classes support inheritance, allowing
type of the object at runtime.
one class to inherit properties and
An overloaded function in C++ refers to behaviors from another class.
Operator overloading---is a feature in a function that has the same name as
many object-oriented programming another function in the same scope but - Structures do not support
languages that allows you to redefine with different parameter lists. This inheritance directly.
the behavior of operators (such as +, -, allows multiple functions with the same
*, /, etc.) for user-defined types or
name to perform different tasks based 3. **Member Functions**:
classes. on the arguments passed to them.
- Classes can have member functions,
basic data types: structure---- is a user-defined data type which are functions that operate on the
that allows you to group together class's data members.
1. Int: Integer type, typically 4 bytes.
variables of different data types under a
single name. It is similar to a class but - Structures can also have member
2. float: Single-precision floating point,
with a few key differences, such as functions in C++, but they were not
usually 4 bytes.
default access level being public for supported in earlier versions of C++.
3.double: Double-precision floating members in a struct whereas it's private
for members in a class by default. 4. **Typical Use Cases**:
point, usually 8 bytes.

- Classes are typically used for complex


4.char: Character type, typically 1
data structures and object-oriented
byte.
programming, where encapsulation and
inheritance are important.
- Structures are often used for simpler from a single base class is known as the be tested for errors while it is being
data structures or for representing plain Single Inheritance. executed. The throw keyword throws an
data with no behavior attached. exception when a problem is detected,
which lets us create a custom error. The
catch statement allows you to define a
Multiple inheritance--- means that a block of code to be executed, if an error
constructor--- is a special member subclass can inherit from two or more occurs in the try block.
function of a class that is automatically superclasses
called when an object of that class is
created. It is used to initialize the
object's data members and perform any File operations---Both <iostream> and
necessary setup tasks. Constructors Multi level---The inheritance in which a <fstream> headers are used in the
have the same name as the class and do class can be derived from another program for file input output. Member
not have a return type. derived class is known as Multilevel functions stream insertion <<, put() and
Inheritance. write() are used for writing data to files
and functions stream extraction >>,
Hierarchical Inheritance---is a type of get(), getline() and read() are used for
destructor----on the other hand, is also inheritance in C++ where one base class reading data from file.
a special member function of a class is inherited by more than one derived
that is automatically called when an class. A template describes a set of related
object of that class is destroyed, either classes or set of related functions in
explicitly by the programmer or when it Hybrid inheritance is defined as the which a list of parameters in the
goes out of scope. It is used to release inheritance which is a combination of declaration describe how the members
any resources that the object may have more than one type of inheritance. of the set vary.
acquired during its lifetime, such as
memory allocated on the heap or open Virtual base classes--- in C++ are used to
file handles. prevent multiple instances of a given
class from appearing in an inheritance
copy constructor--- in C++ is a special hierarchy when using multiple
constructor that initializes a new object inheritances.
as a copy of an existing object of the
same class. The copy constructor abstract--- class in C++ is one that has at
typically takes a reference to another least one pure virtual function by
object of the same class as its definition.
parameter and initializes the new object
Constructor in derived class---If the class
with the same values as the existing
“A” is written before class “B” then the
object.
constructor of class “A” will be executed
[21/05, 1:49 am] CrAxyEe**: overload a first. But if the class “B” is written
unary operator--- in C++, you define a before class “A” then the constructor of
member function with the return type class “B” will be executed first.
of your requirement. Then comes the
"operator" keyword, followed by the
sign of the operator.
This pointer---in C++ holds the memory
address of the class instance (i.e.,
binary operator overloading function---,
object) that is being called from the
there should be one argument to be
member function, allowing those
passed. It is the overloading of an
functions to access the correct data
operator operating on two operands.
members of that specific object.
Through class conversion, one can
assign data that belongs to a particular
class type to an object that belongs to
another class type.

Exception handling---The try statement


Single inheritance---The inheritance in
allows you to define a block of code to
which a single derived class is inherited

You might also like