Renamed all operators beginning with underscore.

This commit is contained in:
Ivan Popivanov 2016-12-17 16:26:10 -08:00
commit 5ec5266284
4 changed files with 68 additions and 38 deletions

View file

@ -19,10 +19,37 @@ double Circle::perimeter() {
return 2*M_PI*radius;
}
Circle::Circle(double xx, double yy, double rr)
: radius(rr)
{
x = xx;
y = yy;
}
bool Circle::operator==(const Circle & other)
{
return x == other.x && y == other.y && radius == other.radius;
}
bool Circle::operator!=(const Circle & other)
{
return !operator==(other);
}
double Square::area() {
return width*width;
}
bool Square::operator==(const Square & other)
{
return x == other.x && y == other.y && width == other.width;
}
bool Square::operator!=(const Square & other)
{
return !operator==(other);
}
double Square::perimeter() {
return 4*width;
}

View file

@ -20,8 +20,12 @@ private:
double radius;
public:
Circle(double r) : radius(r) { }
Circle(double xx, double yy, double rr);
virtual double area();
virtual double perimeter();
bool operator==(const Circle & other);
bool operator!=(const Circle & other);
};
class Square : public Shape {
@ -31,4 +35,7 @@ public:
Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
bool operator==(const Square & other);
bool operator!=(const Square & other);
};

View file

@ -31,6 +31,14 @@ print("Here is their current position:")
sprintf(" Circle = (%f, %f)", circle$x,circle$y)
sprintf(" Square = (%f, %f)", square$x,square$y)
c2 <- Circle(1, 5, 15)
c1 <- circle
c1$move(1, 5)
print(Circle_MemberEq(c1, c2))
print(Circle_MemberNotEq(c1, c2))
print(c1$MemberEq(c2))
# ----- Call some methods -----
print ("Here are some properties of the shapes:")