Practical-16
Define a circle class with radius as data member, Add necessary constructors and member function to compute area of circle. Class should overload the = = operator to compare two circle objects whether they are equal in radius. Demonstrate its use in main().
#include<math.h>
using namespace std;
class circle
{
int radius;
float area;
public:
circle(int);
void display();
int operator==(circle c1);
};
int circle::operator==(circle c1)
{
if(radius==c1.radius)
return 1;
else
return 0;
}
circle::circle(int radius)
{
cout<<"radius="<<radius<<endl;
area=M_PI*(radius*radius);
}
void circle :: display()
{
cout<<"area="<<area<<endl;
}
int main()
{
circle c1(2);
c1.display();
circle c2(2);
c2.display();
int x;
x=(c1==c2);
if(x==1)
cout<<"they are equal in radius";
else
cout<<"not equal";
return 0;
}
No comments:
Post a Comment