Model Call Girl in Narela Delhi reach out to us at đ8264348440đ
Â
C___oop_to_Advanced zarif.pptx
1. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Object Oriented Programming
OOP Concept + OOP Programming
By Zarif Bahaduri
2. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Chapter 1
Introduction to OOP
3. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Programming Languages
⢠Programming languages allow programmers to code
software.
⢠The three major families of languages are:
⢠Machine languages
⢠Assembly languages
⢠High-Level languages
1
4. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Machine Language
⢠Comprised of 1s and 0s
⢠The native language of a computer
⢠Difficult to program â one misplaced 1 or 0 will fail the program
to run.
⢠Example of code:
1110100010101 111010101110
10111010110100 10100011110111
1
5. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Assembly Languages
⢠Assembly languages are a step towards easier programming.
⢠Assembly languages are comprised of a set of elemental
commands which are tied to a specific processor.
⢠Assembly language code needs to be translated to machine
language before the computer processes it.
⢠Example:
ADD 1001010, 1011010
1
6. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
High-Level Languages
⢠High-level languages represent a giant leap towards easier
programming.
⢠The syntax of HL languages is similar to English.
⢠Historically, we divide HL languages into two groups:
⢠Procedural languages
⢠Object-Oriented languages (OOP)
1
7. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Procedural Languages
⢠Early high-level languages are typically called procedural
languages.
⢠Procedural languages are characterized by sequential sets of linear
commands. The focus of such languages is on structure.
⢠Examples include C, COBOL, Fortran, LISP, Perl, HTML,
VBScript
1
8. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Object-Oriented Languages
⢠Most object-oriented languages are high-level languages.
⢠The focus of OOP languages is not on structure, but on
modeling data.
⢠Programmers code using âblueprintsâ of data models called
classes.
⢠Examples of OOP languages include C++, Visual Basic.NET
and Java.
1
9. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
What is OOP ?
⢠A way to look at a problem to be solved using a software based solution.
⢠A problem domain is characterized as a set of objects
⢠Object have specific attributes and behavior
⢠Objects are manipulated with a collection of function (method, operation,
services)
⢠Objects communicates with each other by passing massages
⢠Objects are divided into classes and subclasses
1
10. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Advantage of OOP
⢠There are two advantage of Object Oriented Programming.
⢠Advantage at Management Level
⢠Software is easy to maintain because the structure is inherently decoupled.
⢠Ease to change
⢠Less frustration (disappointed) for costumer and software engineers
⢠Advantage at Technical Level
⢠Objects are reusable and leads to faster software development and high quality
programs
⢠Easier to adapt and scale
1
11. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Chapter 2
Object and Class
12. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Classes
⢠Class: A class is a definition of objects. In other words, a class is a blueprint
for an object, template, or prototype that defines and describes the static
attributes and dynamic behaviors common to all objects of the same kind.
⢠instance: An instance is a realization of a particular item of a class. All the
instances of a class have similar properties, as described in the class
definition. For example, you can define a class called "Student" and create
three instances of the class "Student" for âahmad", âali" and âwalid"
2
13. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
A Class is a 3-Compartment Box
⢠A class can be visualized as a three-compartment box,
⢠Classname (or identifier): identifies the class.
⢠Data Members or Variables (or attributes, states, fields): contains the static
attributes of the class.
⢠Member Functions (or methods, behaviors, operations): contains
the dynamic operations of the class.
2
14. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Class Examples
2
15. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Class Definition
⢠In C++, we use the keyword class to define a class. There are two sections in
the class declaration: private and public, which will be explained later. For
example.
Note: public, private and protected
are access modifiers, we will discuss
it later.
class Circle { // classname
private:
double radius; // Data members (variables)
string color;
public:
double getRadius(); // Member functions
double getArea();
}
2
16. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Creating Instances(object) of a Class
To create an instance of a class:
⢠Declare an instance identifier (name) of a particular class.
⢠Invoke a constructor to construct the instance (for example allocate storage for the
instance and initialize the variables).
⢠For examples, suppose that we have a class called Circle, we can create instances of
Circle as follows:
// Construct 3 instances of the class Circle: c1, c2, and c3
Circle c1(1.2, "red"); // radius, color
Circle c2(3.4); // radius, default color
Circle c3; // default radius and color
2
17. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Dot (.) Operator
⢠To reference a member of a object (data member or function), you must:
1. First identify the instance you are interested in, and then
2. Use the dot operator (.) to reference the member, in the form of
instanceName.memberName.
⢠For example, suppose that we have a class called Circle, with two data members
(radius and color) and two functions (getRadius() and getArea()). We have created
three instances of the class Circle, namely, c1, c2 and c3. To invoke the function
getArea(), you must first identity the instance of interest, says c2, then use the dot
operator, in the form of c2.getArea(), to invoke the getArea() function of instance
c2.
2
18. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
For example
// Declare and construct instances c1 and c2 of the class Circle
Circle c1(1.2, "blue");
Circle c2(3.4, "green");
// Invoke member function via dot operator
cout << c1.getArea() << endl;
cout << c2.getArea() << endl;
// Reference data members via dot operator
c1.radius = 5.5;
c2.radius = 6.6;
2
19. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Data member (Variable) & Member Functions
⢠A data member (variable) has a name (or identifier) and a type; and holds a
value of that particular type.
⢠A member function
1. Receives parameters from the caller,
2. Performs the operations defined in the function body, and
3. Returns a piece of result (or void) to the caller.
2
20. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
OOP Practical Example 2
21. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Practice on classes
Lab Workshop
Practical Practice
2
23. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Constructors
⢠A constructor is a special function that has the function name same as the
classname.
// Constructor has the same name as the class
Circle(double r = 1.0, string c = "red") {
radius = r;
color = c;
}
3
Constructor object Creating and passing values
Circle c1(1.2, "blue");
Circle c2(3.4); // default color
Circle c3; // default radius and color
// Take note that there is no empty bracket ()
24. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Constructors
A constructor function is different from an ordinary function in the following
aspects:
⢠The name of the constructor is the same as the classname.
⢠Constructor has no return type.
⢠Constructors takes Arguments.
⢠Constructor are not inherited.
3
25. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Constructors
⢠There are two Types of Constructors
⢠Default Constructor
⢠Parameterized Constructors
Both Constructors will describe through examples
3
26. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Default Constructor
class MyData{
private:
string ename;
int salary;
public:
//Other methods
void getdata(int s, string n){
salary=s;
ename=n;
cout<<s<<endl<<n;
}};
MyData(){
string n="ali";
int s=500;
salary=s;
ename=n;
cout<<s<<endl<<n;
}
3
27. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Parameterize Constructor
class MyData{
private:
string ename;
int salary;
public:
//Other methods
Int show(){
Int total=salary+com;
Return total;
}
};
MyData(int x=90, int y=0){
salary=x;
com=y;
}
3
28. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Constructor Overloading and Copy
Constructor
Copy
constructor
Constructor
Overloading
29. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Destructor
⢠Destructors are usually used to de-allocate memory and do other cleanup for a
class object and its class members when the object is destroyed. A destructor is
called for a class object when that object passes out of scope or is explicitly deleted.
⢠Destructors are parameter less functions.
⢠Name of the Destructor should be exactly same as the class. With prefix of â~â.
⢠Destructor does not have any return type.
⢠The Destructor of class is automatically called when object goes out of scope.
3
30. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Access Control Modifiers/Access pacifiers
Data hiding is one of the important features of Object Oriented Programming
which allows preventing the functions of a program to access directly the
internal representation of a class type. The access restriction to the class
members is specified by the labeled public, private, and protected sections
within the class body. The keywords public, private, and protected are called
access specifies.
A class can have multiple public, protected, or private labeled sections. The
default access for members and classes is private.
3
31. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Example
Class Test{
Private:
// data members
Public:
// data members
Protected:
// data members
};
3
32. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
The Public members
A public member is
accessible from anywhere
outside the class but
within a program. You can
set and get the value of
public variables without
any member function as
shown in the example:
Class Test{
Public: //access pacifier
int a;
Public: //access pacifier
Void show(){
Cout<<a;
}
};
Main(){
// code
}
3
33. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
The Private members
⢠A private member
variable or function
cannot be accessed, or
even viewed from
outside the class. Only
the class and friend
functions(not Member
functions, outside,) can
access private members.
⢠By default all the
members of a class
would be private.
Class Test{
private: //access pacifier
int salary;
Public: //access pacifier
int tax;
Void setsalary(int x);
};
Test::setsalary(int x){
Salary=x;
Cout<<salary;
}
Main(){
// code
}
3
34. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
The Protected members
⢠A protected member
variable or function is
very similar to a
private member but it
provided one
additional benefit that
they can be accessed in
child classes which are
called derived classes.
The derived classes
will cover later in
details.
class Test {
protected:
int tax=10;
};
class Test2 : Test{
public:
int salary=50;
int calc(){
int total=salary-tax;
return total;
}
};
Main(){
// code
}
3
35. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Access modifiers in Inheritance*
37. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
4
These are OOP main building blocks
1.Classes
2.Inheritance
3.Polymorphism
4.Encapsulation
5.Abstraction
38. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Inheritance
⢠Inheritance is one of the key feature of
object-oriented programming including
C++ which allows user to create a new
class(derived class) from a existing
class(base class). The derived class inherits
all feature from a base class and it can have
additional features of its own.
39. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Concept of Inheritance
Suppose, you want to calculate either area and perimeter of
a rectangle by taking data(length and breadth) from user.
You can create two different objects( Area, Perimeter) and
asks user to enter length and breadth in each object and
calculate corresponding data. But, the better approach
would be to create a additional object Rectangle to store
value of length and breadth from user and derive
objects Area and Perimeter from Rectangle base class. It is
because, the two objects Area, Perimeter are related to
object Rectangle and you don't need to ask user the input
data from these two derived objects as this feature is
included in base class.
40. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Access modifiers in Inheritance
41. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Modes of Inheritance
⢠Public mode: If we derive a sub class from a public base
class. Then the public member of the base class will become
public in the derived class and protected members of the
base class will become protected in derived class.
⢠Protected mode: If we derive a sub class from a Protected
base class. Then both public member and protected
members of the base class will become protected in derived
class.
⢠Private mode: If we derive a sub class from a Private base
class. Then both public member and protected members of
the base class will become Private in derived class.
42. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Inheritance
In C++ we have
⢠Single Inheritance
⢠Multiple Inheritance
⢠Multilevel Inheritance
⢠Hierarchical Inheritance
⢠Hybrid (Virtual) Inheritance
To understand it practically watch video on
YouTube, channel name : Zarif Bahaduri
43. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Inheritance
In C++ we have
⢠Single Inheritance
⢠Multiple Inheritance
⢠Multilevel Inheritance
⢠Hierarchical Inheritance
⢠Hybrid (Virtual) Inheritance
To understand it practically watch video on
YouTube, channel name : Zarif Bahaduri
44. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Inheritance
In C++ we have
⢠Single Inheritance
⢠Multiple Inheritance
⢠Multilevel Inheritance
⢠Hierarchical Inheritance
⢠Hybrid (Virtual) Inheritance
To understand it practically watch video on
YouTube, channel name : Zarif Bahaduri
45. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Inheritance
In C++ we have
⢠Single Inheritance
⢠Multiple Inheritance
⢠Multilevel Inheritance
⢠Hierarchical Inheritance
⢠Hybrid (Virtual) Inheritance
To understand it practically watch video on
YouTube, channel name : Zarif Bahaduri
46. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Inheritance
In C++ we have
⢠Single Inheritance
⢠Multiple Inheritance
⢠Multilevel Inheritance
⢠Hierarchical Inheritance
⢠Hybrid (Virtual) Inheritance
To understand it practically watch video on
YouTube, channel name : Zarif Bahaduri
47. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Function Overloading
&Function Overriding
⢠Function Overloading : Whenever same method name is exiting multiple times in
the same class with different number of parameter or different order of parameters or
different types of parameters is known as Function overloading.
⢠Function Overriding: If base class and derived class have member functions with
same name and arguments. If you create an object of derived class and write code to
access that member function then, the member function in derived class is only
invoked.
the member function of derived class overrides the member function of base class.
This feature in C++ programming is known as function overriding.
48. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Function Overloading
&Function Overriding
Function
Overloading
Function
Overriding
49. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Polymorphism
Function Overloading, Overriding and Virtual
Functions
⢠The process of representing one Form in multiple forms is
known as Polymorphism. Here one form represent original
form or original method always resides in base class and
multiple forms represents overridden method which resides in
derived classes.
⢠Polymorphism is derived from 2 Greek words: poly and
morphs. The word "poly" means many and morphs means
forms. So polymorphism means many forms.
⢠Suppose if you are in class room that time you behave like a
student, when you are in market at that time you behave like a
customer, when you at your home at that time you behave like a
son or daughter, Here one person have different-different
behaviors.
⢠In shopping behave like a customer
⢠In bus behave like a passenger
⢠In school behave like a student
⢠In home behave like a son
50. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Polymorphism
⢠Compile time polymorphism-: The overloaded member
function are selected for invoking by matching arguments
both type and number. this information is known to the
compile at the compile time.
⢠compiler is able to select the appropriate function for a
particular call at the compile time itself. This is called early
binding or static binding or static linking. Also known
as compile time polymorphism
⢠Function Overloading & Operator Overloading are
the best examples of compile time Polymorphism
51. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Polymorphism
⢠We have already discussed Function overloading . Go
back and check the video.
⢠Lets take a look on operator overloading.
⢠In C++, it's possible to change the way operator works
(for user-defined types)
52. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Operator Overloading
⢠We have already discussed Function overloading .
Go back and check the video.
⢠Lets take a look on operator overloading.
⢠C++ programming allows programmer to redefine
the meaning of an operator (when they operate on class objects) is known as operator overloading.
⢠The meaning of an operator is always same for variable of basic types like: int, float, double etc. For
example: To add two integers, + operator is used. However, for user-defined types (like: objects), you
can redefine the way operator works.
⢠For example: If there are two objects of a class that contains string as its data members. You can
redefine the meaning of + operator and use it to concatenate those strings.
53. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Operator Overloading
Lets program it practically, I will use Structures, and
classes in order to understand Operator overloading
completely.
54. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Operator Overloading
Lets program it practically, I will use Structures, and
classes in order to understand Operator overloading
completely.
box1
box2
x=3
y=2.5
y=3
x=4
box3 = box1+box2
y=5.5
x=7
Area =7.5
Area =12
Area =38.5
55. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Polymorphism
⢠Run time Polymorphism -: It is known what object are
under consideration the appropriate version of the
function is invoked since the function is linked with a
particular class much later after the compilation, this
process is termed as late binding. It is also known as
dynamic binding because this section of the appropriate
function is done dynamically at run time.
⢠Dynamic binding is a powerful feathers of C++
programming language. This requires to object.
⢠Function Overriding is the best example of it,
⢠Lets go for virtual function.
56. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Types of Polymorphism
Before using virtual function you must have information about pointer to a class.
⢠A virtual function is a member function which is declared
within base class and is re-defined (Overridden) by derived class.
When you refer to a derived class object using a pointer or a
reference to the base class, you can call a virtual function for
that object and execute the derived classâs version of the
function.
⢠Virtual functions ensure that the correct function is called for an
object, regardless of the type of reference (or pointer) used for
function call.
⢠They are mainly used to achieve Runtime polymorphism
⢠Functions are declared with a virtual keyword in base class.
⢠The resolving of function call is done at Run-time.
57. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Pointer to a class
⢠We have already discussed pointer to Variable,
Arrays and Structures.
⢠A pointer to a C++ class is done exactly. To access
members of a pointer to a class you use the member
access operator -> operator. And you must initialize
the pointer before using it.
⢠Understand the concept of pointer to a class:
58. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
This-keyword
âthisâ keyword is used when
⢠If Local variable have same name as data member.
⢠When a reference to a local object is returned, the returned reference can be used to chain
function calls on a single object
⢠delete this
⢠It kills the object, we recommend you not to use âdelete thisâ in your program.
59. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Encapsulation
⢠Encapsulation is an Object Oriented Programming
concept that binds together the data and functions and
keeps both safe from external attack and misuse. Data
encapsulation led to the important OOP concept of data
hiding.
Advantage of Encapsulation
⢠The main advantage of using of encapsulation is to secure
the data from other methods, when we make a data private
then these data only use within the class, but these data not
accessible outside the class.
⢠1) Make all the data members private.
2) Create public setter and getter functions for each data
member in such a way that the set function set the value
of data member and get function get the value of data
member.
60. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Encapsulation
⢠Real time example
⢠In real live we have a Capsule in which all the
medicine is encapsulate so the medicine is safe from
the external attack.
⢠In C++ we can consider the encapsulation
mechanism as a Capsule in which our Methods and
variable are safe from other classes or other methods
61. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Data Abstraction
⢠Data Abstraction is a concept which shouldn't be
confused with Abstract classes, it is separated.
⢠Data Abstraction is an OOP concept that focuses only
on relevant data of an object. It hides the background
details and emphasizes the essential data points for
reducing the complexity and increase efficiency.
Abstraction method mainly focuses on the idea instead
of actual functioning.
⢠Abstraction hides the irrelevant details found in the code.
62. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Encapsulation Vs Data
Abstraction
Abstraction
Encapsulation
63. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Encapsulation Vs Data
Abstraction
⢠Abstraction hides the irrelevant
details found in the code.
⢠Encapsulated Code is quite flexible
and easy to change with new
requirements.
⢠In abstraction, problems are solved
at the design or interface level.
⢠In encapsulation, problems are
solved at the implementation level.
64. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Passing Argument
⢠There are three ways of passing argument.
1. By passing values
2. By passing reference
3. By passing address, pointer
⢠1:- Passing by values: By default, C++ copies
the actual value of an argument into the formal
parameter of the function. In this case, changes
made to the parameter inside the function have
no effect on the argument. call by value to pass
arguments. In general, this means that code
within a function cannot alter the arguments
used to call the function.
a=9 b=10
z=9
x=9 y=10
65. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Passing Argument
⢠There are three ways of passing argument.
1. By passing values
2. By passing reference
3. By passing address, pointer
⢠2:- Passing by Reference: copies the
reference of an argument into the formal
parameter. Inside the function, the
reference is used to access the actual
argument used in the call, this means that
changes made to the parameter affect the
passed argument.
a=9 b=10
z=9
x y
66. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Passing Argument
⢠There are three ways of passing argument.
1. By passing values
2. By passing reference
3. By passing address, pointer
⢠3:- Passing by address/pointer: copies the
address of an argument into the formal
parameter. Inside the function, the address
is used to access the actual argument used
in the call, this means that change made to
the parameter effect the passed argument.
a=9 b=10
z=9
#001 #010
*x
#001
*y
#010
67. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Virtual Function & Pure
Virtual function
⢠Virtual functions power polymorphism concept, while a pure
virtual functions lead us to the Abstract classes.
⢠A virtual function is a member function in the base class that
you redefine in a derived class. It is declared using the virtual
keyword.
⢠you cannot set a non-virtual function=0;
⢠virtual keyword does not work on class variables
68. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Abstract classes
⢠Are those classes having pure-virtual function
⢠We can not instantiate or can not make object/instance of
these classes same as when the constructor of a class is
private or protected.
⢠The derived class of Abstract class must implement the
pure-virtual function otherwise object of derived class is an
error.
⢠An Abstract class can have a pure-virtual function plus
other non-virtual functions and data members.
69. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Interfaces
⢠Interface is an Abstract class with NO member variable, it
contain on pure virtual functions.
⢠Interfaces are only a concept.
⢠All the pure-functions of an interfaces must be
implemented in derived classes.
70. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Virtual classes
⢠Virtual base classes, used in virtual inheritance, is a way of
preventing multiple "instances" of a given class appearing
in an inheritance hierarchy when using multiple
inheritance.
⢠An instance of textOffice will be made up of truck,
which includes vehicle, and car which also includes
vehicle. So you have two "instances" (for want of a better
expression) of vehicle. When you have this scenario, you
have the possibility of ambiguity.
⢠When you specify virtual when inheriting your classes,
you're telling the compiler that you only want a single
instance.
71. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Virtual classes
⢠Virtual base classes, used in virtual inheritance, is a way of
preventing multiple "instances" of a given class appearing
in an inheritance hierarchy when using multiple
inheritance.
⢠An instance of textOffice will be made up of truck,
which includes vehicle, and car which also includes
vehicle. So you have two "instances" (for want of a better
expression) of vehicle. When you have this scenario, you
have the possibility of ambiguity.
⢠When you specify virtual when inheriting your classes,
you're telling the compiler that you only want a single
instance.
72. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Staticâkeyword
⢠Static is a keyword gives special characteristics to an
element. Static elements are allocated storage only once in
a program lifetime in static storage area. And they have a
scope till the program lifetime. Static Keyword can be used
with.
⢠Static variable in functions
⢠Static Variable in class
⢠Static Class Objects
⢠Static function in class
1. Static variable in function: are initialized only once, and
then they hold there value even through function calls,
These static variables are stored on static storage area ,
not in stack.
⢠NOTE: java doesnât allow static locale variable in a function
73. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Staticâkeyword
2. Static variable in class: As the variables declared as static
are initialized only once and as they are allocated space in
separate static storage so, the static variables in a class are
shared by the objects. There can not be multiple copies
of same static variables for different objects. Also because
of this reason static variables can not be initialized using
constructors. it must be initialized explicitly, always outside
the class. If not initialized, it will give error.
74. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Staticâkeyword
3. Static Class Object: Just like variables, objects
also when declared as static have a scope till the
lifetime of program. the destructor is invoked
after the end of main. This happened because the
scope of static object is through out the life time
of program.
75. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Staticâkeyword
⢠4. Static function in class: Like static member or
variable of a class static member functions also does
not depend on object of class. We are allowed to
invoke a static member function using the object and
the â.â operator but it is recommended to invoke the
static members using the class name and the scope
resolution operator.
Static member functions are allowed to access
only the static data members or other static
member functions, they can not access the non-
static data members or member functions of the
class. It doesn't have any "this" keyword which is the
reason it cannot access ordinary members.
76. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Staticâkeyword
⢠4. Static function in class: Like static member or
variable of a class static member functions also
does not depend on object of class. We are allowed
to invoke a static member function using the object
and the â.â operator but it is recommended to
invoke the static members using the class name
and the scope resolution operator.
Static member functions are allowed to access
only the static data members or other static
member functions, they can not access the non-
static data members or member functions of the
class. It doesn't have any "this" keyword which is
the reason it cannot access ordinary members.
77. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Friend Function
⢠Calling a normal function causes overhead(jumping from one point to
another and back to its previous point / stacking arguments). If a
function is inline, the compiler places a copy of the code of that
function at each point where the function is called at compile time.
NORMAL FUNCTION
{
//âŚ
//âŚ
myfun();
//âŚ
//âŚ
}
{
//âŚ
//âŚ
//âŚ
//..
}
myfun()
main ()
INLINE FUNTION
{
//âŚ
myfun();
}
{
//âŚ
//âŚ
}
main ()
NO
Control transfer
78. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Friend Function
⢠Calling a normal function causes overhead(jumping from one point to
another and back to its previous point / stacking arguments). If a
function is inline, the compiler places a copy of the code of that
function at each point where the function is called at compile time.
NORMAL FUNCTION
{
//âŚ
//âŚ
myfun();
//âŚ
//âŚ
}
{
//âŚ
//âŚ
//âŚ
//..
}
myfun()
main ()
INLINE FUNTION
{
//âŚ
myfun();
}
{
//âŚ
//âŚ
}
main ()
NO
Control transfer
79. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Friend Function
A friend function of a class is defined
outside that class, but it has the right to
access all private and protected members of
the class. Even though the prototypes for
friend functions appear in the class
definition, friends are not member
functions.
To declare a function as a friend of a class,
precede the function prototype in the class
definition with keyword friend as follows:
Friend Function Definition
80. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Operator
Operator is a special symbol that tells the compiler to perform specific
mathematical or logical Operation.
Here we discuss only the
unary operator and binary
operators in details .
81. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Operator
Lets do the practical program for each in Computer Lab
82. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Bit Wise Operator
A bitwise operation operates on one or more bit patterns or binary numerals
at the level of their individual bits. It is a fast, primitive action directly
supported by the processor, and is used to manipulate values for comparisons
and calculations.
83. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Bitwise Operators
1. | bitwise OR
2. ~ bitwise NOT
3. & bitwise AND
4. ^ bitwise XOR
5. << bitwise left shift
6. >> bitwise right shift
NOTE:
To understand completely bitwise
operators you, must have a clear
DLD logical gats concept.
84. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
|, & bitwise
0011 = 3
0101 = 5
0111 = 7
| OR
0011 = 3
0101 = 5
0001 = 1
& AND
If you Remember, logical |OR evaluates to true (1). if either
the left or the right or both operands are true (1). Bitwise OR
evaluates to 1 if either bit (or both) is 1. So, 3 | 5 evaluates
like this:
Bitwise AND works similarly. Logical &AND evaluates to true
if both the left and right operand evaluate to true. Bitwise
AND evaluates to true if both bits in the column are 1)
85. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
~ , ^ bitwise
0011 = 3
1100=12
~ NOT
0011 = 3
0101 = 5
0110 = 6
^ XOR
The last operator is the bitwise XOR (^), also known as exclusive or. When evaluating two operands, XOR evaluates to true (1) if one and only one of it's operands is true (1). If neither or both are true, it evalu
Bitwise XOR (^) also known as exclusive or. When
evaluating two operands, XOR evaluates to true (1) if one and
only one of it's operands is true (1). If neither or both are
true, it evaluates to 0.
The bitwise NOT operator (~) is perhaps the easiest to
understand of all the bitwise operators. It simply flips
each bit from a 0 to a 1,
87. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Important Topics
Friend Function
Virtual function
Inline function
Static Keyword
Pointer and functions
Pointer and strings
Discussed already click here
Discussed already click here
Discussed already click here
88. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
This Pointer
⢠Every object in C++ has access to its own address through an important
pointer called this pointer. The this pointer is an implicit parameter to all
member functions. Therefore, inside a member function, this may be used to
refer to the invoking object.
⢠Friend functions do not have a this pointer, because friends are not
members of a class. Only member functions have a this pointer.
90. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
User Defined Data Types
To declare a new data type in C++ we will discuss only:
⢠Typedef
⢠Union
⢠Structures
3
91. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Typedef
⢠Typedefs allow you to create an alias for a data type, and use the aliased
name instead of the actual type name. To declare a typedef, simply use
the typedef keyword, followed by the type to alias, followed by the alias
name:
typedef double distance; //typedef alias is declare
distance a; = double a;
Example
Typedef int numbers;
Main(){
numbers a;
a=90;
cout<<a;
}
3
92. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Union
⢠A union is a user-defined data type
⢠To begin the declaration of a union with the union keyword, and enclose the
member list in curly braces:
union tag
{
member-list
}declaretor;
Union Data{
int numbers;
Double dec;
String text;
} ver1;
Main(){
Ver1.numbers=900;
cout<<ver1.numbers;
}
Example
3
93. Watch videos on YouTube.
Channel Name: Zarif Bahaduri
Structures
⢠A structure is one or a group of variables considered as a (custom) data type. To
create a structure, use the struct keyword followed by a name for the object, at least
followed by a semi-colon. It can be created as follow
struct data{
//body of structure
Int num;
Doubl dic;
String text;
};
struct data ver1;
Ver1.text=âyour text";
cout<<ver1.text;
3