8 Question 8 In Ctt we can write code such as the following int a = double d = ·
ID: 3918256 • Letter: 8
Question
8 Question 8 In Ctt we can write code such as the following int a = double d = ·.. if (a= d) // value // value // compare int and double . This question uses the classes PointDbl and PointInt defined in Question 7. we shall overload operator"" as a binary operator (not ii class method) 1. Let the operands be objects u and v. 2. Then u == t' if and only if (i) the values of u and v are equal and (ii) the y values of u and v are equal. . There are four versions of operator-- as follows. (return type) operator- (const PointDbl tu, const PointDbl kv); (return type) operator-? (const Point Int &u;, const Point Int kv); (return type) operator (const PointDbl ku, const PointInt Rv); (return type) operator== (const Point Int &u;, const PointDbl kv); . Write the function body for each overload above of operator-. . State the return type of operator- for each case. Bonus Overload operator'= for each case above. (return type) operator (const PointDbl ku, const PointDbl &v;); (return type) operator (const PointInt ku, const PointInt &v;): (return type) operator (const PointDbl ku, const PointInt &v;): (return type) operator (const PointInt ku, const PointDbi kv); Hint: this should be easyExplanation / Answer
#include<iostream>
using namespace std;
typedef struct double_point{
double x;
double y;
}dp;
typedef struct int_point{
int x;
int y;
}ip;
bool operator==(const dp&u,const dp&v){
return (u.x==v.x&&u.y==v.y);
}
bool operator==(const ip&u,const ip&v){
return (u.x==v.x&&u.y==v.y);
}
bool operator==(const dp&u,const ip&v){
return (u.x==v.x&&u.y==v.y);
}
bool operator==(const ip&u,const dp&v){
return (u.x==v.x&&u.y==v.y);
}
bool operator!=(const dp&u,const dp&v){
return (u.x!=v.x||u.y!=v.y);
}
bool operator!=(const ip&u,const ip&v){
return (u.x!=v.x||u.y!=v.y);
}
bool operator!=(const dp&u,const ip&v){
return (u.x!=v.x||u.y!=v.y);
}
bool operator!=(const ip&u,const dp&v){
return (u.x!=v.x||u.y!=v.y);
}
int main(){
dp A{1.2,2.4},B{1.0,2.0};
ip C{1,2},D{3,4};
if(B==C)cout<<"equal ";
else cout<<"not equal ";
if(A!=C)cout<<"not equal ";
else cout<<" equal ";
}
for any query please comment.
please upvote if find it helpful.
Thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.