programming practice and principles chapter 13 exercise 2

The exercise is:

"Draw a box with rounded corners. Define a class box, consisting of four lines and four arcs."

I'm not sure where to start with this. Can anyone help me please!! I'm a self learner.

The previous exercise was define an Arc class based off Ellipse, which you can see here:


struct Arc : Shape {
Arc(Point p, int ww, int hh, int a_start, int a_end) // center, min, and max distance from center
:w(ww), h(hh), arc_start(a_start), arc_end(a_end) { add(Point(p.x-ww,p.y-hh)); }

void draw_lines() const;

Point center() const { return Point(point(0).x+w,point(0).y+h); }
Point focus1() const {
if (h<=w)// foci are on the x-axis:
return Point(center().x+int(sqrt(double(w*w-h*h))),center().y);
else // foci are on the y-axis:
return Point(center().x,center().y+int(sqrt(double(h*h-w*w))));

Point focus2() const {
if (h<=w)
return Point(center().x-int(sqrt(double(w*w-h*h))),center().y);
return Point(center().x,center().y-int(sqrt(double(h*h-w*w))));
//Point focus2() const { return Point(center().x-int(sqrt(double(abs(w*w-h*h)))),center().y); }

void set_major(int ww) { set_point(0,Point(center().x-ww,center().y-h)); w=ww; }
int major() const { return w; }
void set_minor(int hh) { set_point(0,Point(center().x-w,center().y-hh)); h=hh; }
int minor() const { return h; }
int w;
int h;
int arc_start;
int arc_end;



void Arc::draw_lines() const
if (fill_color().visibility()) { // fill
fl_color(color().as_int()); // reset color

if (color().visibility()) {

Since no one else is picking this up, I'll take a stab. I'm not set up to compile with FLTK, so I can't help with that.

Remember that a rounded rectangle has quarter arcs at the corners. The focal point of the arc is, of course, the radius of the arc. Likewise, the distance of the edge lines from the corners is the radii of the arcs.

 ▄▀   │
▄▀    │

Hope this helps.
Topic archived. No new replies allowed.