0

My assignment is to derive a new class called Smiley from an existing class called Circle. I am using FLTK & C++.

Circle is:


    struct Circle : Shape {
        Circle(Point p, int rr) // center and radius
            :r(rr) { add(Point(p.x-r,p.y-r)); }

    void draw_lines() const;

    Point center() const;

    void set_radius(int rr) { set_point(0,Point(center().x-rr,center().y-rr)); r=rr;  }
    int radius() const { return r; }
private:
    int r;
};

(The add method is a free method, not part of Circle)

And what I have created for Smiley so far is


class Smiley : public Circle {
    public:
    Smiley (Point p, int r) : Circle (a, r){
        return;
        }
    };

I'm trying to figure out how to add circular eyes and a semi-circle mouth. I have an extremely vague idea of what the eyes should look like


Circle left_eye(Point(p.x - (r/3), p.y - (r/3)), (r/8)); //left eye
Circle right_eye(Point(p.x + (r/3), p.y - (r/3)), (r/8)); //right eye

But I don't even know how to incorporate it into my Smiley class, or if that's even the proper format. Help would be much appreciated, thanks.

DJ Burb
  • 2,346
  • 2
  • 29
  • 38
user11892
  • 103
  • 5
  • Your class doesn't know what `a` is here: `Smiley (Point p, int r) : Circle (a, r)`. Do you mean `Smiley (Point p, int r) : Circle (p, r)`? – user3353819 Nov 06 '14 at 10:02

1 Answers1

0

You would push back your eyes onto a Vector_ref along with the mouth and the head and then create a function that draws each element of the vec_ref. Use a for loop in the drawing function (the drawing function should override the draw_lines() function from Circle)