0

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;
};
AvG
  • 9
  • 3
  • 2
    When you don't know how to get started, go looking for smaller problems. Take the big problem, hack it up into little problems, and attack each little problem one at a time. If a little problem is found to still be too big, hack it up. Repeat until everything is in nice, bite-sized chunks. – user4581301 Jan 14 '22 at 00:01
  • For example, i am trying to call the variable vectPage_ into the ( std::ostream& operator ) but it wont allow me to call it in there – AvG Jan 14 '22 at 00:45
  • That sounds like something we can help you with, but what do you mean by call> You can't call an object. You can call one of it's methods. Do you mean to write it to the `ostream`? Because there is no universal agreement on how to format the data in a `vector`, you have to write a loop that prints the contents yourself: `for const auto & item: vectPage_) { std::cout << *item << ' '; }` will get the item referenced by the `shared_ptr` and write it, assuming it also has a `<<` operator. – user4581301 Jan 14 '22 at 01:11
  • [Use this question and top answer](https://stackoverflow.com/questions/49903769/how-to-properly-overload-the-stream-operator-for-printing-in-an-polymorphic-clas) for help with getting a polymorphic `<<` operator working. – user4581301 Jan 14 '22 at 01:11
  • For example, if i try calling the object into a for loop to get its methods. It wont allow me. Instead I have a made a new function. In here, I am getting the issue now where when i try calling one of its methods, it wont work as its not in the base class. How would i fix the issue? Add it to the base class? Adding the function init the base class will work but whats the point when it just gets overidden? – AvG Jan 14 '22 at 01:40

0 Answers0