Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shape.h - NON C'E' cpp
- #include "Canvas.h"
- class Shape
- {
- public:
- Shape() {}
- virtual ~Shape() {}
- virtual void draw(Canvas& c) = 0;
- };
- // Rectangle.h
- #include "Shape.h"
- #include "Canvas.h"
- class Rectangle :
- public Shape
- {
- private:
- int x;
- int y;
- int width;
- int height;
- public:
- Rectangle(int x, int y, int width, int height);
- virtual ~Rectangle();
- void draw(Canvas& c) override;
- };
- // Rectangle.cpp
- #include "Rectangle.h"
- Rectangle::Rectangle(int x, int y, int width, int height):
- Shape(),
- x(x), y(y), width(width), height(height)
- {
- }
- Rectangle::~Rectangle()
- {
- }
- void Rectangle::draw(Canvas & c)
- {
- // disegno i lati orizzontali del rettangolo
- for (int x1 = 0; x1 <= width; ++x1) {
- c.set(x + x1, y);
- c.set(x + x1, y + height);
- }
- // disegno i lati verticali del rettangolo
- for (int y1 = 0; y1 <= height; ++y1) {
- c.set(x, y + y1);
- c.set(x + width, y + y1);
- }
- }
- // Square.h - NON C'E' cpp
- #include "Rectangle.h"
- class Square :
- public Rectangle
- {
- public:
- Square(int x, int y, int side) :Rectangle(x, y, side, side) {}
- virtual ~Square() {}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement