(The Circle class) Implement the relational operators < in the Circle class in Listing 9.5 to order the Circle objects according to their radii.

```
class Circle
{
public:
Circle();
Circle(double);
double getArea();
double getRadius();
void setRadius(double);

private:
double radius;
};
```

```
#include
using namespace std;

class Circle
{
public:
// Construct a circle object
Circle::Circle()
{
radius = 1;
}

// Construct a circle object
Circle::Circle(double newRadius)
{
radius = newRadius;
}

// Return the area of this circle
double Circle::getArea()
{
return radius * radius * 3.14159;
}

// Return the radius of this circle
double Circle::getRadius()
{
return radius;
}

// Set a new radius
void Circle::setRadius(double newRadius)
{
radius = (newRadius >= 0) ? newRadius : 0;
}


bool Circle::operator < (const Circle & c)
{
return radius < c.getRadius();
}

bool Circle::operator <= (const Circle & c)
{
return radius <= c.getRadius();
}

bool Circle::operator == (const Circle & c)
{
return radius == c.getRadius();
}

bool Circle::operator != (const Circle & c)
{
return radius != c.getRadius();
}

bool Circle::operator > (const Circle & c)
{
return radius > c.getRadius();
}

bool Circle::operator >= (const Circle & c)
{
return radius >= c.getRadius();
}

private:
double radius;
};



int main()
{
Circle c1(5);
Circle c2(6);

cout << (c1 < c2) << endl;
cout << (c1 <= c2) << endl;
cout << (c1 == c2) << endl;
cout << (c1 != c2) << endl;
cout << (c1 > c2) << endl;
cout << (c1 >= c2) << endl;

return 0;
}
```

Computer Science & Information Technology

You might also like to view...

________ will return the interest paid for one installment of a loan

Fill in the blank(s) with correct word

Computer Science & Information Technology

What organization is a very popular certificate authority?

A. Microsoft B. VeriSign C. eBay D. PKI

Computer Science & Information Technology