Vectors/Overloaded/Drawing

  c++, operator-overloading, vector

I have been given this task to do :Task Description

Currently, I have no clue on how to do it. Any help will be appreciated. There is soo many classes therefore all cannot be shown.

If you are able to show me how to do it would be much appreciated. If not, any resources where I can learn to be able to do it would be really helpful too. I am currently struggling on this section.

The Scene class:

Scene::Scene() {
    std::string blankline(WIDTH, ' ');
    for (int i = 0; i < HEIGHT; i++)
    {
        page_ += (blankline + "n");
    }
}

void Scene::addObject(std::shared_ptr<Shape> ptr) {
    vectPage_.push_back(ptr);
}

void Scene::setDrawDepth(int depth) {
    sceneDepth_ = depth;
}

std::ostream& operator<<(std::ostream& out, const Scene& s) 
{
    return out;
}

Stuff in constructor was done myself

Scene.h

class Scene {

public:
    // Constructor
    Scene();

    // Add the pointer to the collection of pointers stored
    void addObject(std::shared_ptr<Shape> ptr);

    // Set the drawing depth to d
    void setDrawDepth(int d);

    // Constants specifying the size of the drawing area
    static constexpr int WIDTH = 60;
    static constexpr int HEIGHT = 20;


private:
    std::string page_;
    
    std::vector<std::shared_ptr<Shape>> vectPage_;
    int sceneDepth_;


friend std::ostream& operator<<(std::ostream& out, const Scene& s);
};

Base Class.h

    class Shape
{

public:
    // Constructor specifying the depth of the object.
    // If d is negative, throw a std::invalid_argument exception.
    Shape(int d);

// Set depth of object to d. If d is negative, return false and
// do not update depth. Otherwise return true
virtual bool setDepth(int d);

// Return the depth of object
virtual int getDepth() const;

// Return the dimension of the object (0, 1 or 2)
virtual int dim() const = 0;

// Translate the object horizontally by x and vertically by y
virtual void translate(float x, float y) = 0;

// Rotate the object 90 degrees around its centre
virtual void rotate() = 0;

// Scale the object by a factor f relative to its centre.
// If f is zero or negative, throw a std::invalid-argument exception.
virtual void scale(float f) = 0;

// Return true if the object contains p and false otherwise.
// Depths are ignored for purpose of comparison
virtual bool contains(const Point &p) const = 0;

// the constant pi
static constexpr double PI = 3.1415926;

virtual ~Shape() = 0;

protected:
    int d;
    float getX() const;
    float getY() const;
};

Source: Windows Questions C++

LEAVE A COMMENT