Class and Objec
Class and Objec
Class? It is a user defiened data type that has data member(veriable) and member
function(function). It act as blueprint .
Object? It can any thing person place or thing. It allowprogramers to use the
variables and functions from inside the class.
Advantages
Organazingthe code
Reuseability
Save time and space
Constructor
Types
Perametrized constructor
Non-Perametrized constructor
Copy constructor(it is used to initilliazed data members of class using
the another object of same class. )
Polymorphism
Function overloading
Same name function can be used many times . The compiler will decide which function
to call based on the types of function & number and types of arguments passed to the
function.
Operator overloading
the ability to provide the operators with a special meaning for a data type, this
ability is known as operator overloading. For example, we can overload an
operator '+' in a class like String so that we can concatenate two strings by just
using +
Virtual functions
It allows an object of a derived class to behave as if it were an object of the base class.
Inharitance
What is inharitance?
Advantages
Types
Single/simple inharitance
One child class is derived from one parent class(father and son)
Multiple inharitance
Once child class is drived form multiple parent classes(person and employee are
two parent class and teacher is derived form these classes)
Multilevel inharitance
One child is drived from parent and this parent is also derived from another parent
class; EX :son , Father , Grand father , grand grand father
Hierarchical inharitance
One parent have multiple child and these child also have multiple childs
Encapsulation: in single entity or unit(class , function ) It hides the code and data so that the
data can be protected from the outside . it resolve the naming conflict . Ex: Office bag, vollet,
capsule
Access specifier: Access specifiers(Access Modifier) define how the data member and function
of a class can be accessed.
1Private:
When we declared a methods and data members as Private . It can be be accessed only inside the
class (by default it is private )
2Public:
The classes, methods, or constructors which are declared as Public can be accessed from
anywhere.
3Protected
The methods and data members which are declared as protected are accessible by inside the class
and the child classes of this parent class.
Data Structure : The format of storing data in organized way so we can access data easily and
modified easily. ( Data Structure=Organized data +Allowed operations)
Types of DS:
1Premitive DS: It can hold a single value in memory location. Integer, character boolean etc.
1Linear DS: in Linear DS data is stored in sequence . previous and after data cell is connected
with each other. Ex Arrays,Stack,Queue,Linked List etc.
2Non-Linear DS: in Non- Linear DS data is not stored in sequence .. Ex Trees, Graphs,Tables
etc.
Array (linear DS) is a collection of data that have same type and stores in
contiguous(countinues) memory locations
MultiDimentional It is used more then one subscript(big bracket) to define the elements of
Array.
A stackis linear DS thatfollows a LIFO (Last In First Out) order for storing the elements. A stack
uses one end known as a top for insertion and deletion .Ex The collection of plates placed one
over the other is a real-world example of a stack,
A queue is linear DS that follows a FIFO (First In First Out) order for storing the elements .A
queue uses two ends front and rear for insertion and deletion Ex people standing in a queue to
pay an electricity bill is a real-world example of the queue
A linked list is a linear data structure, in which the data are not stored at contiguous memory
locations. It consists of nodes where each node contains a data field and address of the next node
in the list
Singly Linked List . itis the simplest type of linked list. It has 2 parts . in which first part contain
some data and second part contain address of the next node of the same data type.
Note: tail is null
Doubly Linked List Data are stored in nodes. Each node has 3 parts. First part contain the address
of previous node. Second part containt Data. Third part contain the address of next node
(reference link) to the next node of the same data type.
Note:Head and tail is null
Head tail
singly linked ascircular .It has 2 parts . in which first part contain some data and second part
contain address of the next node of the same data type.
Note: Last node in first part store data and second part store the address of first node.
Doubly Linked List as Circular. Data are stored in nodes. Each node has 3 parts. First part contain
the address of previous node. Second part containt Data. Third part contain the address of next
node (reference link) to the next node of the same data type.
Graph VS tree
A tree is a hierarchical non linear (ds) that consists of collection of nodes. Nodes represent value
and nodes are connected by edges. Loop does not exist
A graph is a non linear data structure that consists of a finite set of nodes (or vertices) and a set of
edges connecting them. Loop exist
Tree
Graph
Aset is a non-linear data structure that stores unique elements of the same type in a sorted order.
Each value is a key, which means that we access each value using the value itself. With arrays,
on the other hand, we access each value by its position in the container (the index). Accordingly,
each value in a set must be unique