Less than or equal to <=Â Operator Overloading in C++ and Object Oriented Programming (OOP).
C++ Program to overload the Less than or equal to <= operator
In this program we try to overload the Less than or equal to <= operator with C++.
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 29 30 31 32 33 34 35 36 37 38 |
// <= less than or equal to Operator overloading #include<iostream> using namespace std; class T4Tutorials { private : int num; public : void input() { cin>>num; } int operator <=(T4Tutorials formal_parameter) { if(num<= formal_parameter.num) return 1; else return 0; } }; int main() { T4Tutorials object1, object2; cout<<"Welcome to T4Tutorials: Please enter 1st number. "; object1.input(); cout<<" Welcome to T4Tutorials: Please enter 1st number ."; object2.input(); if(object1<= object2) { cout<<"Result: Value of object1 is less than Value of object2 or Value of object1 is equal to Value of object2. "; } else { cout<<" Result: Value of object1 is not less than, nor equal to Value of object2"; } return 0; } |
Output
Please Enter Any number. 7
Please enter 2nd number. 9
Value of object1 is less than Value of object2 or Value of object1 is equal to Value of object2.
Video Lecture
FAQ
- Less than or equal to operator overloading in c++ example.
- Less than or equal to operator overloading.
- <=Â operator overloading in c++ example.
- Relational operator overloading in c++ with programs.
- Overload comparison operator c++.
- Overloading stream insertion (<>) operators in C++.