Translate these overloaded operator expressions to appropria
Solution
Answer :1
let us assume.
int x=(2*5)+(4%2);
int y=(34-10)+(18/9);
a) x > y
int operator>(const int &x,const int &y){
int r =(x>y);
return r;
//returns 1 when x value is greater than y value otherwise 0.
}
b) x != y
int operator!=(const int &x,const int &y){
int r=(x!=y);
return r;
//returns 1 when x value is not equal to y value otherwise 0.
}
c) x % y
int operator% (const int &x,const int &y){
int r=(x%y);
return r;
//returns remainder value when x value is divided with y value.
}
d) x || y
int operator||(const int &x,const int &y){
int r=(x!|| y);
return r;
//returns 1 when any of x value or y value is greater than 0 otherwise 0.
Answer :2
#include<iostream.h>
#include<conio.h>
// Card class creating
class Card{
char s;//holds the card symbol
char v;//holds the card value
public:
//initialising card value
Card(char va,char sy){
v=va;
s=sy;
}
Card(){
v=\' \';
s=\' \';
}
//> operator overloading
int operator>(const Card y){
int r;
r=(v>y.v) && (s>y.s);
return r;
//returns 1 when card x greater than card y otherwise 0.
}
//< operator overloading
int operator <(const Card y){
int r;
r= (v<y.v) && (s<y.s);
return r;
//returns 1 when card x is lesser than card y otherwise 0.
}
//<= operator overloading
int operator <=(const Card y){
int r;
r=(v<=y.v) && (s<=y.s);
return r;
//returns 1 when card x value is lesser than or equal to card y otherwise 0.
}
//>= operator overloading
int operator >=(const Card y){
int r;
r=(v>=y.v) && (s>=y.s);
return r;
//returns 1 when card x value is greater than card y value otherwise 0;
}
//displaying card
void display()
{
cout<<\"\ card is \"<<v<<\" \"<<s;
}
};
//main method
int main(){
Card x(\'3\',\'&\'),y(\'8\',\'&\');
clrscr();
if(x<y) x.display();
else y.display();
if(x>y) x.display();
else y.display();
if(x<=y)x.display();
else y.display();
if(x>=y)x.display();
else y.display();
return 0;
}

