Answer to Question #225538 in C++ for Janvi Shah

Question #225538


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.



1
Expert's answer
2021-08-12T16:24:33-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS