SlideShare a Scribd company logo
1 of 217
Class and Object
• Class is a user defined datatype which holds its
owns data member and member function in
another word we can say class is collection of
data member and member function which can
accessed and use by creating object of that class
• An object is an instance of a class when ever class
is defined , on memory is allocated but when
object is initialized memory is allocated of that
class
Object
• An object is an instance of a class . When ever
class is defined , no memory is allocated but
when object is initialized memory is allocated
of that class .
• Their are three types of access specifier in
class
1. Private
2. Public
3. Protected
Declaration of class
• Syntax
• Class(class is a keyword) class Name
{
Private:
data member
member function
Public:
data member
member function
Protected:
data member
member function
}
Every class ends with semi- colunn.
Class(Example)
# incude<iostream.h>
Class demo {
private:
int a, b;
Public:
void input()
{
cout <<“enter the values”;
cin>> a>> b;
}
void show()
{
cout<<a<<“ ”<<b
}
};
Void main()
{
demo ob,ob1;
ob.input();
ob. Show();
ob1.input();
ob1.input();
Inheritance
• Inheritance is a mechanism in which one class
inherits the property of other calls is know as
inheritance .
• We can say when one class access the
property of another class is called inheritance
• Example : father and son
Types of inheritance
1. Single inheritance / Simple inheritance.
one base class and one derived class
2. Multi- level in heritance.
one base class and Multiple derived class
3. Multiple inheritance.
One or two base class but only one derived class
4. Hierarchical inheritance.
one base class and derived class are more then one
5. Hybrid inheritance.
• HYBRID INHEITANCE* IT TAKE MORE THEN TWO
INHERITANCE GIVEN above
• Like in example single + multi- level inheritance
Base
Derive
Derive 2
Base
Derive 1
1. Simple inheritance 2. Multi – level inheritance
3. Multiple – inheritance 4. Hierarchical inheritance
Base 1 Base 2
Derive
Base
Derive 1 Derive 2
Hybrid inheritance
Base 1
Drive 1 / base 2
Drive 2
Base 2
Encapsulation
• It is one of the most important features of
oops that used to wrapping the data and
function into a single unit . the data of class is
not accessible to out side the class only those
function access data which are wrapped in the
class.(information hiding )
• Example : Class is an example of encapsulation
which binding the data and function together .
It can be used by object of class
Example of Encapsulation C++
Class A
{
//int a,b; // by default private //
public:
void show()
{
Cout<<“ Enter the value of a & b”<<endl;
Cin>>a>>b;
Cout <<a<<“ ”<<b
}
void sum()
{
Cout<<“ enter the value of a and b ”<<endl;
Cin>> a>>b;
Cout<< sum << a+b<<endl;
}
Private: // we have to make it private by using key word encapsulation we hide the data //
Int a,b; // by default public //
];
void main()
{
A obj, obj2;
obj.show();
obj2.sum();
}
Abstraction in C++
• Abstraction is the one of the most important
features of oop’s which is sharing only the
essential information to out side world and
hiding the internal details .
 Abstraction
 using Class
 using header file
Example using class
• Class A
{
private:
int a=11; //XXXXXXX//
public:
void show()
{
cout<<a;
}
};
Main()
{
A obj;
obj.show();
}
Using header file
# include<math.h>
Main()
{
Int a=4,b;
b= sqrt(a);
Cout<<b;
}
Constructor
• Why we use constructor in C++
Constructor is a special member function of a class which
used to create and initialize the objects
Feature:
1. A constructor can only have one access modifier which
is public.
2. A constructor is never inherited an overridden.
3. Each and every c++ class has constructor either it is
provided by compiler by default or explicitly cratered
Destructor
• Destructor is a special member function that
executed automatically when an object is
destroyed that has been created by the
constructer.
• Destructor are used to de- allocate the
memory that has been allocated for the object
by the constructor
• A destructor declaration should always begin
with the tilde (~) symbol as show in .
# include<iostream.h>
class test
{
public:
test()
{ n=10;
cout<<n; }
}
~test()
{ cout<< “object destroyed”;}
};
Void main()
{test ob;}
Ex . Of constructor
Class A
{
Private:// optional .
Public:// we have to do to access out side.
Int a;
/* A()
{
a=100;
} */
void show()
{
cout<<a;
}
};
Void main()
{
A obj=A(); // A obj;
obj.show()
}
Types of constructor of c++
1. Default constructor
2. Parameterized constructor
3. Copy constructor
Default constructor :- default constructor is the
constructor which does not take any argument and it
has no parameters
• Syntax
Class Classname
{
Public:
Classname()
{
member data;
member function;
}
};
Parameterized constructor in c++
• A constructor which has parameters is called
parameterized constructor
• Constructor is used to provide different value
to distinct object.
Example . WAP to add two no using parameterized
constructor
#include<iostream>
using namespace std;
Class Add
{
Public;
Add(int a, int b)
{
int c = a+b;
cout<<“sum=”<<c;
}
};
Int main()
{
Add ob(10,20)
return 0;
}
C++ copy constructor
• A copy constructor is a an overloaded constructor
used to declare and initialize an object from
another object .
There are two types of copy constructor
1. Default copy constructor => The compiler
defines the default copy constructor. If the user
defines no copy constructor , compiler supplies
its constructor .
2. User defined constructor => The programmer
defines the user-defined constructor
Syntax of user define copy constructor
#include<iostream>
using namespace std;
Class CopyTest
{
public:
int x;
CopyTest(int a) // Parameterized constructor
{
x=a;
}
CopyTest(CopyTest & i) // Copy constructor
{
x= i.x;
}
};
Int main()
{
CopyTest a1(20);
CopyTest a2(a1);
cout<<a2.x;
return 0;
}
Inline function
• Inline is a request to the compiler(not a
command) to make a function as an inline
function. To reduce the overhead of function
calling . If compiler treat a function as a inline
function it substitute the code of function in a
single line
• Inline function should contain a single
instruction
• Ex: request only
Syntax
Inline return-type function name()
{
----------------
----------
}
Program on inline function
#include<iostream.h>
Inline int fun( int a, int b)
{
return(a>b)? a:b;
}
Void main()
{
cout<<“Maximum” fun(10,20);
//
Int s;
s=fun(30,12);
Cout<“maximum”<<s;
//
}
Function Overloading vs Function
Overriding in C++
• Function Overloading (achieved at compile time)
• Function Overloading provides multiple
definitions of the function by changing
signature i.e. changing number of parameters,
change datatype of parameters, return type
doesn’t play any role.
• It can be done in base as well as derived class
Function Overriding (achieved at run time)
• It is the redefinition of base class function in its derived
class with same signature i.e. return type and parameters.
• It can only be done in derived class.
• Example:
Class a
{
public: virtual void display()
{ cout << "hello"; }
};
Class b:public a
{ public: void display()
{ cout << "bye";} };
Function Overloading Function Overriding
Function Overloading provides multiple
definitions of the function by changing signature.
Function Overriding is the redefinition of base
class function in its derived class with same
signature.
An example of compile time polymorphism. An example of run time polymorphism.
Function signatures should be different. Function signatures should be the same.
Overloaded functions are in same scope. Overridden functions are in different scopes.
Overloading is used when the same function has
to behave differently depending upon
parameters passed to them.
Overriding is needed when derived class function
has to do some different job than the base class
function.
A function has the ability to load multiple times. A function can be overridden only a single time.
In function overloading, we don’t need
inheritance.
In function overriding, we need an inheritance
concept.
Default Argument s
# include <iostream>
Using namespace std;
Int sum(int a, int b, int c=b)
{Return a+b+c;}
Int main()
{
Int a=5 ,b=6;
Cout<< sum(a,b);
Return 0;
}
Static keyword in C++
• Static
Data member Member function
Static Data member
 whenever we declare a data member as a
