Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Pos
- {
- private:
- int x, y;
- public:
- Pos(int x = 0, int y = 0)
- {
- this->x = x;
- this->y = y;
- }
- int getX() const
- {
- return x;
- }
- int getY() const
- {
- return y;
- }
- void show() const
- {
- cout << '(' << x << ',' << y << ')';
- }
- };
- class Point : public Pos
- {
- private:
- int color;
- public:
- Point(int x = 0, int y = 0, int color = 0) : Pos(x, y)
- {
- this->color = color;
- }
- int getColor() const
- {
- return color;
- }
- void show() const
- {
- cout << '[';
- Pos::show();
- cout << ':' << color << ']';
- }
- };
- class Circle : public Point
- {
- private:
- int radius;
- public:
- Circle(int x = 0, int y = 0, int color = 0, int radius = 0) : Point(x, y, color)
- {
- this->radius = radius;
- }
- int getRadius() const
- {
- return radius;
- }
- void show() const
- {
- cout << '{';
- Point::show();
- cout << ',' << radius << '}';
- }
- };
- class Square : public Circle
- {
- public:
- Square(int x = 0, int y = 0, int color = 0, int radius = 0) : Circle(x, y, color, radius)
- {
- }
- int getSide() const
- {
- return Circle::getRadius();
- }
- int getRadius() const
- {
- throw "No radius";
- // cout << "No radius!\n";
- // return -1;
- }
- };
- int main()
- {
- Pos pos(3, 6);
- Point t(5, 10, 255*256);
- Circle c(1, 4, 255, 10);
- Square s(5, 5, 0, 30);
- pos.show();
- cout << endl;
- t.show();
- cout << endl;
- c.Pos::show();
- cout << endl;
- s.show();
- cout << endl;
- cout << s.getSide();
- cout << endl;
- try
- {
- cout << s.getRadius();
- } catch(const char *s)
- {
- cout << "Error: " << s;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement