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>
using namespace std;
int main()
{
int x,y;
cout<<"\nEnter the first number:";
cin>>x;
cout<<"\nEnter the second number:";
cin>>y;
int c;
cout<<"1. Compare\n 2. Operation\n";
cout<<"\nEnter your choice:";
cin>>c;
if (c==1){
if (x>y)
cout<<"\n"<<x<<" is greater than"<<y<<endl;
else
cout<<"\n"<<y<<" is greater than"<<x<<endl ;
}
else{
cout<<"\nThe sum of "<<x<<" and "<<y<<" is "<<x+y<<endl;
}
return 0;
}
Comments
Leave a comment