static either inside or outside of a class called
static data member
There is only one copy of static data member
even it there are many class objects
It is always initialized with zero because it’s
default value is ZERO
It is shared memory for all object of the class
It retains it’s values
Static member function
 If we create a member function of a class as a
static called static called static member
function
It is access only static data members
It is also accessible if we don’t have any object
of class
Class A
{ Int a;
static int b;
public:
A(int x, int y)
{
a=x; b=y;
}
void show()
{
cout<<a<<“ ”<< b;
}
static void disp()
{
cout<<b; // a is not accessible
}
};
Int A:: b=0; // we have set Zero
Int main()
{
A obj(30,40), obj2(70,80);
obj.show()
obj2.show()
A:: disp(); // with out object
Obj.show()
}
a=30
B=40/80
a=70
Friend function
• Friend function is a function which is not the member of the class instant of that it
can access private and protected member of class.
• Syntax
friend return_type function name (class ob)
{
body
}
• Friend function is declared in the class with friend keyword.
• Friend function can become friend to more then one class.
Friend class
If a class become a friend class to a other class
then it can access the all function ex . Private
and protected member of that class
Friend class is declared always with friend
keyword
Syntax
Class A
{
Public :
member function()
{
-----
-----
}
Friend class B;
};
Class B
{
public :
member function (A ob)
{
----
-----
};
Class A
{ int a,int b;
Public :
Void input ()
{ cout<< “Enter two number”;
cin>> a>>b}
friend class B;
};
Class B
{
int c;
public:
void add(A ob)
{ c= ob.a+ ob.b;
cout<< sum << c}
};
int main()
{
A ao ; B kk;
ao.input();
kk.add(ao);
Object as function argument
We have 2 way
1. A copy of the entire object is passed to the
function -> pass by value
2. Only the address of the object is transferred
to the function -> pass by reference
Class total
{
int n;
Public :
void getdata(void);
void putdata(void);
void add(total,total);
};
Void total :: getdata(void)
{
cout <<“enter number:”;
cin>> n; endl;
}
Void total:: add(total x ,y)
{
n= x.n + y.n;
}
Void total:: putdata(void)
{
Cout<<n;endl;
}
Int main()
{
total r, s, result;
r.getdata();
s.getdata();
Cout<< “value of A :”;
r.Putdata()
Cout<< “value of B: ”;
s.Putdata();
Result.add(r,s);
Cout<< “addition :”;
result. Putdata();
}
Class matrix
{
Int item[3][3];
Public:
void getdata(void);
void putdata(void);
void add(matrix, matrix);
};
Void matrix :: getdata(void)
{
For(int i=0; i<3;i++)
{ for(int j=0; j<3;j++)
{ cin >> item[i][j];
}
}
}
Void matrix :: putdata(void)
{
For(int i=0; i<3;i++)
{ for(int j=0; j<3;j++)
{ cout<< item[i][j];
}
}
}
Void matrix :: add(matrix m, matrix n)
{
Int i,j;
For(int i=0; i<3;i++)
{ for(int j=0; j<3;j++)
{ item[i][j] = m.item[i][j]
}
}
}
Dynamic initialization of object
• Dynamic initialization of object refers to
initializing the object at run time . Ex... The initial
value of an object is to be provided during run
time.
• Dynamic initialization of object can be achieved
using constructors and passing parameters value
to the constructor(parameterized constructor).
• This type of initialization is required to initialize
the class variables during run time.
Example of dynamic initialization of object
#include<iostream.h>
Class point{ int a,b;
public :
point (int x1,int y1) // parameterized constructor //
{
a=x1;
b=y1;
}
Int getA()
{
return a;
}
Int getB()
{
return b;
}
};
Void main()
{
Int x1,y1;
Cout<<“Enter first value:”;
Cin>> x1;
Cout<<“Enter second value”;
Cin>> y1;
Point p1(x1,y2) // dynamic initiation of objecct //
Cout<<“p1.a=”<<p1.getA(),<<“p1.b=” <<p1.getB();
}
Pointer to object
• Item X
• Item *ptr
• Object pointer are useful in creating object at
runtime
Object
defined
Class
Name
Pointer of
type item
• We can also use an object pointer to access the
public member of an object.
• SYNTAX:
Class_name object;
Class _name *pointer_name;
INITIALIZATION:
pointer_name=&object;
EX.
Class obj;
Class *obj;
Pobj=&obj;
Accessing member using pointer
object
• Syntax:
Pointer_name->function_name()
Pointer_name->member_name;
(*pointer_name).function_name();
(*pointer_name).member_name;
EX.
Pdell->disp()
Pdell->usb;
(*pdell).pisp()
(*pdell).usb;
This keyword in c++
• Whenever the name of instance variable and local
variable both are same and if we initialize instance
variable with help of local variable then our compiler
totally confused that which one is local variable and
which one is instance variable
• to avoid this problem we use this keyword
int a,b;
A(int a,int b)
{
This->a=a; this->b=b;
}
• In c++ programming this is a keyword that
refers to the current instance of the class
there can be 3 main usage of this keyword in
c++
• it can be used to pass current object as a
parameter to another method
• It can be used to refer current class instance
variable
• it can be used to declare indexers
Reference variable in C++
• A variable which are provide alternate name
for the previously defined or existing variable
is called reference variable.
• Ex-> int a=10;
• int &b=a; a
• b
10
123456
Example
#inclued<iostream.h>
Void main()
{
Int a=10;
Int &b=a;
Cout<<a<<“” <<b<< endl;
++b;
Cout<<a<<“”<<b<<endl;
a+=10
Cout<<a<<“”<<b<<endl;
}
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx
C++.pptx

More Related Content

Similar to C++.pptx

Object oriented programming 2
Object oriented programming 2Object oriented programming 2
Object oriented programming 2Aadil Ansari
 
concepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptxconcepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptxurvashipundir04
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptxsyedabbas594247
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsSaleem Thapa
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptishan743441
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Abu Saleh
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxurvashipundir04
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)Durga Devi
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Kumar Boro
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Boro
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.pptKhizar40
 

Similar to C++.pptx (20)

Object oriented programming 2
Object oriented programming 2Object oriented programming 2
Object oriented programming 2
 
concepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptxconcepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptx
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
class and objects
class and objectsclass and objects
class and objects
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.ppt
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

C++.pptx

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Class and Object • Class is a user defined datatype which holds its owns data member and member function in another word we can say class is collection of data member and member function which can accessed and use by creating object of that class • An object is an instance of a class when ever class is defined , on memory is allocated but when object is initialized memory is allocated of that class
  • 29. Object • An object is an instance of a class . When ever class is defined , no memory is allocated but when object is initialized memory is allocated of that class . • Their are three types of access specifier in class 1. Private 2. Public 3. Protected
  • 30. Declaration of class • Syntax • Class(class is a keyword) class Name { Private: data member member function Public: data member member function Protected: data member member function } Every class ends with semi- colunn.
  • 31. Class(Example) # incude<iostream.h> Class demo { private: int a, b; Public: void input() { cout <<“enter the values”; cin>> a>> b; } void show() { cout<<a<<“ ”<<b } }; Void main() { demo ob,ob1; ob.input(); ob. Show(); ob1.input(); ob1.input();
  • 32. Inheritance • Inheritance is a mechanism in which one class inherits the property of other calls is know as inheritance . • We can say when one class access the property of another class is called inheritance • Example : father and son
  • 33. Types of inheritance 1. Single inheritance / Simple inheritance. one base class and one derived class 2. Multi- level in heritance. one base class and Multiple derived class 3. Multiple inheritance. One or two base class but only one derived class 4. Hierarchical inheritance. one base class and derived class are more then one 5. Hybrid inheritance. • HYBRID INHEITANCE* IT TAKE MORE THEN TWO INHERITANCE GIVEN above • Like in example single + multi- level inheritance
  • 34. Base Derive Derive 2 Base Derive 1 1. Simple inheritance 2. Multi – level inheritance 3. Multiple – inheritance 4. Hierarchical inheritance Base 1 Base 2 Derive Base Derive 1 Derive 2
  • 35. Hybrid inheritance Base 1 Drive 1 / base 2 Drive 2 Base 2
  • 36. Encapsulation • It is one of the most important features of oops that used to wrapping the data and function into a single unit . the data of class is not accessible to out side the class only those function access data which are wrapped in the class.(information hiding ) • Example : Class is an example of encapsulation which binding the data and function together . It can be used by object of class
  • 37. Example of Encapsulation C++ Class A { //int a,b; // by default private // public: void show() { Cout<<“ Enter the value of a & b”<<endl; Cin>>a>>b; Cout <<a<<“ ”<<b } void sum() { Cout<<“ enter the value of a and b ”<<endl; Cin>> a>>b; Cout<< sum << a+b<<endl; } Private: // we have to make it private by using key word encapsulation we hide the data // Int a,b; // by default public // ]; void main() { A obj, obj2; obj.show(); obj2.sum(); }
  • 38. Abstraction in C++ • Abstraction is the one of the most important features of oop’s which is sharing only the essential information to out side world and hiding the internal details .  Abstraction  using Class  using header file
  • 39. Example using class • Class A { private: int a=11; //XXXXXXX// public: void show() { cout<<a; } }; Main() { A obj; obj.show(); }
  • 40. Using header file # include<math.h> Main() { Int a=4,b; b= sqrt(a); Cout<<b; }
  • 41. Constructor • Why we use constructor in C++ Constructor is a special member function of a class which used to create and initialize the objects Feature: 1. A constructor can only have one access modifier which is public. 2. A constructor is never inherited an overridden. 3. Each and every c++ class has constructor either it is provided by compiler by default or explicitly cratered
  • 42. Destructor • Destructor is a special member function that executed automatically when an object is destroyed that has been created by the constructer. • Destructor are used to de- allocate the memory that has been allocated for the object by the constructor • A destructor declaration should always begin with the tilde (~) symbol as show in .
  • 43. # include<iostream.h> class test { public: test() { n=10; cout<<n; } } ~test() { cout<< “object destroyed”;} }; Void main() {test ob;}
  • 44.
  • 45. Ex . Of constructor Class A { Private:// optional . Public:// we have to do to access out side. Int a; /* A() { a=100; } */ void show() { cout<<a; } }; Void main() { A obj=A(); // A obj; obj.show() }
  • 46. Types of constructor of c++ 1. Default constructor 2. Parameterized constructor 3. Copy constructor
  • 47. Default constructor :- default constructor is the constructor which does not take any argument and it has no parameters • Syntax Class Classname { Public: Classname() { member data; member function; } };
  • 48. Parameterized constructor in c++ • A constructor which has parameters is called parameterized constructor • Constructor is used to provide different value to distinct object.
  • 49. Example . WAP to add two no using parameterized constructor #include<iostream> using namespace std; Class Add { Public; Add(int a, int b) { int c = a+b; cout<<“sum=”<<c; } }; Int main() { Add ob(10,20) return 0; }
  • 50. C++ copy constructor • A copy constructor is a an overloaded constructor used to declare and initialize an object from another object . There are two types of copy constructor 1. Default copy constructor => The compiler defines the default copy constructor. If the user defines no copy constructor , compiler supplies its constructor . 2. User defined constructor => The programmer defines the user-defined constructor
  • 51. Syntax of user define copy constructor #include<iostream> using namespace std; Class CopyTest { public: int x; CopyTest(int a) // Parameterized constructor { x=a; } CopyTest(CopyTest & i) // Copy constructor { x= i.x; } }; Int main() { CopyTest a1(20); CopyTest a2(a1); cout<<a2.x; return 0; }
  • 52. Inline function • Inline is a request to the compiler(not a command) to make a function as an inline function. To reduce the overhead of function calling . If compiler treat a function as a inline function it substitute the code of function in a single line • Inline function should contain a single instruction • Ex: request only
  • 53. Syntax Inline return-type function name() { ---------------- ---------- }
  • 54. Program on inline function #include<iostream.h> Inline int fun( int a, int b) { return(a>b)? a:b; } Void main() { cout<<“Maximum” fun(10,20); // Int s; s=fun(30,12); Cout<“maximum”<<s; // }
  • 55.
  • 56.
  • 57. Function Overloading vs Function Overriding in C++ • Function Overloading (achieved at compile time) • Function Overloading provides multiple definitions of the function by changing signature i.e. changing number of parameters, change datatype of parameters, return type doesn’t play any role. • It can be done in base as well as derived class
  • 58. Function Overriding (achieved at run time) • It is the redefinition of base class function in its derived class with same signature i.e. return type and parameters. • It can only be done in derived class. • Example: Class a { public: virtual void display() { cout << "hello"; } }; Class b:public a { public: void display() { cout << "bye";} };
  • 59. Function Overloading Function Overriding Function Overloading provides multiple definitions of the function by changing signature. Function Overriding is the redefinition of base class function in its derived class with same signature. An example of compile time polymorphism. An example of run time polymorphism. Function signatures should be different. Function signatures should be the same. Overloaded functions are in same scope. Overridden functions are in different scopes. Overloading is used when the same function has to behave differently depending upon parameters passed to them. Overriding is needed when derived class function has to do some different job than the base class function. A function has the ability to load multiple times. A function can be overridden only a single time. In function overloading, we don’t need inheritance. In function overriding, we need an inheritance concept.
  • 60. Default Argument s # include <iostream> Using namespace std; Int sum(int a, int b, int c=b) {Return a+b+c;} Int main() { Int a=5 ,b=6; Cout<< sum(a,b); Return 0; }
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78. Static keyword in C++ • Static Data member Member function
  • 79. Static Data member  whenever we declare a data member as a static either inside or outside of a class called static data member There is only one copy of static data member even it there are many class objects It is always initialized with zero because it’s default value is ZERO It is shared memory for all object of the class It retains it’s values
  • 80. Static member function  If we create a member function of a class as a static called static called static member function It is access only static data members It is also accessible if we don’t have any object of class
  • 81. Class A { Int a; static int b; public: A(int x, int y) { a=x; b=y; } void show() { cout<<a<<“ ”<< b; } static void disp() { cout<<b; // a is not accessible } }; Int A:: b=0; // we have set Zero Int main() { A obj(30,40), obj2(70,80); obj.show() obj2.show() A:: disp(); // with out object Obj.show() } a=30 B=40/80 a=70
  • 82. Friend function • Friend function is a function which is not the member of the class instant of that it can access private and protected member of class. • Syntax friend return_type function name (class ob) { body } • Friend function is declared in the class with friend keyword. • Friend function can become friend to more then one class.
  • 83.
  • 84. Friend class If a class become a friend class to a other class then it can access the all function ex . Private and protected member of that class Friend class is declared always with friend keyword Syntax
  • 85. Class A { Public : member function() { ----- ----- } Friend class B; }; Class B { public : member function (A ob) { ---- ----- };
  • 86. Class A { int a,int b; Public : Void input () { cout<< “Enter two number”; cin>> a>>b} friend class B; }; Class B { int c; public: void add(A ob) { c= ob.a+ ob.b; cout<< sum << c} }; int main() { A ao ; B kk; ao.input(); kk.add(ao);
  • 87. Object as function argument We have 2 way 1. A copy of the entire object is passed to the function -> pass by value 2. Only the address of the object is transferred to the function -> pass by reference
  • 88. Class total { int n; Public : void getdata(void); void putdata(void); void add(total,total); }; Void total :: getdata(void) { cout <<“enter number:”; cin>> n; endl; } Void total:: add(total x ,y) { n= x.n + y.n; } Void total:: putdata(void) { Cout<<n;endl; } Int main() { total r, s, result; r.getdata(); s.getdata(); Cout<< “value of A :”; r.Putdata() Cout<< “value of B: ”; s.Putdata(); Result.add(r,s); Cout<< “addition :”; result. Putdata(); }
  • 89. Class matrix { Int item[3][3]; Public: void getdata(void); void putdata(void); void add(matrix, matrix); }; Void matrix :: getdata(void) { For(int i=0; i<3;i++) { for(int j=0; j<3;j++) { cin >> item[i][j]; } } } Void matrix :: putdata(void) { For(int i=0; i<3;i++) { for(int j=0; j<3;j++) { cout<< item[i][j]; } } } Void matrix :: add(matrix m, matrix n) { Int i,j; For(int i=0; i<3;i++) { for(int j=0; j<3;j++) { item[i][j] = m.item[i][j] } } }
  • 90. Dynamic initialization of object • Dynamic initialization of object refers to initializing the object at run time . Ex... The initial value of an object is to be provided during run time. • Dynamic initialization of object can be achieved using constructors and passing parameters value to the constructor(parameterized constructor). • This type of initialization is required to initialize the class variables during run time.
  • 91. Example of dynamic initialization of object #include<iostream.h> Class point{ int a,b; public : point (int x1,int y1) // parameterized constructor // { a=x1; b=y1; } Int getA() { return a; } Int getB() { return b; } }; Void main() { Int x1,y1; Cout<<“Enter first value:”; Cin>> x1; Cout<<“Enter second value”; Cin>> y1; Point p1(x1,y2) // dynamic initiation of objecct // Cout<<“p1.a=”<<p1.getA(),<<“p1.b=” <<p1.getB(); }
  • 92. Pointer to object • Item X • Item *ptr • Object pointer are useful in creating object at runtime Object defined Class Name Pointer of type item
  • 93. • We can also use an object pointer to access the public member of an object. • SYNTAX: Class_name object; Class _name *pointer_name; INITIALIZATION: pointer_name=&object; EX. Class obj; Class *obj; Pobj=&obj;
  • 94. Accessing member using pointer object • Syntax: Pointer_name->function_name() Pointer_name->member_name; (*pointer_name).function_name(); (*pointer_name).member_name; EX. Pdell->disp() Pdell->usb; (*pdell).pisp() (*pdell).usb;
  • 95. This keyword in c++ • Whenever the name of instance variable and local variable both are same and if we initialize instance variable with help of local variable then our compiler totally confused that which one is local variable and which one is instance variable • to avoid this problem we use this keyword int a,b; A(int a,int b) { This->a=a; this->b=b; }
  • 96. • In c++ programming this is a keyword that refers to the current instance of the class there can be 3 main usage of this keyword in c++ • it can be used to pass current object as a parameter to another method • It can be used to refer current class instance variable • it can be used to declare indexers
  • 97. Reference variable in C++ • A variable which are provide alternate name for the previously defined or existing variable is called reference variable. • Ex-> int a=10; • int &b=a; a • b 10 123456
  • 98. Example #inclued<iostream.h> Void main() { Int a=10; Int &b=a; Cout<<a<<“” <<b<< endl; ++b; Cout<<a<<“”<<b<<endl; a+=10 Cout<<a<<“”<<b<<endl; }