exercise from Stroustrup's text book

This is from chapter 13. Create a class that draws a box with rounded corners. I got the math figured out, but for some reason the lines are not being drawn to the screen. What could be the problem?

struct Box :Shape {

Box(Point xxyy, int ww, int hh);

void Top_segment ();
void Bottom_segment ();
void Left_side_segment ();
void Right_side_segment();

void draw_lines() const;

int height() const { return h; }
int width () const { return w; }

private:

Point xy; //left most corner

Lines cornerless_box; // create a box with no corners using line segments

int h; // height
int w; // width

double width_tenth; //10% of the width that will calculate the length to remove from each side to make room for the arcs

};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
Box::Box(Point xxyy, int ww, int hh): w(ww), h(hh), xy(xxyy)
{

width_tenth = (xy.x + w) * 0.10;

if (h<=0 || w<=0) error("Bad rectangle: non-positive side");

}
//------------------------------------------------------------------------------
void Box::Top_segment()
{

double top_seg_begin_w; //where the line segment will begin after deducting 10% of w;
double top_seg_end_w; //where the line segment will end after deducting 10% of w;

top_seg_begin_w = xy.x + width_tenth;
top_seg_end_w = (xy.x + w) - width_tenth;

double top_seg_y = xy.y;

cornerless_box.add(Point(top_seg_begin_w,top_seg_y),Point(top_seg_end_w,top_seg_y));
}

//------------------------------------------------------------------------------
void Box::Bottom_segment()
{

double bottom_seg_begin_w;
double bottom_seg_end_w;

bottom_seg_begin_w = xy.x + width_tenth;
bottom_seg_end_w = (xy.x + w) - width_tenth;

double y_bottom = xy.y + h;

cornerless_box.add(Point(bottom_seg_begin_w,y_bottom),Point(bottom_seg_end_w,y_bottom));
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void Box::Left_side_segment()
{
double left_seg_begin_h;
double left_seg_end_h;

left_seg_begin_h = xy.y + width_tenth;

left_seg_end_h = (xy.y + h) - width_tenth;

double x_left = xy.x;

cornerless_box.add(Point(x_left,left_seg_begin_h),Point(x_left,left_seg_end_h));
}

//------------------------------------------------------------------------------
void Box::Right_side_segment()
{
double right_seg_begin_h;
double right_seg_end_h;

right_seg_begin_h = xy.y + width_tenth;
right_seg_end_h = (xy.y + h) - width_tenth;

double x_right = xy.x + w;

cornerless_box.add(Point(x_right,right_seg_begin_h),Point(x_right,right_seg_end_h));
}
berg309

Posts: 2
Joined: Fri Jan 31, 2014 5:43 pm
Topic archived. No new replies allowed.