Write a C++ Program to take two value from the user and create a menu driven code which will perform following operations using operator overloading.
1. Overload to compare two operands and check which operands have greater value and display it.
2. Overload any arithmetic operator and display its result.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Class{
public:
static int count;
int a;
void input()
{
count++;
cout<<"Enter value of object"<<count<<" : ";
cin>>a;
}
int operator > (Class ob)
{
if(ob.a < a)
{
return 1;
}
else{
return 0;
}
}
};
int Class :: count = 0;
int main()
{
Class ob1;
Class ob2;
ob1.input();
cout<<endl;
ob2.input();
cout<<endl;
if(ob1 > ob2)
{
cout<<"Value of object1 is greater"<<endl;
}
else{
cout<<"Value of object2 is greater"<<endl;
}
}
Comments
Leave a comment