0% found this document useful (0 votes)
14 views14 pages

Oops Unit 1 Notes

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

Oops Unit 1 Notes

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

OBJECT ORIENTED

PROGRAMMING WITH C++


SEMESTER 3
UNIT - 1

HI COLLEGE
SYLLABUS
UNIT - 1

HI COLLEGE
OBJECT ORIENTED PARADIG:
Procedural vs. Object-Oriented Development

Class:
A class is a data-type that has its own members i.e. data members and member
functions. It is the blueprint for an object in object oriented programming
language. It is the basic building block of object oriented programming in C++.
The members of a class are accessed in the programming language by creating
an instance of the class.

HiCollege Click Here For More Notes 01


Object:
An object is an instance of a class. It is an entity with characteristics and
behaviour that are used in the object oriented programming. An object is the
entity that is created to allocate memory. A class when defined does not have
memory chunk itself which will be allocated as soon as objects are created.

Encapsulation:
In object oriented programming, encapsulation is the concept of wrapping
together of data and information in a single unit. A formal definition of
encapsulation would be: encapsulation is binding together the data and
related function that can manipulate the data.

Abstraction
Data abstraction or Data Hiding is the concept of hiding data and showing only
relevant data to the final user. It is also an important part object oriented
programing

Polymorphism
The name defines polymorphism is multiple forms. which means
polymorphism is the ability of object oriented programming to do some work
using multiple forms. The behavior of the method is dependent on the type or
the situation in which the method is called.
In C++ programming language, polymorphism is achieved using two ways. They
are operator overloading and function overloading

Inheritance
it is the capability of a class to inherit or derive properties or characteristics
other class. Inheritance is very important and object oriented program as it
allows reusability i.e. using a method defined in another class by using
inheritance. The class that derives properties from other class is known as child
class or subclass and the class from which the properties are inherited is base
class or parent class.

Message passing
OOP is a mechanism for objects to communicate and interact with each other
by sending messages. It involves invoking methods on objects, which can lead
to the exchange of information, execution of a specific behaviour, or
modification of an object's state

HiCollege Click Here For More Notes


02
APPLICATIONS AND BENEFITS OF OOP

Applications:
Client-Server Systems: Object-oriented client-server systems provide the IT
infrastructure, creating Object-Oriented Client-Server Internet (OCSI)
applications.

Object-Oriented Databases: They are also called Object Database


Management Systems (ODBMS). These databases store objects instead of
data, such as real numbers and integers.

Simulation and Modeling System: It’s difficult to model complex systems


due to the varying specification of variables. These are prevalent in medicine
and in other areas of natural science, such as ecology, zoology, and
agronomic systems.

Office Automation Systems: These include formal as well as informal


electronic systems primarily concerned with : sharing and communication
to and from people inside and outside the organization.

CIM/CAD/CAM Systems: OOP can also be used in manufacturing and design


applications, as it allows people to reduce the effort involved. For instance, it
can be used while designing blueprints and flowcharts.

Benefits:
1.Modularity: OOP allows you to break down complex problems into smaller,
manageable modules (objects).

2.Reusability: Objects can be reused in different parts of a program or in


different programs, saving development time.

3.Encapsulation: OOP encapsulates data and methods within objects,


providing data security and preventing unauthorized access.

4.Code organization: OOP promotes a structured approach to programming,


making code easier to understand, maintain, and debug.

HiCollege Click Here For More Notes


03
5. Inheritance: Inheritance allows classes to inherit properties and behaviors
from other classes, promoting code reuse and reducing redundancy.

6. Polymorphism: Polymorphism enables objects to take on different forms,


allowing for flexible and extensible code.

7. Simplicity: OOP simplifies complex problems by modeling them closer to


real-world entities, making the code more intuitive and easier to comprehend.

COMPARISON BETWEEN C AND C++.

LITERALS- CONSTANT QUALIFIERS


Literals in C++ are fixed values that are directly written into the code. They
represent specific types of data, such as integers, floating-point numbers,
characters, and strings. Constant qualifiers, on the other hand, are used to
specify the immutability of variables.

For example
Integer literals: Examples include 42, -10, and 0xFF (hexadecimal).
Floating-point literals: Examples include 3.14, -0.5, and 1.0e-5.
Character literals: Represented within single quotes, such as 'A', 'b', or '%'.
String literals: Represented within double quotes, such as "Hello", "World", or
"OpenAI".

HiCollege Click Here For More Notes


