JUNAIDVK
junaidvkomy@gmail.com
www.facebook.com/junaid.omy
twitter.com/junaid.omy
in.linkedin.com/in/junaidvkomy
9745991390
OPERATOR OVERLOADING
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
WHAT IS OPERATOR???
An operator is a symbol that
tells the compiler to perform
specific mathematical or logical
manipulations. Some operators
are….
• Arithmetical operators
• Logical operators
• Relational operators
OVERLOADING
More than one definition for
a function name or
an operator in the same scope,
which is called overloading.
• Function overloading
• Operator overloading
Operator overloading
The process of making an
operator to exhibit
different behaviours in
different instances is
known as operator
overloading.
Syntax:-
operator([parameters]) { Statements }
operator([parameters])
{
Statements
}
Benefits…..
• Perform different operations
on the same operands.
• It makes code much more
readable.
• Easily access the objects to
perform any operations .
Example
#include <iostream>
using namespace std;
class temp
{
private:
int count;
public:
temp()
{
count=25;
}
void operator --()
{
count--;
}
void Display()
{
cout<<"Count: "<<count;
}
};
main()
{
temp t;
--t;
t.Display();
}
OUTPUT
Count:24
Function overloading
Using a single function name to
perform different types of
tasks is known as function
overloading.
Example:
#include<iostream>
using namespace std;
class shape
{
public:
float area(double a)
{
float circle_area;
circle_area=3.14*(a*a);
return circle_area;
}
int area(int a)
{
int squire_area;
squire_area=a*a;
return squire_area;
}
int area(int a,int b)
{
int rectangle_area;
rectangle_area=a*b;
return rectangle_area;
}
};
main()
{
double circlee;
int squiree,rectanglee;
shape object;
cout<<"Area of Circle:";
circlee=object.area(5.00);
cout<<circlee;
cout<<"nArea of squire:";
squiree=object.area(4);
cout<<squiree;
cout<<"nArea of rectangle:";
rectanglee=object.area(5,6);
cout<<rectanglee;
}
Output:
Area of Circle:78.5
Area of squire:16
Area of rectangle:30
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us

operator overloading in C++

  • 2.
  • 3.
    Disclaimer: This presentationis prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4.
    WHAT IS OPERATOR??? Anoperator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Some operators are…. • Arithmetical operators • Logical operators • Relational operators
  • 5.
    OVERLOADING More than onedefinition for a function name or an operator in the same scope, which is called overloading. • Function overloading • Operator overloading
  • 6.
    Operator overloading The processof making an operator to exhibit different behaviours in different instances is known as operator overloading. Syntax:- operator([parameters]) { Statements } operator([parameters]) { Statements }
  • 7.
    Benefits….. • Perform differentoperations on the same operands. • It makes code much more readable. • Easily access the objects to perform any operations .
  • 8.
    Example #include <iostream> using namespacestd; class temp { private: int count; public: temp() { count=25; } void operator --() { count--; } void Display() { cout<<"Count: "<<count; } }; main() { temp t; --t; t.Display(); } OUTPUT Count:24
  • 9.
    Function overloading Using asingle function name to perform different types of tasks is known as function overloading.
  • 10.
    Example: #include<iostream> using namespace std; classshape { public: float area(double a) { float circle_area; circle_area=3.14*(a*a); return circle_area; } int area(int a) { int squire_area; squire_area=a*a; return squire_area; } int area(int a,int b) { int rectangle_area; rectangle_area=a*b; return rectangle_area; } }; main() { double circlee; int squiree,rectanglee; shape object; cout<<"Area of Circle:"; circlee=object.area(5.00); cout<<circlee; cout<<"nArea of squire:"; squiree=object.area(4); cout<<squiree; cout<<"nArea of rectangle:"; rectanglee=object.area(5,6); cout<<rectanglee; } Output: Area of Circle:78.5 Area of squire:16 Area of rectangle:30
  • 11.
    Follow us @twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 12.
    Emarald Mall (BigBazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us