Site icon T4Tutorials.com

Greater than or equal to >= Operator Overloading C++

Greater than or equal to >= Operator Overloading in C++ and Object Oriented Programming (OOP).

C++ Program to overload the Greater than or equal to >= operator

In this program we try to overload the Greater than or equal to >= operator with C++.

// >= (Greater 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<<"Please  enter 1st number.  ";
	object1.input();
	cout<<" Please  enter 1st number .";
	object2.input();
	if(object1>= object2)
	{
		cout<<"Value of object1 is greater than Value of  object2 or Value of object1 is equal to Value of object2. ";
	}
	else
	{
		cout<<" Value of object1 is not greater than, nor equal to Value of object2";
	}

 return 0;
}

Output

Please Enter Any number. 6

Please enter 2nd number. 5

Value of object1 is greater than Value of object2 or Value of object1 is equal to Value of object2.

Video Lecture

FAQ

Exit mobile version