04
OPERATORS IN C++,
Arithmetic Operators: + (addition)- (subtraction)* (multiplication), / (division)
% (modulus).

Assignment Operators: = (simple assignment), += (addition assignment), -=


(subtraction assignment), *= (multiplication assignment), /= (division
assignment), %= (modulus assignment)

Comparison Operators: == (equality), != (inequality), < (less than), > (greater


than), <= (less than or equal to), >= (greater than or equal to).

Logical Operators: && (logical AND), || (logical OR), ! (logical NOT).

Increment/Decrement Operators: ++ (increment), -- (decrement).

Bitwise Operators: & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise
NOT), << (left shift), >> (right shift).

Ternary Operator: condition ? expression1 : expression2 (conditional


operator)

Member Access Operators: . (dot operator), -> (arrow operator).

Pointer Operators: * (dereference operator), & (address-of operator).

REFERENCE VARIABLE,
A reference variable in C++ is an alias or alternative name for an existing
variable. It allows you to refer to the same memory location as the original
variable, providing an alternative way to access and manipulate its value.

HiCollege Click Here For More Notes


05
OUTPUT -
Original value of x: 5
Value of ref: 5
Modified value of x: 10
Value of ref after modification: 10

FUNCTIONS :
In C++, functions are blocks of code that perform specific tasks or operations.
They allow you to organize your code into reusable and modular units, making
it easier to manage and maintain.

DEFAULT ARGUMENTS,
In C++, default arguments allow you to specify default values for function
parameters. When a function is called, if an argument is not provided for a
parameter with a default value, the default value is used instead.

HiCollege Click Here For More Notes


06
PARAMETER PASSING BY VALUE,
Parameter passing by value is a method used in programming languages to
pass arguments to functions. When passing a parameter by value, a copy of the
argument's value is made and passed to the function. The function works with
this copy, and any modifications made to the parameter within the function do
not affect the original argument outside of the function.

REFERENCES AND POINTERS

REFERENCES:
A reference is an alias or an alternative name for an existing variable.
It provides a way to access and manipulate the original variable directly.
Once a reference is initialized, it cannot be changed to refer to a different
variable.
References are often used as function parameters to avoid making copies of
large objects.
They are declared using the & symbol after the variable type.

HiCollege Click Here For More Notes


07
POINTERS
A pointer is a variable that stores the memory address of another variable.
It allows indirect access to the variable it points to.
Pointers can be reassigned to point to different variables.
They are used for dynamic memory allocation and working with data
structures.
Pointers are declared using the * symbol before the variable name.

HiCollege Click Here For More Notes


08
INLINE FUNCTIONS:
Inline functions are a feature in C++ that allows the compiler to replace the
function call with the actual function code at the call site. This eliminates
the overhead of function call mechanisms, such as stack frame creation and
return address management.

TYPE CONVERSION,
Type conversion, also known as type casting, is the process of converting a
value from one data type to another in a programming language. It allows
you to change the interpretation or representation of a value to suit a
specific context or operation.

HiCollege Click Here For More Notes


09
BASIC C++ PROGRAMS
( YE TOH SABKO AANE CHAHIYE)

FACTORIAL OF NUMBER

HiCollege Click Here For More Notes


10
NUMBER IS PRIME OR NOT

FIBONACCI SERIES

HiCollege Click Here For More Notes


11
BASIC USE AND DYNAMIC MEMORY ALLOCATION FOR ARRAYS.
In C++, the new and delete operators are used for dynamic memory allocation
and deallocation. They allow you to allocate memory at runtime and release it
when it is no longer needed.

New Operator:
The new operator is used to dynamically allocate memory for a single object. It
returns a pointer to the allocated memory.
pointer_variable = new data_type

The Delete operator:


The delete operator is used to deallocate memory that was previously allocated
using new. It frees up the memory so that it can be reused.
delete pointer_variable

Dynamic Memory Allocation for Arrays:


The new operator can also be used to dynamically allocate memory for arrays.
The syntax is slightly different:

pointer_variable = new data_type[size];


int* arr = new int[5];

This statement dynamically allocates memory for an integer array of size 5 and
assigns the address of the allocated memory to the arr pointer.

To deallocate memory for an array, you need to use the delete[] operator:
delete[] arr;
It's important to note that when using dynamic memory allocation, you are
responsible for managing the allocated memory. Always remember to
deallocate the memory using delete or delete[] when you are done using it to
avoid memory leaks.

HiCollege Click Here For More Notes


12

You might also like