Q3. The Table Q3 on the next page is the code of a class named Circle. Study the
ID: 3551989 • Letter: Q
Question
Q3. The Table Q3 on the next page is the code of a class named Circle. Study the code and implement the operator overloading for these relational operators (<, <=, ==, !=, >, >=) for the Circle class. Then, write a test program that creates two instances of the Circle class and compare these two instances using the operators (<, <=, ==, !=, >, >=) overloaded for the Circle class. (35 marks)
More specifically, you should develop the following files as the answer for this question.
(1) Revising the Circle class by adding a set of functions implementing operator overloading. That is, the updated class should include:
A revised header file
It should have the definitions of the following new functions:
Explanation / Answer
Just showing the operator overloading
class Circle
{
public:
double r;
bool operator< (const Circle& other)
{
return r<other.r;
}
bool operator<= (const Circle& other)
{
return r<=other.r;
}
bool operator== (const Circle& other)
{
return r==other.r;
}
bool operator!= (const Circle& other)
{
return r!=other.r;
}
bool operator> (const Circle& other)
{
return r>other.r;
}
bool operator>= (const Circle& other)
{
return r>=other.r;
}
};
So if you have two object of Circle namely a and b then you can directly call a<b or a>=b and so on and it will return true of false based on that.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.