home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / GRAPH / LINE.H < prev   
Text File  |  1995-03-15  |  2KB  |  73 lines

  1. /*************************************************************************
  2.   IBM C/C++ Tools Version 3.00 - Collection Class Library
  3.  (C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
  4.  IBM.  All Rights Reserved.  US Government Users Restricted Rights - Use,
  5.  duplication or disclosure restricted by GSA ADP Schedule Contract with
  6.  IBM Corp.
  7.  *************************************************************************/
  8.  
  9. #if defined (_SUN)
  10. #include <istring.h>
  11. #else
  12. #include <istring.hpp>
  13. #endif
  14. #include <math.h>
  15.  
  16.  
  17. class Line : public Graphics
  18. {
  19. public:
  20.  
  21.   double ivXStart;
  22.   double ivYStart;
  23.   double ivXEnd;
  24.   double ivYEnd;
  25.  
  26.  
  27.   Line(int graphicsKey, IString id, double xstart, double ystart,
  28.                                     double xend,   double yend)
  29.  
  30.                                   : Graphics(graphicsKey, id),
  31.                                     ivXStart(xstart),
  32.                                     ivYStart(ystart),
  33.                                     ivXEnd(xend),
  34.                                     ivYEnd(yend)
  35.                                     { }
  36.  
  37.  
  38.   IBoolean operator== (Line const& line) const
  39.     {
  40.      return (this->ivXStart == line.ivXStart &&
  41.              this->ivYStart == line.ivYStart &&
  42.              this->ivXEnd == line.ivXEnd &&
  43.              this->ivYEnd == line.ivYEnd);
  44.     }
  45.  
  46.  
  47.   void           draw() const
  48.     {
  49.      cout << "drawing "
  50.           << Graphics::id()
  51.           << endl
  52.           << "with starting point: "
  53.           << "(" << this->ivXStart
  54.           << "|" << this->ivYStart << ")"
  55.           << " and with ending point: "
  56.           << "(" << this->ivXEnd
  57.           << "|" << this->ivYEnd << ")"
  58.           << endl;
  59.     }
  60.  
  61.  
  62.   void           lengthOfLine() const
  63.     {
  64.      cout << "The length of line "
  65.           << Graphics::id()
  66.           << " is: "
  67.           << sqrt(pow(((this->ivXEnd) - (this->ivXStart)),2)
  68.                 + pow(((this->ivYEnd) - (this->ivYStart)),2))
  69.           << endl;
  70.     }
  71.  
  72. };
  73.