Thread: exercise from Stroustrup's text book

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    1

    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?

    Code:
    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));
    }
    Last edited by Salem; 02-03-2014 at 12:27 AM. Reason: removed pointless font abuse - code formats properly - use past as text!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculator from Bjarne Stroustrup's book
    By DaineCloud in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2012, 11:36 AM
  2. libraries in Bjarne Stroustrup's book wont work
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2011, 01:07 PM
  3. Need some help with the exercise from the book
    By kenryuakuma in forum C++ Programming
    Replies: 19
    Last Post: 09-26-2008, 08:07 AM
  4. Help with K&R Book Exercise
    By Alejandrito in forum C Programming
    Replies: 5
    Last Post: 03-11-2008, 01:24 PM
  5. calculator program from Bjarne Stroustrup's book
    By deduct in forum C++ Programming
    Replies: 4
    Last Post: 03-21-2003, 01:43 AM

Tags for this Thread